@@ -14,248 +14,248 @@ |
||
14 | 14 | |
15 | 15 | abstract class Shortcode implements ShortcodeContract |
16 | 16 | { |
17 | - /** |
|
18 | - * @var string |
|
19 | - */ |
|
20 | - protected $partialName; |
|
17 | + /** |
|
18 | + * @var string |
|
19 | + */ |
|
20 | + protected $partialName; |
|
21 | 21 | |
22 | - /** |
|
23 | - * @var string |
|
24 | - */ |
|
25 | - protected $shortcodeName; |
|
22 | + /** |
|
23 | + * @var string |
|
24 | + */ |
|
25 | + protected $shortcodeName; |
|
26 | 26 | |
27 | - public function __construct() |
|
28 | - { |
|
29 | - $this->partialName = $this->getShortcodePartialName(); |
|
30 | - $this->shortcodeName = $this->getShortcodeName(); |
|
31 | - } |
|
27 | + public function __construct() |
|
28 | + { |
|
29 | + $this->partialName = $this->getShortcodePartialName(); |
|
30 | + $this->shortcodeName = $this->getShortcodeName(); |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * @param string|array $atts |
|
35 | - * @param string $type |
|
36 | - * @return string |
|
37 | - */ |
|
38 | - public function build($atts, array $args = [], $type = 'shortcode') |
|
39 | - { |
|
40 | - $args = $this->normalizeArgs($args, $type); |
|
41 | - $atts = $this->normalizeAtts($atts, $type); |
|
42 | - $partial = glsr(Partial::class)->build($this->partialName, $atts); |
|
43 | - if (!empty($atts['title'])) { |
|
44 | - $atts = Arr::set($atts, 'title', $args['before_title'].$atts['title'].$args['after_title']); |
|
45 | - } |
|
46 | - $html = glsr(Builder::class)->div((string) $partial, [ |
|
47 | - 'class' => 'glsr glsr-'.glsr(Style::class)->get(), |
|
48 | - 'data-shortcode' => Str::snakeCase($this->partialName), |
|
49 | - 'data-type' => $type, |
|
50 | - 'data-atts' => $atts['json'], // I prefer to have this attribute displayed last |
|
51 | - ]); |
|
52 | - return $args['before_widget'].$atts['title'].$html.$args['after_widget']; |
|
53 | - } |
|
33 | + /** |
|
34 | + * @param string|array $atts |
|
35 | + * @param string $type |
|
36 | + * @return string |
|
37 | + */ |
|
38 | + public function build($atts, array $args = [], $type = 'shortcode') |
|
39 | + { |
|
40 | + $args = $this->normalizeArgs($args, $type); |
|
41 | + $atts = $this->normalizeAtts($atts, $type); |
|
42 | + $partial = glsr(Partial::class)->build($this->partialName, $atts); |
|
43 | + if (!empty($atts['title'])) { |
|
44 | + $atts = Arr::set($atts, 'title', $args['before_title'].$atts['title'].$args['after_title']); |
|
45 | + } |
|
46 | + $html = glsr(Builder::class)->div((string) $partial, [ |
|
47 | + 'class' => 'glsr glsr-'.glsr(Style::class)->get(), |
|
48 | + 'data-shortcode' => Str::snakeCase($this->partialName), |
|
49 | + 'data-type' => $type, |
|
50 | + 'data-atts' => $atts['json'], // I prefer to have this attribute displayed last |
|
51 | + ]); |
|
52 | + return $args['before_widget'].$atts['title'].$html.$args['after_widget']; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * {@inheritdoc} |
|
57 | - */ |
|
58 | - public function buildBlock($atts = []) |
|
59 | - { |
|
60 | - return $this->build($atts, [], 'block'); |
|
61 | - } |
|
55 | + /** |
|
56 | + * {@inheritdoc} |
|
57 | + */ |
|
58 | + public function buildBlock($atts = []) |
|
59 | + { |
|
60 | + return $this->build($atts, [], 'block'); |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * {@inheritdoc} |
|
65 | - */ |
|
66 | - public function buildShortcode($atts = []) |
|
67 | - { |
|
68 | - return $this->build($atts, [], 'shortcode'); |
|
69 | - } |
|
63 | + /** |
|
64 | + * {@inheritdoc} |
|
65 | + */ |
|
66 | + public function buildShortcode($atts = []) |
|
67 | + { |
|
68 | + return $this->build($atts, [], 'shortcode'); |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * @return array |
|
73 | - */ |
|
74 | - public function getDefaults($atts) |
|
75 | - { |
|
76 | - return glsr($this->getShortcodeDefaultsClassName())->restrict(wp_parse_args($atts)); |
|
77 | - } |
|
71 | + /** |
|
72 | + * @return array |
|
73 | + */ |
|
74 | + public function getDefaults($atts) |
|
75 | + { |
|
76 | + return glsr($this->getShortcodeDefaultsClassName())->restrict(wp_parse_args($atts)); |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * @return array |
|
81 | - */ |
|
82 | - public function getHideOptions() |
|
83 | - { |
|
84 | - $options = $this->hideOptions(); |
|
85 | - return apply_filters('site-reviews/shortcode/hide-options', $options, $this->shortcodeName); |
|
86 | - } |
|
79 | + /** |
|
80 | + * @return array |
|
81 | + */ |
|
82 | + public function getHideOptions() |
|
83 | + { |
|
84 | + $options = $this->hideOptions(); |
|
85 | + return apply_filters('site-reviews/shortcode/hide-options', $options, $this->shortcodeName); |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * @return string |
|
90 | - */ |
|
91 | - public function getShortClassName($replace = '', $search = 'Shortcode') |
|
92 | - { |
|
93 | - return str_replace($search, $replace, (new ReflectionClass($this))->getShortName()); |
|
94 | - } |
|
88 | + /** |
|
89 | + * @return string |
|
90 | + */ |
|
91 | + public function getShortClassName($replace = '', $search = 'Shortcode') |
|
92 | + { |
|
93 | + return str_replace($search, $replace, (new ReflectionClass($this))->getShortName()); |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * @return string |
|
98 | - */ |
|
99 | - public function getShortcodeDefaultsClassName() |
|
100 | - { |
|
101 | - $className = Str::replaceLast('Shortcode', 'Defaults', get_class($this)); |
|
102 | - return str_replace('Shortcodes', 'Defaults', $className); |
|
103 | - } |
|
96 | + /** |
|
97 | + * @return string |
|
98 | + */ |
|
99 | + public function getShortcodeDefaultsClassName() |
|
100 | + { |
|
101 | + $className = Str::replaceLast('Shortcode', 'Defaults', get_class($this)); |
|
102 | + return str_replace('Shortcodes', 'Defaults', $className); |
|
103 | + } |
|
104 | 104 | |
105 | - /** |
|
106 | - * @return string |
|
107 | - */ |
|
108 | - public function getShortcodeName() |
|
109 | - { |
|
110 | - return Str::snakeCase($this->getShortClassName()); |
|
111 | - } |
|
105 | + /** |
|
106 | + * @return string |
|
107 | + */ |
|
108 | + public function getShortcodeName() |
|
109 | + { |
|
110 | + return Str::snakeCase($this->getShortClassName()); |
|
111 | + } |
|
112 | 112 | |
113 | - /** |
|
114 | - * @return string |
|
115 | - */ |
|
116 | - public function getShortcodePartialName() |
|
117 | - { |
|
118 | - return Str::dashCase($this->getShortClassName()); |
|
119 | - } |
|
113 | + /** |
|
114 | + * @return string |
|
115 | + */ |
|
116 | + public function getShortcodePartialName() |
|
117 | + { |
|
118 | + return Str::dashCase($this->getShortClassName()); |
|
119 | + } |
|
120 | 120 | |
121 | - /** |
|
122 | - * @param array|string $args |
|
123 | - * @param string $type |
|
124 | - * @return array |
|
125 | - */ |
|
126 | - public function normalizeArgs($args, $type = 'shortcode') |
|
127 | - { |
|
128 | - $args = wp_parse_args($args, [ |
|
129 | - 'before_widget' => '', |
|
130 | - 'after_widget' => '', |
|
131 | - 'before_title' => '<h2 class="glsr-title">', |
|
132 | - 'after_title' => '</h2>', |
|
133 | - ]); |
|
134 | - return apply_filters('site-reviews/shortcode/args', $args, $type, $this->partialName); |
|
135 | - } |
|
121 | + /** |
|
122 | + * @param array|string $args |
|
123 | + * @param string $type |
|
124 | + * @return array |
|
125 | + */ |
|
126 | + public function normalizeArgs($args, $type = 'shortcode') |
|
127 | + { |
|
128 | + $args = wp_parse_args($args, [ |
|
129 | + 'before_widget' => '', |
|
130 | + 'after_widget' => '', |
|
131 | + 'before_title' => '<h2 class="glsr-title">', |
|
132 | + 'after_title' => '</h2>', |
|
133 | + ]); |
|
134 | + return apply_filters('site-reviews/shortcode/args', $args, $type, $this->partialName); |
|
135 | + } |
|
136 | 136 | |
137 | - /** |
|
138 | - * @param array|string $atts |
|
139 | - * @param string $type |
|
140 | - * @return array |
|
141 | - */ |
|
142 | - public function normalizeAtts($atts, $type = 'shortcode') |
|
143 | - { |
|
144 | - $atts = apply_filters('site-reviews/shortcode/atts', $atts, $type, $this->partialName); |
|
145 | - $atts = $this->getDefaults($atts); |
|
146 | - array_walk($atts, function (&$value, $key) { |
|
147 | - $methodName = Helper::buildMethodName($key, 'normalize'); |
|
148 | - if (!method_exists($this, $methodName)) { |
|
149 | - return; |
|
150 | - } |
|
151 | - $value = $this->$methodName($value); |
|
152 | - }); |
|
153 | - $this->setId($atts); |
|
154 | - return $atts; |
|
155 | - } |
|
137 | + /** |
|
138 | + * @param array|string $atts |
|
139 | + * @param string $type |
|
140 | + * @return array |
|
141 | + */ |
|
142 | + public function normalizeAtts($atts, $type = 'shortcode') |
|
143 | + { |
|
144 | + $atts = apply_filters('site-reviews/shortcode/atts', $atts, $type, $this->partialName); |
|
145 | + $atts = $this->getDefaults($atts); |
|
146 | + array_walk($atts, function (&$value, $key) { |
|
147 | + $methodName = Helper::buildMethodName($key, 'normalize'); |
|
148 | + if (!method_exists($this, $methodName)) { |
|
149 | + return; |
|
150 | + } |
|
151 | + $value = $this->$methodName($value); |
|
152 | + }); |
|
153 | + $this->setId($atts); |
|
154 | + return $atts; |
|
155 | + } |
|
156 | 156 | |
157 | - /** |
|
158 | - * @return array |
|
159 | - */ |
|
160 | - abstract protected function hideOptions(); |
|
157 | + /** |
|
158 | + * @return array |
|
159 | + */ |
|
160 | + abstract protected function hideOptions(); |
|
161 | 161 | |
162 | - /** |
|
163 | - * @param string $postId |
|
164 | - * @return int|string |
|
165 | - */ |
|
166 | - protected function normalizeAssignedTo($postId) |
|
167 | - { |
|
168 | - if ('parent_id' == $postId) { |
|
169 | - $postId = intval(wp_get_post_parent_id(intval(get_the_ID()))); |
|
170 | - } elseif ('post_id' == $postId) { |
|
171 | - $postId = intval(get_the_ID()); |
|
172 | - } |
|
173 | - return $postId; |
|
174 | - } |
|
162 | + /** |
|
163 | + * @param string $postId |
|
164 | + * @return int|string |
|
165 | + */ |
|
166 | + protected function normalizeAssignedTo($postId) |
|
167 | + { |
|
168 | + if ('parent_id' == $postId) { |
|
169 | + $postId = intval(wp_get_post_parent_id(intval(get_the_ID()))); |
|
170 | + } elseif ('post_id' == $postId) { |
|
171 | + $postId = intval(get_the_ID()); |
|
172 | + } |
|
173 | + return $postId; |
|
174 | + } |
|
175 | 175 | |
176 | - /** |
|
177 | - * @param string $postId |
|
178 | - * @return int|string |
|
179 | - */ |
|
180 | - protected function normalizeAssignTo($postId) |
|
181 | - { |
|
182 | - return $this->normalizeAssignedTo($postId); |
|
183 | - } |
|
176 | + /** |
|
177 | + * @param string $postId |
|
178 | + * @return int|string |
|
179 | + */ |
|
180 | + protected function normalizeAssignTo($postId) |
|
181 | + { |
|
182 | + return $this->normalizeAssignedTo($postId); |
|
183 | + } |
|
184 | 184 | |
185 | - /** |
|
186 | - * @param string|array $hide |
|
187 | - * @return array |
|
188 | - */ |
|
189 | - protected function normalizeHide($hide) |
|
190 | - { |
|
191 | - if (is_string($hide)) { |
|
192 | - $hide = explode(',', $hide); |
|
193 | - } |
|
194 | - $hideKeys = array_keys($this->getHideOptions()); |
|
195 | - return array_filter(array_map('trim', $hide), function ($value) use ($hideKeys) { |
|
196 | - return in_array($value, $hideKeys); |
|
197 | - }); |
|
198 | - } |
|
185 | + /** |
|
186 | + * @param string|array $hide |
|
187 | + * @return array |
|
188 | + */ |
|
189 | + protected function normalizeHide($hide) |
|
190 | + { |
|
191 | + if (is_string($hide)) { |
|
192 | + $hide = explode(',', $hide); |
|
193 | + } |
|
194 | + $hideKeys = array_keys($this->getHideOptions()); |
|
195 | + return array_filter(array_map('trim', $hide), function ($value) use ($hideKeys) { |
|
196 | + return in_array($value, $hideKeys); |
|
197 | + }); |
|
198 | + } |
|
199 | 199 | |
200 | - /** |
|
201 | - * @param string $id |
|
202 | - * @return string |
|
203 | - */ |
|
204 | - protected function normalizeId($id) |
|
205 | - { |
|
206 | - return sanitize_title($id); |
|
207 | - } |
|
200 | + /** |
|
201 | + * @param string $id |
|
202 | + * @return string |
|
203 | + */ |
|
204 | + protected function normalizeId($id) |
|
205 | + { |
|
206 | + return sanitize_title($id); |
|
207 | + } |
|
208 | 208 | |
209 | - /** |
|
210 | - * @param string $labels |
|
211 | - * @return array |
|
212 | - */ |
|
213 | - protected function normalizeLabels($labels) |
|
214 | - { |
|
215 | - $defaults = [ |
|
216 | - __('Excellent', 'site-reviews'), |
|
217 | - __('Very good', 'site-reviews'), |
|
218 | - __('Average', 'site-reviews'), |
|
219 | - __('Poor', 'site-reviews'), |
|
220 | - __('Terrible', 'site-reviews'), |
|
221 | - ]; |
|
222 | - $maxRating = (int) glsr()->constant('MAX_RATING', Rating::class); |
|
223 | - $defaults = array_pad(array_slice($defaults, 0, $maxRating), $maxRating, ''); |
|
224 | - $labels = array_map('trim', explode(',', $labels)); |
|
225 | - foreach ($defaults as $i => $label) { |
|
226 | - if (empty($labels[$i])) { |
|
227 | - continue; |
|
228 | - } |
|
229 | - $defaults[$i] = $labels[$i]; |
|
230 | - } |
|
231 | - return array_combine(range($maxRating, 1), $defaults); |
|
232 | - } |
|
209 | + /** |
|
210 | + * @param string $labels |
|
211 | + * @return array |
|
212 | + */ |
|
213 | + protected function normalizeLabels($labels) |
|
214 | + { |
|
215 | + $defaults = [ |
|
216 | + __('Excellent', 'site-reviews'), |
|
217 | + __('Very good', 'site-reviews'), |
|
218 | + __('Average', 'site-reviews'), |
|
219 | + __('Poor', 'site-reviews'), |
|
220 | + __('Terrible', 'site-reviews'), |
|
221 | + ]; |
|
222 | + $maxRating = (int) glsr()->constant('MAX_RATING', Rating::class); |
|
223 | + $defaults = array_pad(array_slice($defaults, 0, $maxRating), $maxRating, ''); |
|
224 | + $labels = array_map('trim', explode(',', $labels)); |
|
225 | + foreach ($defaults as $i => $label) { |
|
226 | + if (empty($labels[$i])) { |
|
227 | + continue; |
|
228 | + } |
|
229 | + $defaults[$i] = $labels[$i]; |
|
230 | + } |
|
231 | + return array_combine(range($maxRating, 1), $defaults); |
|
232 | + } |
|
233 | 233 | |
234 | - /** |
|
235 | - * @param string $schema |
|
236 | - * @return bool |
|
237 | - */ |
|
238 | - protected function normalizeSchema($schema) |
|
239 | - { |
|
240 | - return wp_validate_boolean($schema); |
|
241 | - } |
|
234 | + /** |
|
235 | + * @param string $schema |
|
236 | + * @return bool |
|
237 | + */ |
|
238 | + protected function normalizeSchema($schema) |
|
239 | + { |
|
240 | + return wp_validate_boolean($schema); |
|
241 | + } |
|
242 | 242 | |
243 | - /** |
|
244 | - * @param string $text |
|
245 | - * @return string |
|
246 | - */ |
|
247 | - protected function normalizeText($text) |
|
248 | - { |
|
249 | - return trim($text); |
|
250 | - } |
|
243 | + /** |
|
244 | + * @param string $text |
|
245 | + * @return string |
|
246 | + */ |
|
247 | + protected function normalizeText($text) |
|
248 | + { |
|
249 | + return trim($text); |
|
250 | + } |
|
251 | 251 | |
252 | - /** |
|
253 | - * @return void |
|
254 | - */ |
|
255 | - protected function setId(array &$atts) |
|
256 | - { |
|
257 | - if (empty($atts['id'])) { |
|
258 | - $atts['id'] = Application::PREFIX.substr(md5(serialize($atts)), 0, 8); |
|
259 | - } |
|
260 | - } |
|
252 | + /** |
|
253 | + * @return void |
|
254 | + */ |
|
255 | + protected function setId(array &$atts) |
|
256 | + { |
|
257 | + if (empty($atts['id'])) { |
|
258 | + $atts['id'] = Application::PREFIX.substr(md5(serialize($atts)), 0, 8); |
|
259 | + } |
|
260 | + } |
|
261 | 261 | } |
@@ -4,16 +4,16 @@ |
||
4 | 4 | |
5 | 5 | class RegisterWidgets |
6 | 6 | { |
7 | - public $widgets; |
|
7 | + public $widgets; |
|
8 | 8 | |
9 | - public function __construct(array $input) |
|
10 | - { |
|
11 | - array_walk($input, function (&$args, $id) { |
|
12 | - $args = wp_parse_args($args, [ |
|
13 | - 'description' => '', |
|
14 | - 'name' => '', |
|
15 | - ]); |
|
16 | - }); |
|
17 | - $this->widgets = $input; |
|
18 | - } |
|
9 | + public function __construct(array $input) |
|
10 | + { |
|
11 | + array_walk($input, function (&$args, $id) { |
|
12 | + $args = wp_parse_args($args, [ |
|
13 | + 'description' => '', |
|
14 | + 'name' => '', |
|
15 | + ]); |
|
16 | + }); |
|
17 | + $this->widgets = $input; |
|
18 | + } |
|
19 | 19 | } |
@@ -6,145 +6,145 @@ |
||
6 | 6 | |
7 | 7 | class CreateReview |
8 | 8 | { |
9 | - public $ajax_request; |
|
10 | - public $assigned_to; |
|
11 | - public $author; |
|
12 | - public $avatar; |
|
13 | - public $blacklisted; |
|
14 | - public $category; |
|
15 | - public $content; |
|
16 | - public $custom; |
|
17 | - public $date; |
|
18 | - public $email; |
|
19 | - public $form_id; |
|
20 | - public $ip_address; |
|
21 | - public $post_id; |
|
22 | - public $rating; |
|
23 | - public $referer; |
|
24 | - public $request; |
|
25 | - public $response; |
|
26 | - public $terms; |
|
27 | - public $title; |
|
28 | - public $url; |
|
9 | + public $ajax_request; |
|
10 | + public $assigned_to; |
|
11 | + public $author; |
|
12 | + public $avatar; |
|
13 | + public $blacklisted; |
|
14 | + public $category; |
|
15 | + public $content; |
|
16 | + public $custom; |
|
17 | + public $date; |
|
18 | + public $email; |
|
19 | + public $form_id; |
|
20 | + public $ip_address; |
|
21 | + public $post_id; |
|
22 | + public $rating; |
|
23 | + public $referer; |
|
24 | + public $request; |
|
25 | + public $response; |
|
26 | + public $terms; |
|
27 | + public $title; |
|
28 | + public $url; |
|
29 | 29 | |
30 | - public function __construct($input) |
|
31 | - { |
|
32 | - $this->request = $input; |
|
33 | - $this->ajax_request = isset($input['_ajax_request']); |
|
34 | - $this->assigned_to = $this->getNumeric('assign_to'); |
|
35 | - $this->author = sanitize_text_field($this->getUser('name')); |
|
36 | - $this->avatar = $this->getAvatar(); |
|
37 | - $this->blacklisted = isset($input['blacklisted']); |
|
38 | - $this->category = $this->getCategory(); |
|
39 | - $this->content = sanitize_textarea_field($this->get('content')); |
|
40 | - $this->custom = $this->getCustom(); |
|
41 | - $this->date = $this->getDate('date'); |
|
42 | - $this->email = sanitize_email($this->getUser('email')); |
|
43 | - $this->form_id = sanitize_key($this->get('form_id')); |
|
44 | - $this->ip_address = $this->get('ip_address'); |
|
45 | - $this->post_id = intval($this->get('_post_id')); |
|
46 | - $this->rating = intval($this->get('rating')); |
|
47 | - $this->referer = sanitize_text_field($this->get('_referer')); |
|
48 | - $this->response = sanitize_textarea_field($this->get('response')); |
|
49 | - $this->terms = !empty($input['terms']); |
|
50 | - $this->title = sanitize_text_field($this->get('title')); |
|
51 | - $this->url = esc_url_raw(sanitize_text_field($this->get('url'))); |
|
52 | - } |
|
30 | + public function __construct($input) |
|
31 | + { |
|
32 | + $this->request = $input; |
|
33 | + $this->ajax_request = isset($input['_ajax_request']); |
|
34 | + $this->assigned_to = $this->getNumeric('assign_to'); |
|
35 | + $this->author = sanitize_text_field($this->getUser('name')); |
|
36 | + $this->avatar = $this->getAvatar(); |
|
37 | + $this->blacklisted = isset($input['blacklisted']); |
|
38 | + $this->category = $this->getCategory(); |
|
39 | + $this->content = sanitize_textarea_field($this->get('content')); |
|
40 | + $this->custom = $this->getCustom(); |
|
41 | + $this->date = $this->getDate('date'); |
|
42 | + $this->email = sanitize_email($this->getUser('email')); |
|
43 | + $this->form_id = sanitize_key($this->get('form_id')); |
|
44 | + $this->ip_address = $this->get('ip_address'); |
|
45 | + $this->post_id = intval($this->get('_post_id')); |
|
46 | + $this->rating = intval($this->get('rating')); |
|
47 | + $this->referer = sanitize_text_field($this->get('_referer')); |
|
48 | + $this->response = sanitize_textarea_field($this->get('response')); |
|
49 | + $this->terms = !empty($input['terms']); |
|
50 | + $this->title = sanitize_text_field($this->get('title')); |
|
51 | + $this->url = esc_url_raw(sanitize_text_field($this->get('url'))); |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * @param string $key |
|
56 | - * @return string |
|
57 | - */ |
|
58 | - protected function get($key) |
|
59 | - { |
|
60 | - return (string) Arr::get($this->request, $key); |
|
61 | - } |
|
54 | + /** |
|
55 | + * @param string $key |
|
56 | + * @return string |
|
57 | + */ |
|
58 | + protected function get($key) |
|
59 | + { |
|
60 | + return (string) Arr::get($this->request, $key); |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * @return string |
|
65 | - */ |
|
66 | - protected function getAvatar() |
|
67 | - { |
|
68 | - $avatar = $this->get('avatar'); |
|
69 | - return !filter_var($avatar, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED) |
|
70 | - ? (string) get_avatar_url($this->get('email')) |
|
71 | - : $avatar; |
|
72 | - } |
|
63 | + /** |
|
64 | + * @return string |
|
65 | + */ |
|
66 | + protected function getAvatar() |
|
67 | + { |
|
68 | + $avatar = $this->get('avatar'); |
|
69 | + return !filter_var($avatar, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED) |
|
70 | + ? (string) get_avatar_url($this->get('email')) |
|
71 | + : $avatar; |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @return string |
|
76 | - */ |
|
77 | - protected function getCategory() |
|
78 | - { |
|
79 | - $categories = Arr::convertFromString($this->get('category')); |
|
80 | - return sanitize_key(Arr::get($categories, 0)); |
|
81 | - } |
|
74 | + /** |
|
75 | + * @return string |
|
76 | + */ |
|
77 | + protected function getCategory() |
|
78 | + { |
|
79 | + $categories = Arr::convertFromString($this->get('category')); |
|
80 | + return sanitize_key(Arr::get($categories, 0)); |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * @return array |
|
85 | - */ |
|
86 | - protected function getCustom() |
|
87 | - { |
|
88 | - $unset = [ |
|
89 | - '_action', '_ajax_request', '_counter', '_nonce', '_post_id', '_recaptcha-token', |
|
90 | - '_referer', 'assign_to', 'category', 'content', 'date', 'email', 'excluded', 'form_id', |
|
91 | - 'gotcha', 'ip_address', 'name', 'rating', 'response', 'terms', 'title', 'url', |
|
92 | - ]; |
|
93 | - $unset = apply_filters('site-reviews/create/unset-keys-from-custom', $unset); |
|
94 | - $custom = $this->request; |
|
95 | - foreach ($unset as $key) { |
|
96 | - unset($custom[$key]); |
|
97 | - } |
|
98 | - foreach ($custom as $key => $value) { |
|
99 | - if (is_string($value)) { |
|
100 | - $custom[$key] = sanitize_text_field($value); |
|
101 | - } |
|
102 | - } |
|
103 | - return $custom; |
|
104 | - } |
|
83 | + /** |
|
84 | + * @return array |
|
85 | + */ |
|
86 | + protected function getCustom() |
|
87 | + { |
|
88 | + $unset = [ |
|
89 | + '_action', '_ajax_request', '_counter', '_nonce', '_post_id', '_recaptcha-token', |
|
90 | + '_referer', 'assign_to', 'category', 'content', 'date', 'email', 'excluded', 'form_id', |
|
91 | + 'gotcha', 'ip_address', 'name', 'rating', 'response', 'terms', 'title', 'url', |
|
92 | + ]; |
|
93 | + $unset = apply_filters('site-reviews/create/unset-keys-from-custom', $unset); |
|
94 | + $custom = $this->request; |
|
95 | + foreach ($unset as $key) { |
|
96 | + unset($custom[$key]); |
|
97 | + } |
|
98 | + foreach ($custom as $key => $value) { |
|
99 | + if (is_string($value)) { |
|
100 | + $custom[$key] = sanitize_text_field($value); |
|
101 | + } |
|
102 | + } |
|
103 | + return $custom; |
|
104 | + } |
|
105 | 105 | |
106 | - /** |
|
107 | - * @param string $key |
|
108 | - * @return string |
|
109 | - */ |
|
110 | - protected function getDate($key) |
|
111 | - { |
|
112 | - $date = strtotime($this->get($key)); |
|
113 | - if (false === $date) { |
|
114 | - $date = time(); |
|
115 | - } |
|
116 | - return get_date_from_gmt(gmdate('Y-m-d H:i:s', $date)); |
|
117 | - } |
|
106 | + /** |
|
107 | + * @param string $key |
|
108 | + * @return string |
|
109 | + */ |
|
110 | + protected function getDate($key) |
|
111 | + { |
|
112 | + $date = strtotime($this->get($key)); |
|
113 | + if (false === $date) { |
|
114 | + $date = time(); |
|
115 | + } |
|
116 | + return get_date_from_gmt(gmdate('Y-m-d H:i:s', $date)); |
|
117 | + } |
|
118 | 118 | |
119 | - /** |
|
120 | - * @param string $key |
|
121 | - * @return string |
|
122 | - */ |
|
123 | - protected function getUser($key) |
|
124 | - { |
|
125 | - $value = $this->get($key); |
|
126 | - if (empty($value)) { |
|
127 | - $user = wp_get_current_user(); |
|
128 | - $userValues = [ |
|
129 | - 'email' => 'user_email', |
|
130 | - 'name' => 'display_name', |
|
131 | - ]; |
|
132 | - if ($user->exists() && array_key_exists($key, $userValues)) { |
|
133 | - return $user->{$userValues[$key]}; |
|
134 | - } |
|
135 | - } |
|
136 | - return $value; |
|
137 | - } |
|
119 | + /** |
|
120 | + * @param string $key |
|
121 | + * @return string |
|
122 | + */ |
|
123 | + protected function getUser($key) |
|
124 | + { |
|
125 | + $value = $this->get($key); |
|
126 | + if (empty($value)) { |
|
127 | + $user = wp_get_current_user(); |
|
128 | + $userValues = [ |
|
129 | + 'email' => 'user_email', |
|
130 | + 'name' => 'display_name', |
|
131 | + ]; |
|
132 | + if ($user->exists() && array_key_exists($key, $userValues)) { |
|
133 | + return $user->{$userValues[$key]}; |
|
134 | + } |
|
135 | + } |
|
136 | + return $value; |
|
137 | + } |
|
138 | 138 | |
139 | - /** |
|
140 | - * @param string $key |
|
141 | - * @return string |
|
142 | - */ |
|
143 | - protected function getNumeric($key) |
|
144 | - { |
|
145 | - $value = $this->get($key); |
|
146 | - return is_numeric($value) |
|
147 | - ? $value |
|
148 | - : ''; |
|
149 | - } |
|
139 | + /** |
|
140 | + * @param string $key |
|
141 | + * @return string |
|
142 | + */ |
|
143 | + protected function getNumeric($key) |
|
144 | + { |
|
145 | + $value = $this->get($key); |
|
146 | + return is_numeric($value) |
|
147 | + ? $value |
|
148 | + : ''; |
|
149 | + } |
|
150 | 150 | } |
@@ -18,249 +18,249 @@ |
||
18 | 18 | |
19 | 19 | class AdminController extends Controller |
20 | 20 | { |
21 | - /** |
|
22 | - * @return void |
|
23 | - * @action admin_enqueue_scripts |
|
24 | - */ |
|
25 | - public function enqueueAssets() |
|
26 | - { |
|
27 | - $command = new EnqueueAdminAssets([ |
|
28 | - 'pointers' => [[ |
|
29 | - 'content' => __('You can pin exceptional reviews so that they are always shown first.', 'site-reviews'), |
|
30 | - 'id' => 'glsr-pointer-pinned', |
|
31 | - 'position' => [ |
|
32 | - 'edge' => 'right', |
|
33 | - 'align' => 'middle', |
|
34 | - ], |
|
35 | - 'screen' => Application::POST_TYPE, |
|
36 | - 'target' => '#misc-pub-pinned', |
|
37 | - 'title' => __('Pin Your Reviews', 'site-reviews'), |
|
38 | - ]], |
|
39 | - ]); |
|
40 | - $this->execute($command); |
|
41 | - } |
|
21 | + /** |
|
22 | + * @return void |
|
23 | + * @action admin_enqueue_scripts |
|
24 | + */ |
|
25 | + public function enqueueAssets() |
|
26 | + { |
|
27 | + $command = new EnqueueAdminAssets([ |
|
28 | + 'pointers' => [[ |
|
29 | + 'content' => __('You can pin exceptional reviews so that they are always shown first.', 'site-reviews'), |
|
30 | + 'id' => 'glsr-pointer-pinned', |
|
31 | + 'position' => [ |
|
32 | + 'edge' => 'right', |
|
33 | + 'align' => 'middle', |
|
34 | + ], |
|
35 | + 'screen' => Application::POST_TYPE, |
|
36 | + 'target' => '#misc-pub-pinned', |
|
37 | + 'title' => __('Pin Your Reviews', 'site-reviews'), |
|
38 | + ]], |
|
39 | + ]); |
|
40 | + $this->execute($command); |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @return array |
|
45 | - * @filter plugin_action_links_site-reviews/site-reviews.php |
|
46 | - */ |
|
47 | - public function filterActionLinks(array $links) |
|
48 | - { |
|
49 | - $links['documentation'] = glsr(Builder::class)->a(__('Help', 'site-reviews'), [ |
|
50 | - 'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=documentation'), |
|
51 | - ]); |
|
52 | - $links['settings'] = glsr(Builder::class)->a(__('Settings', 'site-reviews'), [ |
|
53 | - 'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=settings'), |
|
54 | - ]); |
|
55 | - return $links; |
|
56 | - } |
|
43 | + /** |
|
44 | + * @return array |
|
45 | + * @filter plugin_action_links_site-reviews/site-reviews.php |
|
46 | + */ |
|
47 | + public function filterActionLinks(array $links) |
|
48 | + { |
|
49 | + $links['documentation'] = glsr(Builder::class)->a(__('Help', 'site-reviews'), [ |
|
50 | + 'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=documentation'), |
|
51 | + ]); |
|
52 | + $links['settings'] = glsr(Builder::class)->a(__('Settings', 'site-reviews'), [ |
|
53 | + 'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=settings'), |
|
54 | + ]); |
|
55 | + return $links; |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * @param array $capabilities |
|
60 | - * @param string $capability |
|
61 | - * @return array |
|
62 | - * @filter map_meta_cap |
|
63 | - */ |
|
64 | - public function filterCreateCapability($capabilities, $capability) |
|
65 | - { |
|
66 | - if ($capability == 'create_'.Application::POST_TYPE) { |
|
67 | - $capabilities[] = 'do_not_allow'; |
|
68 | - } |
|
69 | - return $capabilities; |
|
70 | - } |
|
58 | + /** |
|
59 | + * @param array $capabilities |
|
60 | + * @param string $capability |
|
61 | + * @return array |
|
62 | + * @filter map_meta_cap |
|
63 | + */ |
|
64 | + public function filterCreateCapability($capabilities, $capability) |
|
65 | + { |
|
66 | + if ($capability == 'create_'.Application::POST_TYPE) { |
|
67 | + $capabilities[] = 'do_not_allow'; |
|
68 | + } |
|
69 | + return $capabilities; |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * @param array $items |
|
74 | - * @return array |
|
75 | - * @filter dashboard_glance_items |
|
76 | - */ |
|
77 | - public function filterDashboardGlanceItems($items) |
|
78 | - { |
|
79 | - $postCount = wp_count_posts(Application::POST_TYPE); |
|
80 | - if (empty($postCount->publish)) { |
|
81 | - return $items; |
|
82 | - } |
|
83 | - $text = _n('%s Review', '%s Reviews', $postCount->publish, 'site-reviews'); |
|
84 | - $text = sprintf($text, number_format_i18n($postCount->publish)); |
|
85 | - $items = Arr::consolidate($items); |
|
86 | - $items[] = glsr()->can('edit_posts') |
|
87 | - ? glsr(Builder::class)->a($text, [ |
|
88 | - 'class' => 'glsr-review-count', |
|
89 | - 'href' => 'edit.php?post_type='.Application::POST_TYPE, |
|
90 | - ]) |
|
91 | - : glsr(Builder::class)->span($text, [ |
|
92 | - 'class' => 'glsr-review-count', |
|
93 | - ]); |
|
94 | - return $items; |
|
95 | - } |
|
72 | + /** |
|
73 | + * @param array $items |
|
74 | + * @return array |
|
75 | + * @filter dashboard_glance_items |
|
76 | + */ |
|
77 | + public function filterDashboardGlanceItems($items) |
|
78 | + { |
|
79 | + $postCount = wp_count_posts(Application::POST_TYPE); |
|
80 | + if (empty($postCount->publish)) { |
|
81 | + return $items; |
|
82 | + } |
|
83 | + $text = _n('%s Review', '%s Reviews', $postCount->publish, 'site-reviews'); |
|
84 | + $text = sprintf($text, number_format_i18n($postCount->publish)); |
|
85 | + $items = Arr::consolidate($items); |
|
86 | + $items[] = glsr()->can('edit_posts') |
|
87 | + ? glsr(Builder::class)->a($text, [ |
|
88 | + 'class' => 'glsr-review-count', |
|
89 | + 'href' => 'edit.php?post_type='.Application::POST_TYPE, |
|
90 | + ]) |
|
91 | + : glsr(Builder::class)->span($text, [ |
|
92 | + 'class' => 'glsr-review-count', |
|
93 | + ]); |
|
94 | + return $items; |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * @param array $plugins |
|
99 | - * @return array |
|
100 | - * @filter mce_external_plugins |
|
101 | - */ |
|
102 | - public function filterTinymcePlugins($plugins) |
|
103 | - { |
|
104 | - if (glsr()->can('edit_posts')) { |
|
105 | - $plugins = Arr::consolidate($plugins); |
|
106 | - $plugins['glsr_shortcode'] = glsr()->url('assets/scripts/mce-plugin.js'); |
|
107 | - } |
|
108 | - return $plugins; |
|
109 | - } |
|
97 | + /** |
|
98 | + * @param array $plugins |
|
99 | + * @return array |
|
100 | + * @filter mce_external_plugins |
|
101 | + */ |
|
102 | + public function filterTinymcePlugins($plugins) |
|
103 | + { |
|
104 | + if (glsr()->can('edit_posts')) { |
|
105 | + $plugins = Arr::consolidate($plugins); |
|
106 | + $plugins['glsr_shortcode'] = glsr()->url('assets/scripts/mce-plugin.js'); |
|
107 | + } |
|
108 | + return $plugins; |
|
109 | + } |
|
110 | 110 | |
111 | - /** |
|
112 | - * @return void |
|
113 | - * @action admin_init |
|
114 | - */ |
|
115 | - public function registerTinymcePopups() |
|
116 | - { |
|
117 | - $command = new RegisterTinymcePopups([ |
|
118 | - 'site_reviews' => esc_html__('Recent Reviews', 'site-reviews'), |
|
119 | - 'site_reviews_form' => esc_html__('Submit a Review', 'site-reviews'), |
|
120 | - 'site_reviews_summary' => esc_html__('Summary of Reviews', 'site-reviews'), |
|
121 | - ]); |
|
122 | - $this->execute($command); |
|
123 | - } |
|
111 | + /** |
|
112 | + * @return void |
|
113 | + * @action admin_init |
|
114 | + */ |
|
115 | + public function registerTinymcePopups() |
|
116 | + { |
|
117 | + $command = new RegisterTinymcePopups([ |
|
118 | + 'site_reviews' => esc_html__('Recent Reviews', 'site-reviews'), |
|
119 | + 'site_reviews_form' => esc_html__('Submit a Review', 'site-reviews'), |
|
120 | + 'site_reviews_summary' => esc_html__('Summary of Reviews', 'site-reviews'), |
|
121 | + ]); |
|
122 | + $this->execute($command); |
|
123 | + } |
|
124 | 124 | |
125 | - /** |
|
126 | - * @param string $editorId |
|
127 | - * @return void|null |
|
128 | - * @action media_buttons |
|
129 | - */ |
|
130 | - public function renderTinymceButton($editorId) |
|
131 | - { |
|
132 | - $allowedEditors = apply_filters('site-reviews/tinymce/editor-ids', ['content'], $editorId); |
|
133 | - if ('post' != glsr_current_screen()->base || !in_array($editorId, $allowedEditors)) { |
|
134 | - return; |
|
135 | - } |
|
136 | - $shortcodes = []; |
|
137 | - foreach (glsr()->mceShortcodes as $shortcode => $values) { |
|
138 | - $shortcodes[$shortcode] = $values; |
|
139 | - } |
|
140 | - if (empty($shortcodes)) { |
|
141 | - return; |
|
142 | - } |
|
143 | - glsr()->render('partials/editor/tinymce', [ |
|
144 | - 'shortcodes' => $shortcodes, |
|
145 | - ]); |
|
146 | - } |
|
125 | + /** |
|
126 | + * @param string $editorId |
|
127 | + * @return void|null |
|
128 | + * @action media_buttons |
|
129 | + */ |
|
130 | + public function renderTinymceButton($editorId) |
|
131 | + { |
|
132 | + $allowedEditors = apply_filters('site-reviews/tinymce/editor-ids', ['content'], $editorId); |
|
133 | + if ('post' != glsr_current_screen()->base || !in_array($editorId, $allowedEditors)) { |
|
134 | + return; |
|
135 | + } |
|
136 | + $shortcodes = []; |
|
137 | + foreach (glsr()->mceShortcodes as $shortcode => $values) { |
|
138 | + $shortcodes[$shortcode] = $values; |
|
139 | + } |
|
140 | + if (empty($shortcodes)) { |
|
141 | + return; |
|
142 | + } |
|
143 | + glsr()->render('partials/editor/tinymce', [ |
|
144 | + 'shortcodes' => $shortcodes, |
|
145 | + ]); |
|
146 | + } |
|
147 | 147 | |
148 | - /** |
|
149 | - * @return void |
|
150 | - */ |
|
151 | - public function routerClearConsole() |
|
152 | - { |
|
153 | - glsr(Console::class)->clear(); |
|
154 | - glsr(Notice::class)->addSuccess(__('Console cleared.', 'site-reviews')); |
|
155 | - } |
|
148 | + /** |
|
149 | + * @return void |
|
150 | + */ |
|
151 | + public function routerClearConsole() |
|
152 | + { |
|
153 | + glsr(Console::class)->clear(); |
|
154 | + glsr(Notice::class)->addSuccess(__('Console cleared.', 'site-reviews')); |
|
155 | + } |
|
156 | 156 | |
157 | - /** |
|
158 | - * @return void |
|
159 | - */ |
|
160 | - public function routerCountReviews() |
|
161 | - { |
|
162 | - glsr(CountsManager::class)->updateAll(); |
|
163 | - glsr(Notice::class)->clear()->addSuccess(__('Recalculated rating counts.', 'site-reviews')); |
|
164 | - } |
|
157 | + /** |
|
158 | + * @return void |
|
159 | + */ |
|
160 | + public function routerCountReviews() |
|
161 | + { |
|
162 | + glsr(CountsManager::class)->updateAll(); |
|
163 | + glsr(Notice::class)->clear()->addSuccess(__('Recalculated rating counts.', 'site-reviews')); |
|
164 | + } |
|
165 | 165 | |
166 | - /** |
|
167 | - * @return void |
|
168 | - */ |
|
169 | - public function routerDownloadConsole() |
|
170 | - { |
|
171 | - $this->download(Application::ID.'-console.txt', glsr(Console::class)->get()); |
|
172 | - } |
|
166 | + /** |
|
167 | + * @return void |
|
168 | + */ |
|
169 | + public function routerDownloadConsole() |
|
170 | + { |
|
171 | + $this->download(Application::ID.'-console.txt', glsr(Console::class)->get()); |
|
172 | + } |
|
173 | 173 | |
174 | - /** |
|
175 | - * @return void |
|
176 | - */ |
|
177 | - public function routerDownloadSystemInfo() |
|
178 | - { |
|
179 | - $this->download(Application::ID.'-system-info.txt', glsr(System::class)->get()); |
|
180 | - } |
|
174 | + /** |
|
175 | + * @return void |
|
176 | + */ |
|
177 | + public function routerDownloadSystemInfo() |
|
178 | + { |
|
179 | + $this->download(Application::ID.'-system-info.txt', glsr(System::class)->get()); |
|
180 | + } |
|
181 | 181 | |
182 | - /** |
|
183 | - * @return void |
|
184 | - */ |
|
185 | - public function routerExportSettings() |
|
186 | - { |
|
187 | - $this->download(Application::ID.'-settings.json', glsr(OptionManager::class)->json()); |
|
188 | - } |
|
182 | + /** |
|
183 | + * @return void |
|
184 | + */ |
|
185 | + public function routerExportSettings() |
|
186 | + { |
|
187 | + $this->download(Application::ID.'-settings.json', glsr(OptionManager::class)->json()); |
|
188 | + } |
|
189 | 189 | |
190 | - /** |
|
191 | - * @return void |
|
192 | - */ |
|
193 | - public function routerFetchConsole() |
|
194 | - { |
|
195 | - glsr(Notice::class)->addSuccess(__('Console reloaded.', 'site-reviews')); |
|
196 | - } |
|
190 | + /** |
|
191 | + * @return void |
|
192 | + */ |
|
193 | + public function routerFetchConsole() |
|
194 | + { |
|
195 | + glsr(Notice::class)->addSuccess(__('Console reloaded.', 'site-reviews')); |
|
196 | + } |
|
197 | 197 | |
198 | - /** |
|
199 | - * @return void |
|
200 | - */ |
|
201 | - public function routerImportSettings() |
|
202 | - { |
|
203 | - $file = $_FILES['import-file']; |
|
204 | - if (UPLOAD_ERR_OK !== $file['error']) { |
|
205 | - return glsr(Notice::class)->addError($this->getUploadError($file['error'])); |
|
206 | - } |
|
207 | - if ('application/json' !== $file['type'] || !Str::endsWith('.json', $file['name'])) { |
|
208 | - return glsr(Notice::class)->addError(__('Please use a valid Site Reviews settings file.', 'site-reviews')); |
|
209 | - } |
|
210 | - $settings = json_decode(file_get_contents($file['tmp_name']), true); |
|
211 | - if (empty($settings)) { |
|
212 | - return glsr(Notice::class)->addWarning(__('There were no settings found to import.', 'site-reviews')); |
|
213 | - } |
|
214 | - glsr(OptionManager::class)->set(glsr(OptionManager::class)->normalize($settings)); |
|
215 | - glsr(Notice::class)->addSuccess(__('Settings imported.', 'site-reviews')); |
|
216 | - } |
|
198 | + /** |
|
199 | + * @return void |
|
200 | + */ |
|
201 | + public function routerImportSettings() |
|
202 | + { |
|
203 | + $file = $_FILES['import-file']; |
|
204 | + if (UPLOAD_ERR_OK !== $file['error']) { |
|
205 | + return glsr(Notice::class)->addError($this->getUploadError($file['error'])); |
|
206 | + } |
|
207 | + if ('application/json' !== $file['type'] || !Str::endsWith('.json', $file['name'])) { |
|
208 | + return glsr(Notice::class)->addError(__('Please use a valid Site Reviews settings file.', 'site-reviews')); |
|
209 | + } |
|
210 | + $settings = json_decode(file_get_contents($file['tmp_name']), true); |
|
211 | + if (empty($settings)) { |
|
212 | + return glsr(Notice::class)->addWarning(__('There were no settings found to import.', 'site-reviews')); |
|
213 | + } |
|
214 | + glsr(OptionManager::class)->set(glsr(OptionManager::class)->normalize($settings)); |
|
215 | + glsr(Notice::class)->addSuccess(__('Settings imported.', 'site-reviews')); |
|
216 | + } |
|
217 | 217 | |
218 | - /** |
|
219 | - * @return void |
|
220 | - */ |
|
221 | - public function routerMigrateReviews() |
|
222 | - { |
|
223 | - glsr(Migrate::class)->runAll(); |
|
224 | - glsr(Notice::class)->clear()->addSuccess(__('The plugin has been migrated to the latest version.', 'site-reviews')); |
|
225 | - } |
|
218 | + /** |
|
219 | + * @return void |
|
220 | + */ |
|
221 | + public function routerMigrateReviews() |
|
222 | + { |
|
223 | + glsr(Migrate::class)->runAll(); |
|
224 | + glsr(Notice::class)->clear()->addSuccess(__('The plugin has been migrated to the latest version.', 'site-reviews')); |
|
225 | + } |
|
226 | 226 | |
227 | - /** |
|
228 | - * @return void |
|
229 | - */ |
|
230 | - public function routerResetPermissions() |
|
231 | - { |
|
232 | - glsr(Role::class)->resetAll(); |
|
233 | - glsr(Notice::class)->clear()->addSuccess(__('The permissions have been reset.', 'site-reviews')); |
|
234 | - } |
|
227 | + /** |
|
228 | + * @return void |
|
229 | + */ |
|
230 | + public function routerResetPermissions() |
|
231 | + { |
|
232 | + glsr(Role::class)->resetAll(); |
|
233 | + glsr(Notice::class)->clear()->addSuccess(__('The permissions have been reset.', 'site-reviews')); |
|
234 | + } |
|
235 | 235 | |
236 | - /** |
|
237 | - * @return void |
|
238 | - * @action admin_init |
|
239 | - */ |
|
240 | - public function runMigrations() |
|
241 | - { |
|
242 | - if (glsr(Migrate::class)->isMigrationNeeded()) { |
|
243 | - if (glsr(Migrate::class)->run()) { |
|
244 | - glsr(CountsManager::class)->updateAll(); |
|
245 | - } |
|
246 | - } |
|
247 | - } |
|
236 | + /** |
|
237 | + * @return void |
|
238 | + * @action admin_init |
|
239 | + */ |
|
240 | + public function runMigrations() |
|
241 | + { |
|
242 | + if (glsr(Migrate::class)->isMigrationNeeded()) { |
|
243 | + if (glsr(Migrate::class)->run()) { |
|
244 | + glsr(CountsManager::class)->updateAll(); |
|
245 | + } |
|
246 | + } |
|
247 | + } |
|
248 | 248 | |
249 | - /** |
|
250 | - * @param int $errorCode |
|
251 | - * @return string |
|
252 | - */ |
|
253 | - protected function getUploadError($errorCode) |
|
254 | - { |
|
255 | - $errors = [ |
|
256 | - UPLOAD_ERR_INI_SIZE => __('The uploaded file exceeds the upload_max_filesize directive in php.ini.', 'site-reviews'), |
|
257 | - UPLOAD_ERR_FORM_SIZE => __('The uploaded file is too big.', 'site-reviews'), |
|
258 | - UPLOAD_ERR_PARTIAL => __('The uploaded file was only partially uploaded.', 'site-reviews'), |
|
259 | - UPLOAD_ERR_NO_FILE => __('No file was uploaded.', 'site-reviews'), |
|
260 | - UPLOAD_ERR_NO_TMP_DIR => __('Missing a temporary folder.', 'site-reviews'), |
|
261 | - UPLOAD_ERR_CANT_WRITE => __('Failed to write file to disk.', 'site-reviews'), |
|
262 | - UPLOAD_ERR_EXTENSION => __('A PHP extension stopped the file upload.', 'site-reviews'), |
|
263 | - ]; |
|
264 | - return Arr::get($errors, $errorCode, __('Unknown upload error.', 'site-reviews')); |
|
265 | - } |
|
249 | + /** |
|
250 | + * @param int $errorCode |
|
251 | + * @return string |
|
252 | + */ |
|
253 | + protected function getUploadError($errorCode) |
|
254 | + { |
|
255 | + $errors = [ |
|
256 | + UPLOAD_ERR_INI_SIZE => __('The uploaded file exceeds the upload_max_filesize directive in php.ini.', 'site-reviews'), |
|
257 | + UPLOAD_ERR_FORM_SIZE => __('The uploaded file is too big.', 'site-reviews'), |
|
258 | + UPLOAD_ERR_PARTIAL => __('The uploaded file was only partially uploaded.', 'site-reviews'), |
|
259 | + UPLOAD_ERR_NO_FILE => __('No file was uploaded.', 'site-reviews'), |
|
260 | + UPLOAD_ERR_NO_TMP_DIR => __('Missing a temporary folder.', 'site-reviews'), |
|
261 | + UPLOAD_ERR_CANT_WRITE => __('Failed to write file to disk.', 'site-reviews'), |
|
262 | + UPLOAD_ERR_EXTENSION => __('A PHP extension stopped the file upload.', 'site-reviews'), |
|
263 | + ]; |
|
264 | + return Arr::get($errors, $errorCode, __('Unknown upload error.', 'site-reviews')); |
|
265 | + } |
|
266 | 266 | } |
@@ -12,163 +12,163 @@ |
||
12 | 12 | |
13 | 13 | class SettingsController extends Controller |
14 | 14 | { |
15 | - /** |
|
16 | - * @param mixed $input |
|
17 | - * @return array |
|
18 | - * @callback register_setting |
|
19 | - */ |
|
20 | - public function callbackRegisterSettings($input) |
|
21 | - { |
|
22 | - $settings = Arr::consolidate($input); |
|
23 | - if (1 === count($settings) && array_key_exists('settings', $settings)) { |
|
24 | - $options = array_replace_recursive(glsr(OptionManager::class)->all(), $input); |
|
25 | - $options = $this->sanitizeGeneral($input, $options); |
|
26 | - $options = $this->sanitizeLicenses($input, $options); |
|
27 | - $options = $this->sanitizeSubmissions($input, $options); |
|
28 | - $options = $this->sanitizeTranslations($input, $options); |
|
29 | - $options = apply_filters('site-reviews/settings/callback', $options, $settings); |
|
30 | - if (filter_input(INPUT_POST, 'option_page') == Application::ID.'-settings') { |
|
31 | - glsr(Notice::class)->addSuccess(__('Settings updated.', 'site-reviews')); |
|
32 | - } |
|
33 | - return $options; |
|
34 | - } |
|
35 | - return $input; |
|
36 | - } |
|
15 | + /** |
|
16 | + * @param mixed $input |
|
17 | + * @return array |
|
18 | + * @callback register_setting |
|
19 | + */ |
|
20 | + public function callbackRegisterSettings($input) |
|
21 | + { |
|
22 | + $settings = Arr::consolidate($input); |
|
23 | + if (1 === count($settings) && array_key_exists('settings', $settings)) { |
|
24 | + $options = array_replace_recursive(glsr(OptionManager::class)->all(), $input); |
|
25 | + $options = $this->sanitizeGeneral($input, $options); |
|
26 | + $options = $this->sanitizeLicenses($input, $options); |
|
27 | + $options = $this->sanitizeSubmissions($input, $options); |
|
28 | + $options = $this->sanitizeTranslations($input, $options); |
|
29 | + $options = apply_filters('site-reviews/settings/callback', $options, $settings); |
|
30 | + if (filter_input(INPUT_POST, 'option_page') == Application::ID.'-settings') { |
|
31 | + glsr(Notice::class)->addSuccess(__('Settings updated.', 'site-reviews')); |
|
32 | + } |
|
33 | + return $options; |
|
34 | + } |
|
35 | + return $input; |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * @return void |
|
40 | - * @action admin_init |
|
41 | - */ |
|
42 | - public function registerSettings() |
|
43 | - { |
|
44 | - register_setting(Application::ID.'-settings', OptionManager::databaseKey(), [ |
|
45 | - 'sanitize_callback' => [$this, 'callbackRegisterSettings'], |
|
46 | - ]); |
|
47 | - } |
|
38 | + /** |
|
39 | + * @return void |
|
40 | + * @action admin_init |
|
41 | + */ |
|
42 | + public function registerSettings() |
|
43 | + { |
|
44 | + register_setting(Application::ID.'-settings', OptionManager::databaseKey(), [ |
|
45 | + 'sanitize_callback' => [$this, 'callbackRegisterSettings'], |
|
46 | + ]); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * @return array |
|
51 | - */ |
|
52 | - protected function sanitizeGeneral(array $input, array $options) |
|
53 | - { |
|
54 | - $key = 'settings.general'; |
|
55 | - $inputForm = Arr::get($input, $key); |
|
56 | - if (!$this->hasMultilingualIntegration(Arr::get($inputForm, 'multilingual'))) { |
|
57 | - $options = Arr::set($options, $key.'.multilingual', ''); |
|
58 | - } |
|
59 | - if ('' == trim(Arr::get($inputForm, 'notification_message'))) { |
|
60 | - $defaultValue = Arr::get(glsr()->defaults, $key.'.notification_message'); |
|
61 | - $options = Arr::set($options, $key.'.notification_message', $defaultValue); |
|
62 | - } |
|
63 | - $defaultValue = Arr::get($inputForm, 'notifications', []); |
|
64 | - $options = Arr::set($options, $key.'.notifications', $defaultValue); |
|
65 | - return $options; |
|
66 | - } |
|
49 | + /** |
|
50 | + * @return array |
|
51 | + */ |
|
52 | + protected function sanitizeGeneral(array $input, array $options) |
|
53 | + { |
|
54 | + $key = 'settings.general'; |
|
55 | + $inputForm = Arr::get($input, $key); |
|
56 | + if (!$this->hasMultilingualIntegration(Arr::get($inputForm, 'multilingual'))) { |
|
57 | + $options = Arr::set($options, $key.'.multilingual', ''); |
|
58 | + } |
|
59 | + if ('' == trim(Arr::get($inputForm, 'notification_message'))) { |
|
60 | + $defaultValue = Arr::get(glsr()->defaults, $key.'.notification_message'); |
|
61 | + $options = Arr::set($options, $key.'.notification_message', $defaultValue); |
|
62 | + } |
|
63 | + $defaultValue = Arr::get($inputForm, 'notifications', []); |
|
64 | + $options = Arr::set($options, $key.'.notifications', $defaultValue); |
|
65 | + return $options; |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @return array |
|
70 | - */ |
|
71 | - protected function sanitizeLicenses(array $input, array $options) |
|
72 | - { |
|
73 | - $key = 'settings.licenses'; |
|
74 | - $licenses = Arr::consolidate(Arr::get($input, $key)); |
|
75 | - foreach ($licenses as $slug => &$license) { |
|
76 | - if (empty($license)) { |
|
77 | - continue; |
|
78 | - } |
|
79 | - $license = $this->verifyLicense($license, $slug); |
|
80 | - } |
|
81 | - $options = Arr::set($options, $key, $licenses); |
|
82 | - return $options; |
|
83 | - } |
|
68 | + /** |
|
69 | + * @return array |
|
70 | + */ |
|
71 | + protected function sanitizeLicenses(array $input, array $options) |
|
72 | + { |
|
73 | + $key = 'settings.licenses'; |
|
74 | + $licenses = Arr::consolidate(Arr::get($input, $key)); |
|
75 | + foreach ($licenses as $slug => &$license) { |
|
76 | + if (empty($license)) { |
|
77 | + continue; |
|
78 | + } |
|
79 | + $license = $this->verifyLicense($license, $slug); |
|
80 | + } |
|
81 | + $options = Arr::set($options, $key, $licenses); |
|
82 | + return $options; |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * @return array |
|
87 | - */ |
|
88 | - protected function sanitizeSubmissions(array $input, array $options) |
|
89 | - { |
|
90 | - $key = 'settings.submissions'; |
|
91 | - $inputForm = Arr::get($input, $key); |
|
92 | - $defaultValue = isset($inputForm['required']) |
|
93 | - ? $inputForm['required'] |
|
94 | - : []; |
|
95 | - $options = Arr::set($options, $key.'.required', $defaultValue); |
|
96 | - return $options; |
|
97 | - } |
|
85 | + /** |
|
86 | + * @return array |
|
87 | + */ |
|
88 | + protected function sanitizeSubmissions(array $input, array $options) |
|
89 | + { |
|
90 | + $key = 'settings.submissions'; |
|
91 | + $inputForm = Arr::get($input, $key); |
|
92 | + $defaultValue = isset($inputForm['required']) |
|
93 | + ? $inputForm['required'] |
|
94 | + : []; |
|
95 | + $options = Arr::set($options, $key.'.required', $defaultValue); |
|
96 | + return $options; |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * @return array |
|
101 | - */ |
|
102 | - protected function sanitizeTranslations(array $input, array $options) |
|
103 | - { |
|
104 | - $key = 'settings.strings'; |
|
105 | - $inputForm = Arr::consolidate(Arr::get($input, $key)); |
|
106 | - if (!empty($inputForm)) { |
|
107 | - $options = Arr::set($options, $key, array_values(array_filter($inputForm))); |
|
108 | - $allowedTags = [ |
|
109 | - 'a' => ['class' => [], 'href' => [], 'target' => []], |
|
110 | - 'span' => ['class' => []], |
|
111 | - ]; |
|
112 | - array_walk($options['settings']['strings'], function (&$string) use ($allowedTags) { |
|
113 | - if (isset($string['s2'])) { |
|
114 | - $string['s2'] = wp_kses($string['s2'], $allowedTags); |
|
115 | - } |
|
116 | - if (isset($string['p2'])) { |
|
117 | - $string['p2'] = wp_kses($string['p2'], $allowedTags); |
|
118 | - } |
|
119 | - }); |
|
120 | - } |
|
121 | - return $options; |
|
122 | - } |
|
99 | + /** |
|
100 | + * @return array |
|
101 | + */ |
|
102 | + protected function sanitizeTranslations(array $input, array $options) |
|
103 | + { |
|
104 | + $key = 'settings.strings'; |
|
105 | + $inputForm = Arr::consolidate(Arr::get($input, $key)); |
|
106 | + if (!empty($inputForm)) { |
|
107 | + $options = Arr::set($options, $key, array_values(array_filter($inputForm))); |
|
108 | + $allowedTags = [ |
|
109 | + 'a' => ['class' => [], 'href' => [], 'target' => []], |
|
110 | + 'span' => ['class' => []], |
|
111 | + ]; |
|
112 | + array_walk($options['settings']['strings'], function (&$string) use ($allowedTags) { |
|
113 | + if (isset($string['s2'])) { |
|
114 | + $string['s2'] = wp_kses($string['s2'], $allowedTags); |
|
115 | + } |
|
116 | + if (isset($string['p2'])) { |
|
117 | + $string['p2'] = wp_kses($string['p2'], $allowedTags); |
|
118 | + } |
|
119 | + }); |
|
120 | + } |
|
121 | + return $options; |
|
122 | + } |
|
123 | 123 | |
124 | - /** |
|
125 | - * @param string $integrationSlug |
|
126 | - * @return bool |
|
127 | - */ |
|
128 | - protected function hasMultilingualIntegration($integrationSlug) |
|
129 | - { |
|
130 | - $integration = glsr(Multilingual::class)->getIntegration($integrationSlug); |
|
131 | - if (!$integration) { |
|
132 | - return false; |
|
133 | - } |
|
134 | - if (!$integration->isActive()) { |
|
135 | - glsr(Notice::class)->addError(sprintf( |
|
136 | - __('Please install/activate the %s plugin to enable integration.', 'site-reviews'), |
|
137 | - $integration->pluginName |
|
138 | - )); |
|
139 | - return false; |
|
140 | - } elseif (!$integration->isSupported()) { |
|
141 | - glsr(Notice::class)->addError(sprintf( |
|
142 | - __('Please update the %s plugin to v%s or greater to enable integration.', 'site-reviews'), |
|
143 | - $integration->pluginName, |
|
144 | - $integration->supportedVersion |
|
145 | - )); |
|
146 | - return false; |
|
147 | - } |
|
148 | - return true; |
|
149 | - } |
|
124 | + /** |
|
125 | + * @param string $integrationSlug |
|
126 | + * @return bool |
|
127 | + */ |
|
128 | + protected function hasMultilingualIntegration($integrationSlug) |
|
129 | + { |
|
130 | + $integration = glsr(Multilingual::class)->getIntegration($integrationSlug); |
|
131 | + if (!$integration) { |
|
132 | + return false; |
|
133 | + } |
|
134 | + if (!$integration->isActive()) { |
|
135 | + glsr(Notice::class)->addError(sprintf( |
|
136 | + __('Please install/activate the %s plugin to enable integration.', 'site-reviews'), |
|
137 | + $integration->pluginName |
|
138 | + )); |
|
139 | + return false; |
|
140 | + } elseif (!$integration->isSupported()) { |
|
141 | + glsr(Notice::class)->addError(sprintf( |
|
142 | + __('Please update the %s plugin to v%s or greater to enable integration.', 'site-reviews'), |
|
143 | + $integration->pluginName, |
|
144 | + $integration->supportedVersion |
|
145 | + )); |
|
146 | + return false; |
|
147 | + } |
|
148 | + return true; |
|
149 | + } |
|
150 | 150 | |
151 | - /** |
|
152 | - * @param string $license |
|
153 | - * @param string $slug |
|
154 | - * @return string |
|
155 | - */ |
|
156 | - protected function verifyLicense($license, $slug) |
|
157 | - { |
|
158 | - try { |
|
159 | - $addon = glsr($slug); |
|
160 | - $updater = new Updater($addon->update_url, $addon->file, [ |
|
161 | - 'license' => $license, |
|
162 | - 'testedTo' => $addon->testedTo, |
|
163 | - ]); |
|
164 | - if (!$updater->isLicenseValid()) { |
|
165 | - throw new Exception('Invalid license: '.$license.' ('.$addon->id.')'); |
|
166 | - } |
|
167 | - } catch (Exception $e) { |
|
168 | - $license = ''; |
|
169 | - glsr_log()->debug($e->getMessage()); |
|
170 | - glsr(Notice::class)->addError(__('A license you entered was invalid.', 'site-reviews')); |
|
171 | - } |
|
172 | - return $license; |
|
173 | - } |
|
151 | + /** |
|
152 | + * @param string $license |
|
153 | + * @param string $slug |
|
154 | + * @return string |
|
155 | + */ |
|
156 | + protected function verifyLicense($license, $slug) |
|
157 | + { |
|
158 | + try { |
|
159 | + $addon = glsr($slug); |
|
160 | + $updater = new Updater($addon->update_url, $addon->file, [ |
|
161 | + 'license' => $license, |
|
162 | + 'testedTo' => $addon->testedTo, |
|
163 | + ]); |
|
164 | + if (!$updater->isLicenseValid()) { |
|
165 | + throw new Exception('Invalid license: '.$license.' ('.$addon->id.')'); |
|
166 | + } |
|
167 | + } catch (Exception $e) { |
|
168 | + $license = ''; |
|
169 | + glsr_log()->debug($e->getMessage()); |
|
170 | + glsr(Notice::class)->addError(__('A license you entered was invalid.', 'site-reviews')); |
|
171 | + } |
|
172 | + return $license; |
|
173 | + } |
|
174 | 174 | } |
@@ -20,402 +20,402 @@ |
||
20 | 20 | |
21 | 21 | class EditorController extends Controller |
22 | 22 | { |
23 | - /** |
|
24 | - * @param array $settings |
|
25 | - * @return array |
|
26 | - * @filter wp_editor_settings |
|
27 | - */ |
|
28 | - public function filterEditorSettings($settings) |
|
29 | - { |
|
30 | - return glsr(Customization::class)->filterEditorSettings( |
|
31 | - Arr::consolidate($settings) |
|
32 | - ); |
|
33 | - } |
|
23 | + /** |
|
24 | + * @param array $settings |
|
25 | + * @return array |
|
26 | + * @filter wp_editor_settings |
|
27 | + */ |
|
28 | + public function filterEditorSettings($settings) |
|
29 | + { |
|
30 | + return glsr(Customization::class)->filterEditorSettings( |
|
31 | + Arr::consolidate($settings) |
|
32 | + ); |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * Modify the WP_Editor html to allow autosizing without breaking the `editor-expand` script. |
|
37 | - * @param string $html |
|
38 | - * @return string |
|
39 | - * @filter the_editor |
|
40 | - */ |
|
41 | - public function filterEditorTextarea($html) |
|
42 | - { |
|
43 | - return glsr(Customization::class)->filterEditorTextarea($html); |
|
44 | - } |
|
35 | + /** |
|
36 | + * Modify the WP_Editor html to allow autosizing without breaking the `editor-expand` script. |
|
37 | + * @param string $html |
|
38 | + * @return string |
|
39 | + * @filter the_editor |
|
40 | + */ |
|
41 | + public function filterEditorTextarea($html) |
|
42 | + { |
|
43 | + return glsr(Customization::class)->filterEditorTextarea($html); |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * @param bool $protected |
|
48 | - * @param string $metaKey |
|
49 | - * @param string $metaType |
|
50 | - * @return bool |
|
51 | - * @filter is_protected_meta |
|
52 | - */ |
|
53 | - public function filterIsProtectedMeta($protected, $metaKey, $metaType) |
|
54 | - { |
|
55 | - if ('post' == $metaType && Application::POST_TYPE == get_post_type()) { |
|
56 | - $values = glsr(CreateReviewDefaults::class)->unguarded(); |
|
57 | - $values = Arr::prefixKeys($values); |
|
58 | - if (array_key_exists($metaKey, $values)) { |
|
59 | - $protected = false; |
|
60 | - } |
|
61 | - } |
|
62 | - return $protected; |
|
63 | - } |
|
46 | + /** |
|
47 | + * @param bool $protected |
|
48 | + * @param string $metaKey |
|
49 | + * @param string $metaType |
|
50 | + * @return bool |
|
51 | + * @filter is_protected_meta |
|
52 | + */ |
|
53 | + public function filterIsProtectedMeta($protected, $metaKey, $metaType) |
|
54 | + { |
|
55 | + if ('post' == $metaType && Application::POST_TYPE == get_post_type()) { |
|
56 | + $values = glsr(CreateReviewDefaults::class)->unguarded(); |
|
57 | + $values = Arr::prefixKeys($values); |
|
58 | + if (array_key_exists($metaKey, $values)) { |
|
59 | + $protected = false; |
|
60 | + } |
|
61 | + } |
|
62 | + return $protected; |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * @param array $messages |
|
67 | - * @return array |
|
68 | - * @filter post_updated_messages |
|
69 | - */ |
|
70 | - public function filterUpdateMessages($messages) |
|
71 | - { |
|
72 | - return glsr(Labels::class)->filterUpdateMessages( |
|
73 | - Arr::consolidate($messages) |
|
74 | - ); |
|
75 | - } |
|
65 | + /** |
|
66 | + * @param array $messages |
|
67 | + * @return array |
|
68 | + * @filter post_updated_messages |
|
69 | + */ |
|
70 | + public function filterUpdateMessages($messages) |
|
71 | + { |
|
72 | + return glsr(Labels::class)->filterUpdateMessages( |
|
73 | + Arr::consolidate($messages) |
|
74 | + ); |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * @return void |
|
79 | - * @action add_meta_boxes_{Application::POST_TYPE} |
|
80 | - */ |
|
81 | - public function registerMetaBoxes($post) |
|
82 | - { |
|
83 | - add_meta_box(Application::ID.'_assigned_to', __('Assigned To', 'site-reviews'), [$this, 'renderAssignedToMetabox'], null, 'side'); |
|
84 | - add_meta_box(Application::ID.'_review', __('Details', 'site-reviews'), [$this, 'renderDetailsMetaBox'], null, 'side'); |
|
85 | - if ('local' != glsr(Database::class)->get($post->ID, 'review_type')) { |
|
86 | - return; |
|
87 | - } |
|
88 | - add_meta_box(Application::ID.'_response', __('Respond Publicly', 'site-reviews'), [$this, 'renderResponseMetaBox'], null, 'normal'); |
|
89 | - } |
|
77 | + /** |
|
78 | + * @return void |
|
79 | + * @action add_meta_boxes_{Application::POST_TYPE} |
|
80 | + */ |
|
81 | + public function registerMetaBoxes($post) |
|
82 | + { |
|
83 | + add_meta_box(Application::ID.'_assigned_to', __('Assigned To', 'site-reviews'), [$this, 'renderAssignedToMetabox'], null, 'side'); |
|
84 | + add_meta_box(Application::ID.'_review', __('Details', 'site-reviews'), [$this, 'renderDetailsMetaBox'], null, 'side'); |
|
85 | + if ('local' != glsr(Database::class)->get($post->ID, 'review_type')) { |
|
86 | + return; |
|
87 | + } |
|
88 | + add_meta_box(Application::ID.'_response', __('Respond Publicly', 'site-reviews'), [$this, 'renderResponseMetaBox'], null, 'normal'); |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * @return void |
|
93 | - * @action admin_print_scripts |
|
94 | - */ |
|
95 | - public function removeAutosave() |
|
96 | - { |
|
97 | - glsr(Customization::class)->removeAutosave(); |
|
98 | - } |
|
91 | + /** |
|
92 | + * @return void |
|
93 | + * @action admin_print_scripts |
|
94 | + */ |
|
95 | + public function removeAutosave() |
|
96 | + { |
|
97 | + glsr(Customization::class)->removeAutosave(); |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * @return void |
|
102 | - * @action admin_menu |
|
103 | - */ |
|
104 | - public function removeMetaBoxes() |
|
105 | - { |
|
106 | - glsr(Customization::class)->removeMetaBoxes(); |
|
107 | - } |
|
100 | + /** |
|
101 | + * @return void |
|
102 | + * @action admin_menu |
|
103 | + */ |
|
104 | + public function removeMetaBoxes() |
|
105 | + { |
|
106 | + glsr(Customization::class)->removeMetaBoxes(); |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * @return void |
|
111 | - */ |
|
112 | - public function removePostTypeSupport() |
|
113 | - { |
|
114 | - glsr(Customization::class)->removePostTypeSupport(); |
|
115 | - } |
|
109 | + /** |
|
110 | + * @return void |
|
111 | + */ |
|
112 | + public function removePostTypeSupport() |
|
113 | + { |
|
114 | + glsr(Customization::class)->removePostTypeSupport(); |
|
115 | + } |
|
116 | 116 | |
117 | - /** |
|
118 | - * @param WP_Post $post |
|
119 | - * @return void |
|
120 | - * @callback add_meta_box |
|
121 | - */ |
|
122 | - public function renderAssignedToMetabox($post) |
|
123 | - { |
|
124 | - if (!$this->isReviewPostType($post)) { |
|
125 | - return; |
|
126 | - } |
|
127 | - $assignedTo = (string) glsr(Database::class)->get($post->ID, 'assigned_to'); |
|
128 | - wp_nonce_field('assigned_to', '_nonce-assigned-to', false); |
|
129 | - glsr()->render('partials/editor/metabox-assigned-to', [ |
|
130 | - 'id' => $assignedTo, |
|
131 | - 'template' => $this->buildAssignedToTemplate($assignedTo, $post), |
|
132 | - ]); |
|
133 | - } |
|
117 | + /** |
|
118 | + * @param WP_Post $post |
|
119 | + * @return void |
|
120 | + * @callback add_meta_box |
|
121 | + */ |
|
122 | + public function renderAssignedToMetabox($post) |
|
123 | + { |
|
124 | + if (!$this->isReviewPostType($post)) { |
|
125 | + return; |
|
126 | + } |
|
127 | + $assignedTo = (string) glsr(Database::class)->get($post->ID, 'assigned_to'); |
|
128 | + wp_nonce_field('assigned_to', '_nonce-assigned-to', false); |
|
129 | + glsr()->render('partials/editor/metabox-assigned-to', [ |
|
130 | + 'id' => $assignedTo, |
|
131 | + 'template' => $this->buildAssignedToTemplate($assignedTo, $post), |
|
132 | + ]); |
|
133 | + } |
|
134 | 134 | |
135 | - /** |
|
136 | - * @param WP_Post $post |
|
137 | - * @return void |
|
138 | - * @callback add_meta_box |
|
139 | - */ |
|
140 | - public function renderDetailsMetaBox($post) |
|
141 | - { |
|
142 | - if (!$this->isReviewPostType($post)) { |
|
143 | - return; |
|
144 | - } |
|
145 | - $review = glsr_get_review($post); |
|
146 | - glsr()->render('partials/editor/metabox-details', [ |
|
147 | - 'button' => $this->buildDetailsMetaBoxRevertButton($review, $post), |
|
148 | - 'metabox' => $this->normalizeDetailsMetaBox($review), |
|
149 | - ]); |
|
150 | - } |
|
135 | + /** |
|
136 | + * @param WP_Post $post |
|
137 | + * @return void |
|
138 | + * @callback add_meta_box |
|
139 | + */ |
|
140 | + public function renderDetailsMetaBox($post) |
|
141 | + { |
|
142 | + if (!$this->isReviewPostType($post)) { |
|
143 | + return; |
|
144 | + } |
|
145 | + $review = glsr_get_review($post); |
|
146 | + glsr()->render('partials/editor/metabox-details', [ |
|
147 | + 'button' => $this->buildDetailsMetaBoxRevertButton($review, $post), |
|
148 | + 'metabox' => $this->normalizeDetailsMetaBox($review), |
|
149 | + ]); |
|
150 | + } |
|
151 | 151 | |
152 | - /** |
|
153 | - * @return void |
|
154 | - * @action post_submitbox_misc_actions |
|
155 | - */ |
|
156 | - public function renderPinnedInPublishMetaBox() |
|
157 | - { |
|
158 | - if (!$this->isReviewPostType(get_post()) |
|
159 | - || !glsr()->can('edit_others_posts')) { |
|
160 | - return; |
|
161 | - } |
|
162 | - glsr(Template::class)->render('partials/editor/pinned', [ |
|
163 | - 'context' => [ |
|
164 | - 'no' => __('No', 'site-reviews'), |
|
165 | - 'yes' => __('Yes', 'site-reviews'), |
|
166 | - ], |
|
167 | - 'pinned' => wp_validate_boolean(glsr(Database::class)->get(get_the_ID(), 'pinned')), |
|
168 | - ]); |
|
169 | - } |
|
152 | + /** |
|
153 | + * @return void |
|
154 | + * @action post_submitbox_misc_actions |
|
155 | + */ |
|
156 | + public function renderPinnedInPublishMetaBox() |
|
157 | + { |
|
158 | + if (!$this->isReviewPostType(get_post()) |
|
159 | + || !glsr()->can('edit_others_posts')) { |
|
160 | + return; |
|
161 | + } |
|
162 | + glsr(Template::class)->render('partials/editor/pinned', [ |
|
163 | + 'context' => [ |
|
164 | + 'no' => __('No', 'site-reviews'), |
|
165 | + 'yes' => __('Yes', 'site-reviews'), |
|
166 | + ], |
|
167 | + 'pinned' => wp_validate_boolean(glsr(Database::class)->get(get_the_ID(), 'pinned')), |
|
168 | + ]); |
|
169 | + } |
|
170 | 170 | |
171 | - /** |
|
172 | - * @param WP_Post $post |
|
173 | - * @return void |
|
174 | - * @callback add_meta_box |
|
175 | - */ |
|
176 | - public function renderResponseMetaBox($post) |
|
177 | - { |
|
178 | - if (!$this->isReviewPostType($post)) { |
|
179 | - return; |
|
180 | - } |
|
181 | - wp_nonce_field('response', '_nonce-response', false); |
|
182 | - glsr()->render('partials/editor/metabox-response', [ |
|
183 | - 'response' => glsr(Database::class)->get($post->ID, 'response'), |
|
184 | - ]); |
|
185 | - } |
|
171 | + /** |
|
172 | + * @param WP_Post $post |
|
173 | + * @return void |
|
174 | + * @callback add_meta_box |
|
175 | + */ |
|
176 | + public function renderResponseMetaBox($post) |
|
177 | + { |
|
178 | + if (!$this->isReviewPostType($post)) { |
|
179 | + return; |
|
180 | + } |
|
181 | + wp_nonce_field('response', '_nonce-response', false); |
|
182 | + glsr()->render('partials/editor/metabox-response', [ |
|
183 | + 'response' => glsr(Database::class)->get($post->ID, 'response'), |
|
184 | + ]); |
|
185 | + } |
|
186 | 186 | |
187 | - /** |
|
188 | - * @param WP_Post $post |
|
189 | - * @return void |
|
190 | - * @action edit_form_after_title |
|
191 | - */ |
|
192 | - public function renderReviewEditor($post) |
|
193 | - { |
|
194 | - if (!$this->isReviewPostType($post) || $this->isReviewEditable($post)) { |
|
195 | - return; |
|
196 | - } |
|
197 | - glsr()->render('partials/editor/review', [ |
|
198 | - 'post' => $post, |
|
199 | - 'response' => glsr(Database::class)->get($post->ID, 'response'), |
|
200 | - ]); |
|
201 | - } |
|
187 | + /** |
|
188 | + * @param WP_Post $post |
|
189 | + * @return void |
|
190 | + * @action edit_form_after_title |
|
191 | + */ |
|
192 | + public function renderReviewEditor($post) |
|
193 | + { |
|
194 | + if (!$this->isReviewPostType($post) || $this->isReviewEditable($post)) { |
|
195 | + return; |
|
196 | + } |
|
197 | + glsr()->render('partials/editor/review', [ |
|
198 | + 'post' => $post, |
|
199 | + 'response' => glsr(Database::class)->get($post->ID, 'response'), |
|
200 | + ]); |
|
201 | + } |
|
202 | 202 | |
203 | - /** |
|
204 | - * @return void |
|
205 | - * @action admin_head |
|
206 | - */ |
|
207 | - public function renderReviewFields() |
|
208 | - { |
|
209 | - $screen = glsr_current_screen(); |
|
210 | - if ('post' != $screen->base || Application::POST_TYPE != $screen->post_type) { |
|
211 | - return; |
|
212 | - } |
|
213 | - add_action('edit_form_after_title', [$this, 'renderReviewEditor']); |
|
214 | - add_action('edit_form_top', [$this, 'renderReviewNotice']); |
|
215 | - } |
|
203 | + /** |
|
204 | + * @return void |
|
205 | + * @action admin_head |
|
206 | + */ |
|
207 | + public function renderReviewFields() |
|
208 | + { |
|
209 | + $screen = glsr_current_screen(); |
|
210 | + if ('post' != $screen->base || Application::POST_TYPE != $screen->post_type) { |
|
211 | + return; |
|
212 | + } |
|
213 | + add_action('edit_form_after_title', [$this, 'renderReviewEditor']); |
|
214 | + add_action('edit_form_top', [$this, 'renderReviewNotice']); |
|
215 | + } |
|
216 | 216 | |
217 | - /** |
|
218 | - * @param WP_Post $post |
|
219 | - * @return void |
|
220 | - * @action edit_form_top |
|
221 | - */ |
|
222 | - public function renderReviewNotice($post) |
|
223 | - { |
|
224 | - if (!$this->isReviewPostType($post) || $this->isReviewEditable($post)) { |
|
225 | - return; |
|
226 | - } |
|
227 | - glsr(Notice::class)->addWarning(sprintf( |
|
228 | - __('%s reviews are read-only.', 'site-reviews'), |
|
229 | - glsr(Columns::class)->buildColumnReviewType($post->ID) |
|
230 | - )); |
|
231 | - glsr(Template::class)->render('partials/editor/notice', [ |
|
232 | - 'context' => [ |
|
233 | - 'notices' => glsr(Notice::class)->get(), |
|
234 | - ], |
|
235 | - ]); |
|
236 | - } |
|
217 | + /** |
|
218 | + * @param WP_Post $post |
|
219 | + * @return void |
|
220 | + * @action edit_form_top |
|
221 | + */ |
|
222 | + public function renderReviewNotice($post) |
|
223 | + { |
|
224 | + if (!$this->isReviewPostType($post) || $this->isReviewEditable($post)) { |
|
225 | + return; |
|
226 | + } |
|
227 | + glsr(Notice::class)->addWarning(sprintf( |
|
228 | + __('%s reviews are read-only.', 'site-reviews'), |
|
229 | + glsr(Columns::class)->buildColumnReviewType($post->ID) |
|
230 | + )); |
|
231 | + glsr(Template::class)->render('partials/editor/notice', [ |
|
232 | + 'context' => [ |
|
233 | + 'notices' => glsr(Notice::class)->get(), |
|
234 | + ], |
|
235 | + ]); |
|
236 | + } |
|
237 | 237 | |
238 | - /** |
|
239 | - * @param WP_Post $post |
|
240 | - * @return void |
|
241 | - * @see glsr_categories_meta_box() |
|
242 | - * @callback register_taxonomy |
|
243 | - */ |
|
244 | - public function renderTaxonomyMetabox($post) |
|
245 | - { |
|
246 | - if (!$this->isReviewPostType($post)) { |
|
247 | - return; |
|
248 | - } |
|
249 | - glsr()->render('partials/editor/metabox-categories', [ |
|
250 | - 'post' => $post, |
|
251 | - 'tax_name' => Application::TAXONOMY, |
|
252 | - 'taxonomy' => get_taxonomy(Application::TAXONOMY), |
|
253 | - ]); |
|
254 | - } |
|
238 | + /** |
|
239 | + * @param WP_Post $post |
|
240 | + * @return void |
|
241 | + * @see glsr_categories_meta_box() |
|
242 | + * @callback register_taxonomy |
|
243 | + */ |
|
244 | + public function renderTaxonomyMetabox($post) |
|
245 | + { |
|
246 | + if (!$this->isReviewPostType($post)) { |
|
247 | + return; |
|
248 | + } |
|
249 | + glsr()->render('partials/editor/metabox-categories', [ |
|
250 | + 'post' => $post, |
|
251 | + 'tax_name' => Application::TAXONOMY, |
|
252 | + 'taxonomy' => get_taxonomy(Application::TAXONOMY), |
|
253 | + ]); |
|
254 | + } |
|
255 | 255 | |
256 | - /** |
|
257 | - * @return void |
|
258 | - * @see $this->filterUpdateMessages() |
|
259 | - * @action admin_action_revert |
|
260 | - */ |
|
261 | - public function revertReview() |
|
262 | - { |
|
263 | - if (Application::ID != filter_input(INPUT_GET, 'plugin')) { |
|
264 | - return; |
|
265 | - } |
|
266 | - check_admin_referer('revert-review_'.($postId = $this->getPostId())); |
|
267 | - glsr(ReviewManager::class)->revert($postId); |
|
268 | - $this->redirect($postId, 52); |
|
269 | - } |
|
256 | + /** |
|
257 | + * @return void |
|
258 | + * @see $this->filterUpdateMessages() |
|
259 | + * @action admin_action_revert |
|
260 | + */ |
|
261 | + public function revertReview() |
|
262 | + { |
|
263 | + if (Application::ID != filter_input(INPUT_GET, 'plugin')) { |
|
264 | + return; |
|
265 | + } |
|
266 | + check_admin_referer('revert-review_'.($postId = $this->getPostId())); |
|
267 | + glsr(ReviewManager::class)->revert($postId); |
|
268 | + $this->redirect($postId, 52); |
|
269 | + } |
|
270 | 270 | |
271 | - /** |
|
272 | - * @param int $postId |
|
273 | - * @param \WP_Post $post |
|
274 | - * @param bool $isUpdate |
|
275 | - * @return void |
|
276 | - * @action save_post_.Application::POST_TYPE |
|
277 | - */ |
|
278 | - public function saveMetaboxes($postId, $post, $isUpdating) |
|
279 | - { |
|
280 | - glsr(Metaboxes::class)->saveAssignedToMetabox($postId); |
|
281 | - glsr(Metaboxes::class)->saveResponseMetabox($postId); |
|
282 | - if ($isUpdating) { |
|
283 | - do_action('site-reviews/review/saved', glsr_get_review($postId)); |
|
284 | - } |
|
285 | - } |
|
271 | + /** |
|
272 | + * @param int $postId |
|
273 | + * @param \WP_Post $post |
|
274 | + * @param bool $isUpdate |
|
275 | + * @return void |
|
276 | + * @action save_post_.Application::POST_TYPE |
|
277 | + */ |
|
278 | + public function saveMetaboxes($postId, $post, $isUpdating) |
|
279 | + { |
|
280 | + glsr(Metaboxes::class)->saveAssignedToMetabox($postId); |
|
281 | + glsr(Metaboxes::class)->saveResponseMetabox($postId); |
|
282 | + if ($isUpdating) { |
|
283 | + do_action('site-reviews/review/saved', glsr_get_review($postId)); |
|
284 | + } |
|
285 | + } |
|
286 | 286 | |
287 | - /** |
|
288 | - * @param string $assignedTo |
|
289 | - * @return string |
|
290 | - */ |
|
291 | - protected function buildAssignedToTemplate($assignedTo, WP_Post $post) |
|
292 | - { |
|
293 | - $assignedPost = glsr(Database::class)->getAssignedToPost($post->ID, $assignedTo); |
|
294 | - if (!($assignedPost instanceof WP_Post)) { |
|
295 | - return; |
|
296 | - } |
|
297 | - return glsr(Template::class)->build('partials/editor/assigned-post', [ |
|
298 | - 'context' => [ |
|
299 | - 'data.url' => (string) get_permalink($assignedPost), |
|
300 | - 'data.title' => get_the_title($assignedPost), |
|
301 | - ], |
|
302 | - ]); |
|
303 | - } |
|
287 | + /** |
|
288 | + * @param string $assignedTo |
|
289 | + * @return string |
|
290 | + */ |
|
291 | + protected function buildAssignedToTemplate($assignedTo, WP_Post $post) |
|
292 | + { |
|
293 | + $assignedPost = glsr(Database::class)->getAssignedToPost($post->ID, $assignedTo); |
|
294 | + if (!($assignedPost instanceof WP_Post)) { |
|
295 | + return; |
|
296 | + } |
|
297 | + return glsr(Template::class)->build('partials/editor/assigned-post', [ |
|
298 | + 'context' => [ |
|
299 | + 'data.url' => (string) get_permalink($assignedPost), |
|
300 | + 'data.title' => get_the_title($assignedPost), |
|
301 | + ], |
|
302 | + ]); |
|
303 | + } |
|
304 | 304 | |
305 | - /** |
|
306 | - * @return string |
|
307 | - */ |
|
308 | - protected function buildDetailsMetaBoxRevertButton(Review $review, WP_Post $post) |
|
309 | - { |
|
310 | - $isModified = !Arr::compare( |
|
311 | - [$review->title, $review->content, $review->date], |
|
312 | - [ |
|
313 | - glsr(Database::class)->get($post->ID, 'title'), |
|
314 | - glsr(Database::class)->get($post->ID, 'content'), |
|
315 | - glsr(Database::class)->get($post->ID, 'date'), |
|
316 | - ] |
|
317 | - ); |
|
318 | - if ($isModified) { |
|
319 | - $revertUrl = wp_nonce_url( |
|
320 | - admin_url('post.php?post='.$post->ID.'&action=revert&plugin='.Application::ID), |
|
321 | - 'revert-review_'.$post->ID |
|
322 | - ); |
|
323 | - return glsr(Builder::class)->a(__('Revert Changes', 'site-reviews'), [ |
|
324 | - 'class' => 'button button-large', |
|
325 | - 'href' => $revertUrl, |
|
326 | - 'id' => 'revert', |
|
327 | - ]); |
|
328 | - } |
|
329 | - return glsr(Builder::class)->button(__('Nothing to Revert', 'site-reviews'), [ |
|
330 | - 'class' => 'button-large', |
|
331 | - 'disabled' => true, |
|
332 | - 'id' => 'revert', |
|
333 | - ]); |
|
334 | - } |
|
305 | + /** |
|
306 | + * @return string |
|
307 | + */ |
|
308 | + protected function buildDetailsMetaBoxRevertButton(Review $review, WP_Post $post) |
|
309 | + { |
|
310 | + $isModified = !Arr::compare( |
|
311 | + [$review->title, $review->content, $review->date], |
|
312 | + [ |
|
313 | + glsr(Database::class)->get($post->ID, 'title'), |
|
314 | + glsr(Database::class)->get($post->ID, 'content'), |
|
315 | + glsr(Database::class)->get($post->ID, 'date'), |
|
316 | + ] |
|
317 | + ); |
|
318 | + if ($isModified) { |
|
319 | + $revertUrl = wp_nonce_url( |
|
320 | + admin_url('post.php?post='.$post->ID.'&action=revert&plugin='.Application::ID), |
|
321 | + 'revert-review_'.$post->ID |
|
322 | + ); |
|
323 | + return glsr(Builder::class)->a(__('Revert Changes', 'site-reviews'), [ |
|
324 | + 'class' => 'button button-large', |
|
325 | + 'href' => $revertUrl, |
|
326 | + 'id' => 'revert', |
|
327 | + ]); |
|
328 | + } |
|
329 | + return glsr(Builder::class)->button(__('Nothing to Revert', 'site-reviews'), [ |
|
330 | + 'class' => 'button-large', |
|
331 | + 'disabled' => true, |
|
332 | + 'id' => 'revert', |
|
333 | + ]); |
|
334 | + } |
|
335 | 335 | |
336 | - /** |
|
337 | - * @param object $review |
|
338 | - * @return string|void |
|
339 | - */ |
|
340 | - protected function getReviewType($review) |
|
341 | - { |
|
342 | - if (count(glsr()->reviewTypes) < 2) { |
|
343 | - return; |
|
344 | - } |
|
345 | - $reviewType = array_key_exists($review->review_type, glsr()->reviewTypes) |
|
346 | - ? glsr()->reviewTypes[$review->review_type] |
|
347 | - : __('Unknown', 'site-reviews'); |
|
348 | - if (!empty($review->url)) { |
|
349 | - $reviewType = glsr(Builder::class)->a($reviewType, [ |
|
350 | - 'href' => $review->url, |
|
351 | - 'target' => '_blank', |
|
352 | - ]); |
|
353 | - } |
|
354 | - return $reviewType; |
|
355 | - } |
|
336 | + /** |
|
337 | + * @param object $review |
|
338 | + * @return string|void |
|
339 | + */ |
|
340 | + protected function getReviewType($review) |
|
341 | + { |
|
342 | + if (count(glsr()->reviewTypes) < 2) { |
|
343 | + return; |
|
344 | + } |
|
345 | + $reviewType = array_key_exists($review->review_type, glsr()->reviewTypes) |
|
346 | + ? glsr()->reviewTypes[$review->review_type] |
|
347 | + : __('Unknown', 'site-reviews'); |
|
348 | + if (!empty($review->url)) { |
|
349 | + $reviewType = glsr(Builder::class)->a($reviewType, [ |
|
350 | + 'href' => $review->url, |
|
351 | + 'target' => '_blank', |
|
352 | + ]); |
|
353 | + } |
|
354 | + return $reviewType; |
|
355 | + } |
|
356 | 356 | |
357 | - /** |
|
358 | - * @return bool |
|
359 | - */ |
|
360 | - protected function isReviewEditable($post) |
|
361 | - { |
|
362 | - return $this->isReviewPostType($post) |
|
363 | - && post_type_supports(Application::POST_TYPE, 'title') |
|
364 | - && 'local' == glsr(Database::class)->get($post->ID, 'review_type'); |
|
365 | - } |
|
357 | + /** |
|
358 | + * @return bool |
|
359 | + */ |
|
360 | + protected function isReviewEditable($post) |
|
361 | + { |
|
362 | + return $this->isReviewPostType($post) |
|
363 | + && post_type_supports(Application::POST_TYPE, 'title') |
|
364 | + && 'local' == glsr(Database::class)->get($post->ID, 'review_type'); |
|
365 | + } |
|
366 | 366 | |
367 | - /** |
|
368 | - * @param mixed $post |
|
369 | - * @return bool |
|
370 | - */ |
|
371 | - protected function isReviewPostType($post) |
|
372 | - { |
|
373 | - return $post instanceof WP_Post && Application::POST_TYPE == $post->post_type; |
|
374 | - } |
|
367 | + /** |
|
368 | + * @param mixed $post |
|
369 | + * @return bool |
|
370 | + */ |
|
371 | + protected function isReviewPostType($post) |
|
372 | + { |
|
373 | + return $post instanceof WP_Post && Application::POST_TYPE == $post->post_type; |
|
374 | + } |
|
375 | 375 | |
376 | - /** |
|
377 | - * @return array |
|
378 | - */ |
|
379 | - protected function normalizeDetailsMetaBox(Review $review) |
|
380 | - { |
|
381 | - $user = empty($review->user_id) |
|
382 | - ? __('Unregistered user', 'site-reviews') |
|
383 | - : glsr(Builder::class)->a(get_the_author_meta('display_name', $review->user_id), [ |
|
384 | - 'href' => get_author_posts_url($review->user_id), |
|
385 | - ]); |
|
386 | - $email = empty($review->email) |
|
387 | - ? '—' |
|
388 | - : glsr(Builder::class)->a($review->email, [ |
|
389 | - 'href' => 'mailto:'.$review->email.'?subject='.esc_attr(__('RE:', 'site-reviews').' '.$review->title), |
|
390 | - ]); |
|
391 | - $metabox = [ |
|
392 | - __('Rating', 'site-reviews') => glsr_star_rating($review->rating), |
|
393 | - __('Type', 'site-reviews') => $this->getReviewType($review), |
|
394 | - __('Date', 'site-reviews') => get_date_from_gmt($review->date, 'F j, Y'), |
|
395 | - __('Name', 'site-reviews') => $review->author, |
|
396 | - __('Email', 'site-reviews') => $email, |
|
397 | - __('User', 'site-reviews') => $user, |
|
398 | - __('IP Address', 'site-reviews') => $review->ip_address, |
|
399 | - __('Avatar', 'site-reviews') => sprintf('<img src="%s" width="96">', $review->avatar), |
|
400 | - ]; |
|
401 | - return array_filter(apply_filters('site-reviews/metabox/details', $metabox, $review)); |
|
402 | - } |
|
376 | + /** |
|
377 | + * @return array |
|
378 | + */ |
|
379 | + protected function normalizeDetailsMetaBox(Review $review) |
|
380 | + { |
|
381 | + $user = empty($review->user_id) |
|
382 | + ? __('Unregistered user', 'site-reviews') |
|
383 | + : glsr(Builder::class)->a(get_the_author_meta('display_name', $review->user_id), [ |
|
384 | + 'href' => get_author_posts_url($review->user_id), |
|
385 | + ]); |
|
386 | + $email = empty($review->email) |
|
387 | + ? '—' |
|
388 | + : glsr(Builder::class)->a($review->email, [ |
|
389 | + 'href' => 'mailto:'.$review->email.'?subject='.esc_attr(__('RE:', 'site-reviews').' '.$review->title), |
|
390 | + ]); |
|
391 | + $metabox = [ |
|
392 | + __('Rating', 'site-reviews') => glsr_star_rating($review->rating), |
|
393 | + __('Type', 'site-reviews') => $this->getReviewType($review), |
|
394 | + __('Date', 'site-reviews') => get_date_from_gmt($review->date, 'F j, Y'), |
|
395 | + __('Name', 'site-reviews') => $review->author, |
|
396 | + __('Email', 'site-reviews') => $email, |
|
397 | + __('User', 'site-reviews') => $user, |
|
398 | + __('IP Address', 'site-reviews') => $review->ip_address, |
|
399 | + __('Avatar', 'site-reviews') => sprintf('<img src="%s" width="96">', $review->avatar), |
|
400 | + ]; |
|
401 | + return array_filter(apply_filters('site-reviews/metabox/details', $metabox, $review)); |
|
402 | + } |
|
403 | 403 | |
404 | - /** |
|
405 | - * @param int $postId |
|
406 | - * @param int $messageIndex |
|
407 | - * @return void |
|
408 | - */ |
|
409 | - protected function redirect($postId, $messageIndex) |
|
410 | - { |
|
411 | - $referer = wp_get_referer(); |
|
412 | - $hasReferer = !$referer |
|
413 | - || Str::contains($referer, 'post.php') |
|
414 | - || Str::contains($referer, 'post-new.php'); |
|
415 | - $redirectUri = $hasReferer |
|
416 | - ? remove_query_arg(['deleted', 'ids', 'trashed', 'untrashed'], $referer) |
|
417 | - : get_edit_post_link($postId); |
|
418 | - wp_safe_redirect(add_query_arg(['message' => $messageIndex], $redirectUri)); |
|
419 | - exit; |
|
420 | - } |
|
404 | + /** |
|
405 | + * @param int $postId |
|
406 | + * @param int $messageIndex |
|
407 | + * @return void |
|
408 | + */ |
|
409 | + protected function redirect($postId, $messageIndex) |
|
410 | + { |
|
411 | + $referer = wp_get_referer(); |
|
412 | + $hasReferer = !$referer |
|
413 | + || Str::contains($referer, 'post.php') |
|
414 | + || Str::contains($referer, 'post-new.php'); |
|
415 | + $redirectUri = $hasReferer |
|
416 | + ? remove_query_arg(['deleted', 'ids', 'trashed', 'untrashed'], $referer) |
|
417 | + : get_edit_post_link($postId); |
|
418 | + wp_safe_redirect(add_query_arg(['message' => $messageIndex], $redirectUri)); |
|
419 | + exit; |
|
420 | + } |
|
421 | 421 | } |
@@ -10,64 +10,64 @@ |
||
10 | 10 | |
11 | 11 | abstract class Controller |
12 | 12 | { |
13 | - /** |
|
14 | - * @return void |
|
15 | - */ |
|
16 | - public function download($filename, $content) |
|
17 | - { |
|
18 | - if (!glsr()->can('edit_others_posts')) { |
|
19 | - return; |
|
20 | - } |
|
21 | - nocache_headers(); |
|
22 | - header('Content-Type: text/plain'); |
|
23 | - header('Content-Disposition: attachment; filename="'.$filename.'"'); |
|
24 | - echo html_entity_decode($content); |
|
25 | - exit; |
|
26 | - } |
|
13 | + /** |
|
14 | + * @return void |
|
15 | + */ |
|
16 | + public function download($filename, $content) |
|
17 | + { |
|
18 | + if (!glsr()->can('edit_others_posts')) { |
|
19 | + return; |
|
20 | + } |
|
21 | + nocache_headers(); |
|
22 | + header('Content-Type: text/plain'); |
|
23 | + header('Content-Disposition: attachment; filename="'.$filename.'"'); |
|
24 | + echo html_entity_decode($content); |
|
25 | + exit; |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * @param object $command |
|
30 | - * @return mixed |
|
31 | - * @throws InvalidArgumentException |
|
32 | - */ |
|
33 | - public function execute($command) |
|
34 | - { |
|
35 | - $handlerClass = str_replace('Commands', 'Handlers', get_class($command)); |
|
36 | - if (!class_exists($handlerClass)) { |
|
37 | - throw new InvalidArgumentException('Handler '.$handlerClass.' not found.'); |
|
38 | - } |
|
39 | - try { |
|
40 | - return glsr($handlerClass)->handle($command); |
|
41 | - } catch (Exception $e) { |
|
42 | - status_header(400); |
|
43 | - glsr(Notice::class)->addError(new WP_Error('site_reviews_error', $e->getMessage())); |
|
44 | - glsr_log()->error($e->getMessage()); |
|
45 | - } |
|
46 | - } |
|
28 | + /** |
|
29 | + * @param object $command |
|
30 | + * @return mixed |
|
31 | + * @throws InvalidArgumentException |
|
32 | + */ |
|
33 | + public function execute($command) |
|
34 | + { |
|
35 | + $handlerClass = str_replace('Commands', 'Handlers', get_class($command)); |
|
36 | + if (!class_exists($handlerClass)) { |
|
37 | + throw new InvalidArgumentException('Handler '.$handlerClass.' not found.'); |
|
38 | + } |
|
39 | + try { |
|
40 | + return glsr($handlerClass)->handle($command); |
|
41 | + } catch (Exception $e) { |
|
42 | + status_header(400); |
|
43 | + glsr(Notice::class)->addError(new WP_Error('site_reviews_error', $e->getMessage())); |
|
44 | + glsr_log()->error($e->getMessage()); |
|
45 | + } |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * @return int |
|
50 | - */ |
|
51 | - protected function getPostId() |
|
52 | - { |
|
53 | - return intval(filter_input(INPUT_GET, 'post')); |
|
54 | - } |
|
48 | + /** |
|
49 | + * @return int |
|
50 | + */ |
|
51 | + protected function getPostId() |
|
52 | + { |
|
53 | + return intval(filter_input(INPUT_GET, 'post')); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * @return bool |
|
58 | - */ |
|
59 | - protected function isReviewAdminPage() |
|
60 | - { |
|
61 | - return is_admin() |
|
62 | - && in_array(glsr()->post_type, [get_post_type(), filter_input(INPUT_GET, 'post_type')]); |
|
63 | - } |
|
56 | + /** |
|
57 | + * @return bool |
|
58 | + */ |
|
59 | + protected function isReviewAdminPage() |
|
60 | + { |
|
61 | + return is_admin() |
|
62 | + && in_array(glsr()->post_type, [get_post_type(), filter_input(INPUT_GET, 'post_type')]); |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * @param int $postId |
|
67 | - * @return bool |
|
68 | - */ |
|
69 | - protected function isReviewPostId($postId) |
|
70 | - { |
|
71 | - return Application::POST_TYPE == get_post_field('post_type', $postId); |
|
72 | - } |
|
65 | + /** |
|
66 | + * @param int $postId |
|
67 | + * @return bool |
|
68 | + */ |
|
69 | + protected function isReviewPostId($postId) |
|
70 | + { |
|
71 | + return Application::POST_TYPE == get_post_field('post_type', $postId); |
|
72 | + } |
|
73 | 73 | } |
@@ -10,95 +10,95 @@ |
||
10 | 10 | |
11 | 11 | class MainController extends Controller |
12 | 12 | { |
13 | - /** |
|
14 | - * @return void |
|
15 | - * @action init |
|
16 | - */ |
|
17 | - public function registerPostType() |
|
18 | - { |
|
19 | - if (!glsr()->hasPermission()) { |
|
20 | - return; |
|
21 | - } |
|
22 | - $command = new RegisterPostType([ |
|
23 | - 'capabilities' => ['create_posts' => 'create_'.Application::POST_TYPE], |
|
24 | - 'capability_type' => Application::POST_TYPE, |
|
25 | - 'columns' => [ |
|
26 | - 'title' => '', |
|
27 | - 'category' => '', |
|
28 | - 'assigned_to' => __('Assigned To', 'site-reviews'), |
|
29 | - 'reviewer' => __('Author', 'site-reviews'), |
|
30 | - 'email' => __('Email', 'site-reviews'), |
|
31 | - 'ip_address' => __('IP Address', 'site-reviews'), |
|
32 | - 'response' => __('Response', 'site-reviews'), |
|
33 | - 'review_type' => __('Type', 'site-reviews'), |
|
34 | - 'rating' => __('Rating', 'site-reviews'), |
|
35 | - 'pinned' => __('Pinned', 'site-reviews'), |
|
36 | - 'date' => '', |
|
37 | - ], |
|
38 | - 'menu_icon' => 'dashicons-star-half', |
|
39 | - 'menu_name' => glsr()->name, |
|
40 | - 'map_meta_cap' => true, |
|
41 | - 'plural' => __('Reviews', 'site-reviews'), |
|
42 | - 'post_type' => Application::POST_TYPE, |
|
43 | - 'rest_controller_class' => RestReviewController::class, |
|
44 | - 'show_in_rest' => true, |
|
45 | - 'single' => __('Review', 'site-reviews'), |
|
46 | - ]); |
|
47 | - $this->execute($command); |
|
48 | - } |
|
13 | + /** |
|
14 | + * @return void |
|
15 | + * @action init |
|
16 | + */ |
|
17 | + public function registerPostType() |
|
18 | + { |
|
19 | + if (!glsr()->hasPermission()) { |
|
20 | + return; |
|
21 | + } |
|
22 | + $command = new RegisterPostType([ |
|
23 | + 'capabilities' => ['create_posts' => 'create_'.Application::POST_TYPE], |
|
24 | + 'capability_type' => Application::POST_TYPE, |
|
25 | + 'columns' => [ |
|
26 | + 'title' => '', |
|
27 | + 'category' => '', |
|
28 | + 'assigned_to' => __('Assigned To', 'site-reviews'), |
|
29 | + 'reviewer' => __('Author', 'site-reviews'), |
|
30 | + 'email' => __('Email', 'site-reviews'), |
|
31 | + 'ip_address' => __('IP Address', 'site-reviews'), |
|
32 | + 'response' => __('Response', 'site-reviews'), |
|
33 | + 'review_type' => __('Type', 'site-reviews'), |
|
34 | + 'rating' => __('Rating', 'site-reviews'), |
|
35 | + 'pinned' => __('Pinned', 'site-reviews'), |
|
36 | + 'date' => '', |
|
37 | + ], |
|
38 | + 'menu_icon' => 'dashicons-star-half', |
|
39 | + 'menu_name' => glsr()->name, |
|
40 | + 'map_meta_cap' => true, |
|
41 | + 'plural' => __('Reviews', 'site-reviews'), |
|
42 | + 'post_type' => Application::POST_TYPE, |
|
43 | + 'rest_controller_class' => RestReviewController::class, |
|
44 | + 'show_in_rest' => true, |
|
45 | + 'single' => __('Review', 'site-reviews'), |
|
46 | + ]); |
|
47 | + $this->execute($command); |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @return void |
|
52 | - * @action init |
|
53 | - */ |
|
54 | - public function registerShortcodes() |
|
55 | - { |
|
56 | - $command = new RegisterShortcodes([ |
|
57 | - 'site_reviews', |
|
58 | - 'site_reviews_form', |
|
59 | - 'site_reviews_summary', |
|
60 | - ]); |
|
61 | - $this->execute($command); |
|
62 | - } |
|
50 | + /** |
|
51 | + * @return void |
|
52 | + * @action init |
|
53 | + */ |
|
54 | + public function registerShortcodes() |
|
55 | + { |
|
56 | + $command = new RegisterShortcodes([ |
|
57 | + 'site_reviews', |
|
58 | + 'site_reviews_form', |
|
59 | + 'site_reviews_summary', |
|
60 | + ]); |
|
61 | + $this->execute($command); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @return void |
|
66 | - * @action init |
|
67 | - */ |
|
68 | - public function registerTaxonomy() |
|
69 | - { |
|
70 | - $command = new RegisterTaxonomy([ |
|
71 | - 'hierarchical' => true, |
|
72 | - 'meta_box_cb' => [glsr(EditorController::class), 'renderTaxonomyMetabox'], |
|
73 | - 'public' => false, |
|
74 | - 'rest_controller_class' => RestCategoryController::class, |
|
75 | - 'show_admin_column' => true, |
|
76 | - 'show_in_rest' => true, |
|
77 | - 'show_ui' => true, |
|
78 | - ]); |
|
79 | - $this->execute($command); |
|
80 | - } |
|
64 | + /** |
|
65 | + * @return void |
|
66 | + * @action init |
|
67 | + */ |
|
68 | + public function registerTaxonomy() |
|
69 | + { |
|
70 | + $command = new RegisterTaxonomy([ |
|
71 | + 'hierarchical' => true, |
|
72 | + 'meta_box_cb' => [glsr(EditorController::class), 'renderTaxonomyMetabox'], |
|
73 | + 'public' => false, |
|
74 | + 'rest_controller_class' => RestCategoryController::class, |
|
75 | + 'show_admin_column' => true, |
|
76 | + 'show_in_rest' => true, |
|
77 | + 'show_ui' => true, |
|
78 | + ]); |
|
79 | + $this->execute($command); |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * @return void |
|
84 | - * @action widgets_init |
|
85 | - */ |
|
86 | - public function registerWidgets() |
|
87 | - { |
|
88 | - $command = new RegisterWidgets([ |
|
89 | - 'site-reviews' => [ |
|
90 | - 'description' => __('Site Reviews: Display your recent reviews.', 'site-reviews'), |
|
91 | - 'name' => __('Recent Reviews', 'site-reviews'), |
|
92 | - ], |
|
93 | - 'site-reviews-form' => [ |
|
94 | - 'description' => __('Site Reviews: Display a form to submit reviews.', 'site-reviews'), |
|
95 | - 'name' => __('Submit a Review', 'site-reviews'), |
|
96 | - ], |
|
97 | - 'site-reviews-summary' => [ |
|
98 | - 'description' => __('Site Reviews: Display a summary of your reviews.', 'site-reviews'), |
|
99 | - 'name' => __('Summary of Reviews', 'site-reviews'), |
|
100 | - ], |
|
101 | - ]); |
|
102 | - $this->execute($command); |
|
103 | - } |
|
82 | + /** |
|
83 | + * @return void |
|
84 | + * @action widgets_init |
|
85 | + */ |
|
86 | + public function registerWidgets() |
|
87 | + { |
|
88 | + $command = new RegisterWidgets([ |
|
89 | + 'site-reviews' => [ |
|
90 | + 'description' => __('Site Reviews: Display your recent reviews.', 'site-reviews'), |
|
91 | + 'name' => __('Recent Reviews', 'site-reviews'), |
|
92 | + ], |
|
93 | + 'site-reviews-form' => [ |
|
94 | + 'description' => __('Site Reviews: Display a form to submit reviews.', 'site-reviews'), |
|
95 | + 'name' => __('Submit a Review', 'site-reviews'), |
|
96 | + ], |
|
97 | + 'site-reviews-summary' => [ |
|
98 | + 'description' => __('Site Reviews: Display a summary of your reviews.', 'site-reviews'), |
|
99 | + 'name' => __('Summary of Reviews', 'site-reviews'), |
|
100 | + ], |
|
101 | + ]); |
|
102 | + $this->execute($command); |
|
103 | + } |
|
104 | 104 | } |
@@ -8,86 +8,86 @@ |
||
8 | 8 | |
9 | 9 | class BlocksController extends Controller |
10 | 10 | { |
11 | - /** |
|
12 | - * @param array $categories |
|
13 | - * @return array |
|
14 | - * @filter block_categories |
|
15 | - */ |
|
16 | - public function filterBlockCategories($categories) |
|
17 | - { |
|
18 | - $categories = Arr::consolidate($categories); |
|
19 | - $categories[] = [ |
|
20 | - 'icon' => null, |
|
21 | - 'slug' => Application::ID, |
|
22 | - 'title' => glsr()->name, |
|
23 | - ]; |
|
24 | - return $categories; |
|
25 | - } |
|
11 | + /** |
|
12 | + * @param array $categories |
|
13 | + * @return array |
|
14 | + * @filter block_categories |
|
15 | + */ |
|
16 | + public function filterBlockCategories($categories) |
|
17 | + { |
|
18 | + $categories = Arr::consolidate($categories); |
|
19 | + $categories[] = [ |
|
20 | + 'icon' => null, |
|
21 | + 'slug' => Application::ID, |
|
22 | + 'title' => glsr()->name, |
|
23 | + ]; |
|
24 | + return $categories; |
|
25 | + } |
|
26 | 26 | |
27 | - /** |
|
28 | - * @param array $editors |
|
29 | - * @param string $postType |
|
30 | - * @return array |
|
31 | - * @filter classic_editor_enabled_editors_for_post_type |
|
32 | - * @plugin classic-editor/classic-editor.php |
|
33 | - */ |
|
34 | - public function filterEnabledEditors($editors, $postType) |
|
35 | - { |
|
36 | - return Application::POST_TYPE == $postType |
|
37 | - ? ['block_editor' => false, 'classic_editor' => false] |
|
38 | - : $editors; |
|
39 | - } |
|
27 | + /** |
|
28 | + * @param array $editors |
|
29 | + * @param string $postType |
|
30 | + * @return array |
|
31 | + * @filter classic_editor_enabled_editors_for_post_type |
|
32 | + * @plugin classic-editor/classic-editor.php |
|
33 | + */ |
|
34 | + public function filterEnabledEditors($editors, $postType) |
|
35 | + { |
|
36 | + return Application::POST_TYPE == $postType |
|
37 | + ? ['block_editor' => false, 'classic_editor' => false] |
|
38 | + : $editors; |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * @param bool $bool |
|
43 | - * @param string $postType |
|
44 | - * @return bool |
|
45 | - * @filter use_block_editor_for_post_type |
|
46 | - */ |
|
47 | - public function filterUseBlockEditor($bool, $postType) |
|
48 | - { |
|
49 | - return Application::POST_TYPE == $postType |
|
50 | - ? false |
|
51 | - : $bool; |
|
52 | - } |
|
41 | + /** |
|
42 | + * @param bool $bool |
|
43 | + * @param string $postType |
|
44 | + * @return bool |
|
45 | + * @filter use_block_editor_for_post_type |
|
46 | + */ |
|
47 | + public function filterUseBlockEditor($bool, $postType) |
|
48 | + { |
|
49 | + return Application::POST_TYPE == $postType |
|
50 | + ? false |
|
51 | + : $bool; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * @return void |
|
56 | - * @action init |
|
57 | - */ |
|
58 | - public function registerAssets() |
|
59 | - { |
|
60 | - wp_register_style( |
|
61 | - Application::ID.'/blocks', |
|
62 | - glsr()->url('assets/styles/'.Application::ID.'-blocks.css'), |
|
63 | - ['wp-edit-blocks'], |
|
64 | - glsr()->version |
|
65 | - ); |
|
66 | - wp_register_script( |
|
67 | - Application::ID.'/blocks', |
|
68 | - glsr()->url('assets/scripts/'.Application::ID.'-blocks.js'), |
|
69 | - ['wp-api-fetch', 'wp-blocks', 'wp-i18n', 'wp-editor', 'wp-element', Application::ID.'/admin'], |
|
70 | - glsr()->version |
|
71 | - ); |
|
72 | - } |
|
54 | + /** |
|
55 | + * @return void |
|
56 | + * @action init |
|
57 | + */ |
|
58 | + public function registerAssets() |
|
59 | + { |
|
60 | + wp_register_style( |
|
61 | + Application::ID.'/blocks', |
|
62 | + glsr()->url('assets/styles/'.Application::ID.'-blocks.css'), |
|
63 | + ['wp-edit-blocks'], |
|
64 | + glsr()->version |
|
65 | + ); |
|
66 | + wp_register_script( |
|
67 | + Application::ID.'/blocks', |
|
68 | + glsr()->url('assets/scripts/'.Application::ID.'-blocks.js'), |
|
69 | + ['wp-api-fetch', 'wp-blocks', 'wp-i18n', 'wp-editor', 'wp-element', Application::ID.'/admin'], |
|
70 | + glsr()->version |
|
71 | + ); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @return void |
|
76 | - * @action init |
|
77 | - */ |
|
78 | - public function registerBlocks() |
|
79 | - { |
|
80 | - $blocks = [ |
|
81 | - 'form', 'reviews', 'summary', |
|
82 | - ]; |
|
83 | - foreach ($blocks as $block) { |
|
84 | - $id = str_replace('_reviews', '', Application::ID.'_'.$block); |
|
85 | - $blockClass = Helper::buildClassName($id.'-block', 'Blocks'); |
|
86 | - if (!class_exists($blockClass)) { |
|
87 | - glsr_log()->error(sprintf('Block class missing (%s)', $blockClass)); |
|
88 | - continue; |
|
89 | - } |
|
90 | - glsr($blockClass)->register($block); |
|
91 | - } |
|
92 | - } |
|
74 | + /** |
|
75 | + * @return void |
|
76 | + * @action init |
|
77 | + */ |
|
78 | + public function registerBlocks() |
|
79 | + { |
|
80 | + $blocks = [ |
|
81 | + 'form', 'reviews', 'summary', |
|
82 | + ]; |
|
83 | + foreach ($blocks as $block) { |
|
84 | + $id = str_replace('_reviews', '', Application::ID.'_'.$block); |
|
85 | + $blockClass = Helper::buildClassName($id.'-block', 'Blocks'); |
|
86 | + if (!class_exists($blockClass)) { |
|
87 | + glsr_log()->error(sprintf('Block class missing (%s)', $blockClass)); |
|
88 | + continue; |
|
89 | + } |
|
90 | + glsr($blockClass)->register($block); |
|
91 | + } |
|
92 | + } |
|
93 | 93 | } |