@@ -1,4 +1,4 @@ |
||
1 | -<?php defined('WPINC') || die; ?> |
|
1 | +<?php defined( 'WPINC' ) || die; ?> |
|
2 | 2 | |
3 | 3 | <div class="glsr-login-register"> |
4 | 4 | <p>{{ text }}</p> |
@@ -1,4 +1,4 @@ |
||
1 | -<?php defined('WPINC') || die; ?> |
|
1 | +<?php defined( 'WPINC' ) || die; ?> |
|
2 | 2 | |
3 | 3 | <div class="glsr-reviews-wrap"> |
4 | 4 | <div class="{{ class }}" id="{{ id }}"> |
@@ -9,201 +9,201 @@ |
||
9 | 9 | |
10 | 10 | class Email |
11 | 11 | { |
12 | - /** |
|
13 | - * @var array |
|
14 | - */ |
|
15 | - public $attachments; |
|
16 | - |
|
17 | - /** |
|
18 | - * @var array |
|
19 | - */ |
|
20 | - public $email; |
|
21 | - |
|
22 | - /** |
|
23 | - * @var array |
|
24 | - */ |
|
25 | - public $headers; |
|
26 | - |
|
27 | - /** |
|
28 | - * @var string |
|
29 | - */ |
|
30 | - public $message; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var string |
|
34 | - */ |
|
35 | - public $subject; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var string|array |
|
39 | - */ |
|
40 | - public $to; |
|
41 | - |
|
42 | - /** |
|
43 | - * @return Email |
|
44 | - */ |
|
45 | - public function compose(array $email) |
|
46 | - { |
|
47 | - $this->normalize($email); |
|
48 | - $this->attachments = $this->email['attachments']; |
|
49 | - $this->headers = $this->buildHeaders(); |
|
50 | - $this->message = $this->buildHtmlMessage(); |
|
51 | - $this->subject = $this->email['subject']; |
|
52 | - $this->to = $this->email['to']; |
|
53 | - add_action('phpmailer_init', [$this, 'buildPlainTextMessage']); |
|
54 | - return $this; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * @param string $format |
|
59 | - * @return string|null |
|
60 | - */ |
|
61 | - public function read($format = '') |
|
62 | - { |
|
63 | - if ('plaintext' == $format) { |
|
64 | - $message = $this->stripHtmlTags($this->message); |
|
65 | - return apply_filters('site-reviews/email/message', $message, 'text', $this); |
|
66 | - } |
|
67 | - return $this->message; |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * @return void|bool |
|
72 | - */ |
|
73 | - public function send() |
|
74 | - { |
|
75 | - if (!$this->message || !$this->subject || !$this->to) { |
|
76 | - return; |
|
77 | - } |
|
78 | - add_action('wp_mail_failed', [$this, 'logMailError']); |
|
79 | - $sent = wp_mail( |
|
80 | - $this->to, |
|
81 | - $this->subject, |
|
82 | - $this->message, |
|
83 | - $this->headers, |
|
84 | - $this->attachments |
|
85 | - ); |
|
86 | - remove_action('wp_mail_failed', [$this, 'logMailError']); |
|
87 | - $this->reset(); |
|
88 | - return $sent; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * @return void |
|
93 | - * @action phpmailer_init |
|
94 | - */ |
|
95 | - public function buildPlainTextMessage(PHPMailer $phpmailer) |
|
96 | - { |
|
97 | - if (empty($this->email)) { |
|
98 | - return; |
|
99 | - } |
|
100 | - if ('text/plain' === $phpmailer->ContentType || !empty($phpmailer->AltBody)) { |
|
101 | - return; |
|
102 | - } |
|
103 | - $message = $this->stripHtmlTags($phpmailer->Body); |
|
104 | - $phpmailer->AltBody = apply_filters('site-reviews/email/message', $message, 'text', $this); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * @return array |
|
109 | - */ |
|
110 | - protected function buildHeaders() |
|
111 | - { |
|
112 | - $allowed = [ |
|
113 | - 'bcc', 'cc', 'from', 'reply-to', |
|
114 | - ]; |
|
115 | - $headers = array_intersect_key($this->email, array_flip($allowed)); |
|
116 | - $headers = array_filter($headers); |
|
117 | - foreach ($headers as $key => $value) { |
|
118 | - unset($headers[$key]); |
|
119 | - $headers[] = $key.': '.$value; |
|
120 | - } |
|
121 | - $headers[] = 'Content-Type: text/html'; |
|
122 | - return apply_filters('site-reviews/email/headers', $headers, $this); |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * @return string |
|
127 | - */ |
|
128 | - protected function buildHtmlMessage() |
|
129 | - { |
|
130 | - $template = trim(glsr(OptionManager::class)->get('settings.general.notification_message')); |
|
131 | - if (!empty($template)) { |
|
132 | - $message = glsr(Template::class)->interpolate($template, $this->email['template-tags'], $this->email['template']); |
|
133 | - } elseif ($this->email['template']) { |
|
134 | - $message = glsr(Template::class)->build('templates/'.$this->email['template'], [ |
|
135 | - 'context' => $this->email['template-tags'], |
|
136 | - ]); |
|
137 | - } |
|
138 | - if (!isset($message)) { |
|
139 | - $message = $this->email['message']; |
|
140 | - } |
|
141 | - $message = $this->email['before'].$message.$this->email['after']; |
|
142 | - $message = strip_shortcodes($message); |
|
143 | - $message = wptexturize($message); |
|
144 | - $message = wpautop($message); |
|
145 | - $message = str_replace('<> ', '', $message); |
|
146 | - $message = str_replace(']]>', ']]>', $message); |
|
147 | - $message = glsr(Template::class)->build('partials/email/index', [ |
|
148 | - 'context' => ['message' => $message], |
|
149 | - ]); |
|
150 | - return apply_filters('site-reviews/email/message', stripslashes($message), 'html', $this); |
|
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * @param \WP_Error $error |
|
155 | - * @return void |
|
156 | - */ |
|
157 | - protected function logMailError($error) |
|
158 | - { |
|
159 | - glsr_log()->error('Email was not sent (wp_mail failed)') |
|
160 | - ->debug($this) |
|
161 | - ->debug($error); |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * @return void |
|
166 | - */ |
|
167 | - protected function normalize(array $email = []) |
|
168 | - { |
|
169 | - $email = shortcode_atts(glsr(EmailDefaults::class)->defaults(), $email); |
|
170 | - if (empty($email['reply-to'])) { |
|
171 | - $email['reply-to'] = $email['from']; |
|
172 | - } |
|
173 | - $this->email = apply_filters('site-reviews/email/compose', $email, $this); |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * @return void |
|
178 | - */ |
|
179 | - protected function reset() |
|
180 | - { |
|
181 | - $this->attachments = []; |
|
182 | - $this->email = []; |
|
183 | - $this->headers = []; |
|
184 | - $this->message = null; |
|
185 | - $this->subject = null; |
|
186 | - $this->to = null; |
|
187 | - } |
|
188 | - |
|
189 | - /** |
|
190 | - * @return string |
|
191 | - */ |
|
192 | - protected function stripHtmlTags($string) |
|
193 | - { |
|
194 | - // remove invisible elements |
|
195 | - $string = preg_replace('@<(embed|head|noembed|noscript|object|script|style)[^>]*?>.*?</\\1>@siu', '', $string); |
|
196 | - // replace certain elements with a line-break |
|
197 | - $string = preg_replace('@</(div|h[1-9]|p|pre|tr)@iu', "\r\n\$0", $string); |
|
198 | - // replace other elements with a space |
|
199 | - $string = preg_replace('@</(td|th)@iu', ' $0', $string); |
|
200 | - // add a placeholder for plain-text bullets to list elements |
|
201 | - $string = preg_replace('@<(li)[^>]*?>@siu', '$0-o-^-o-', $string); |
|
202 | - // strip all remaining HTML tags |
|
203 | - $string = wp_strip_all_tags($string); |
|
204 | - $string = wp_specialchars_decode($string, ENT_QUOTES); |
|
205 | - $string = preg_replace('/\v(?:[\v\h]+){2,}/', "\r\n\r\n", $string); |
|
206 | - $string = str_replace('-o-^-o-', ' - ', $string); |
|
207 | - return html_entity_decode($string, ENT_QUOTES, 'UTF-8'); |
|
208 | - } |
|
12 | + /** |
|
13 | + * @var array |
|
14 | + */ |
|
15 | + public $attachments; |
|
16 | + |
|
17 | + /** |
|
18 | + * @var array |
|
19 | + */ |
|
20 | + public $email; |
|
21 | + |
|
22 | + /** |
|
23 | + * @var array |
|
24 | + */ |
|
25 | + public $headers; |
|
26 | + |
|
27 | + /** |
|
28 | + * @var string |
|
29 | + */ |
|
30 | + public $message; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var string |
|
34 | + */ |
|
35 | + public $subject; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var string|array |
|
39 | + */ |
|
40 | + public $to; |
|
41 | + |
|
42 | + /** |
|
43 | + * @return Email |
|
44 | + */ |
|
45 | + public function compose(array $email) |
|
46 | + { |
|
47 | + $this->normalize($email); |
|
48 | + $this->attachments = $this->email['attachments']; |
|
49 | + $this->headers = $this->buildHeaders(); |
|
50 | + $this->message = $this->buildHtmlMessage(); |
|
51 | + $this->subject = $this->email['subject']; |
|
52 | + $this->to = $this->email['to']; |
|
53 | + add_action('phpmailer_init', [$this, 'buildPlainTextMessage']); |
|
54 | + return $this; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * @param string $format |
|
59 | + * @return string|null |
|
60 | + */ |
|
61 | + public function read($format = '') |
|
62 | + { |
|
63 | + if ('plaintext' == $format) { |
|
64 | + $message = $this->stripHtmlTags($this->message); |
|
65 | + return apply_filters('site-reviews/email/message', $message, 'text', $this); |
|
66 | + } |
|
67 | + return $this->message; |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * @return void|bool |
|
72 | + */ |
|
73 | + public function send() |
|
74 | + { |
|
75 | + if (!$this->message || !$this->subject || !$this->to) { |
|
76 | + return; |
|
77 | + } |
|
78 | + add_action('wp_mail_failed', [$this, 'logMailError']); |
|
79 | + $sent = wp_mail( |
|
80 | + $this->to, |
|
81 | + $this->subject, |
|
82 | + $this->message, |
|
83 | + $this->headers, |
|
84 | + $this->attachments |
|
85 | + ); |
|
86 | + remove_action('wp_mail_failed', [$this, 'logMailError']); |
|
87 | + $this->reset(); |
|
88 | + return $sent; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * @return void |
|
93 | + * @action phpmailer_init |
|
94 | + */ |
|
95 | + public function buildPlainTextMessage(PHPMailer $phpmailer) |
|
96 | + { |
|
97 | + if (empty($this->email)) { |
|
98 | + return; |
|
99 | + } |
|
100 | + if ('text/plain' === $phpmailer->ContentType || !empty($phpmailer->AltBody)) { |
|
101 | + return; |
|
102 | + } |
|
103 | + $message = $this->stripHtmlTags($phpmailer->Body); |
|
104 | + $phpmailer->AltBody = apply_filters('site-reviews/email/message', $message, 'text', $this); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * @return array |
|
109 | + */ |
|
110 | + protected function buildHeaders() |
|
111 | + { |
|
112 | + $allowed = [ |
|
113 | + 'bcc', 'cc', 'from', 'reply-to', |
|
114 | + ]; |
|
115 | + $headers = array_intersect_key($this->email, array_flip($allowed)); |
|
116 | + $headers = array_filter($headers); |
|
117 | + foreach ($headers as $key => $value) { |
|
118 | + unset($headers[$key]); |
|
119 | + $headers[] = $key.': '.$value; |
|
120 | + } |
|
121 | + $headers[] = 'Content-Type: text/html'; |
|
122 | + return apply_filters('site-reviews/email/headers', $headers, $this); |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * @return string |
|
127 | + */ |
|
128 | + protected function buildHtmlMessage() |
|
129 | + { |
|
130 | + $template = trim(glsr(OptionManager::class)->get('settings.general.notification_message')); |
|
131 | + if (!empty($template)) { |
|
132 | + $message = glsr(Template::class)->interpolate($template, $this->email['template-tags'], $this->email['template']); |
|
133 | + } elseif ($this->email['template']) { |
|
134 | + $message = glsr(Template::class)->build('templates/'.$this->email['template'], [ |
|
135 | + 'context' => $this->email['template-tags'], |
|
136 | + ]); |
|
137 | + } |
|
138 | + if (!isset($message)) { |
|
139 | + $message = $this->email['message']; |
|
140 | + } |
|
141 | + $message = $this->email['before'].$message.$this->email['after']; |
|
142 | + $message = strip_shortcodes($message); |
|
143 | + $message = wptexturize($message); |
|
144 | + $message = wpautop($message); |
|
145 | + $message = str_replace('<> ', '', $message); |
|
146 | + $message = str_replace(']]>', ']]>', $message); |
|
147 | + $message = glsr(Template::class)->build('partials/email/index', [ |
|
148 | + 'context' => ['message' => $message], |
|
149 | + ]); |
|
150 | + return apply_filters('site-reviews/email/message', stripslashes($message), 'html', $this); |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * @param \WP_Error $error |
|
155 | + * @return void |
|
156 | + */ |
|
157 | + protected function logMailError($error) |
|
158 | + { |
|
159 | + glsr_log()->error('Email was not sent (wp_mail failed)') |
|
160 | + ->debug($this) |
|
161 | + ->debug($error); |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * @return void |
|
166 | + */ |
|
167 | + protected function normalize(array $email = []) |
|
168 | + { |
|
169 | + $email = shortcode_atts(glsr(EmailDefaults::class)->defaults(), $email); |
|
170 | + if (empty($email['reply-to'])) { |
|
171 | + $email['reply-to'] = $email['from']; |
|
172 | + } |
|
173 | + $this->email = apply_filters('site-reviews/email/compose', $email, $this); |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * @return void |
|
178 | + */ |
|
179 | + protected function reset() |
|
180 | + { |
|
181 | + $this->attachments = []; |
|
182 | + $this->email = []; |
|
183 | + $this->headers = []; |
|
184 | + $this->message = null; |
|
185 | + $this->subject = null; |
|
186 | + $this->to = null; |
|
187 | + } |
|
188 | + |
|
189 | + /** |
|
190 | + * @return string |
|
191 | + */ |
|
192 | + protected function stripHtmlTags($string) |
|
193 | + { |
|
194 | + // remove invisible elements |
|
195 | + $string = preg_replace('@<(embed|head|noembed|noscript|object|script|style)[^>]*?>.*?</\\1>@siu', '', $string); |
|
196 | + // replace certain elements with a line-break |
|
197 | + $string = preg_replace('@</(div|h[1-9]|p|pre|tr)@iu', "\r\n\$0", $string); |
|
198 | + // replace other elements with a space |
|
199 | + $string = preg_replace('@</(td|th)@iu', ' $0', $string); |
|
200 | + // add a placeholder for plain-text bullets to list elements |
|
201 | + $string = preg_replace('@<(li)[^>]*?>@siu', '$0-o-^-o-', $string); |
|
202 | + // strip all remaining HTML tags |
|
203 | + $string = wp_strip_all_tags($string); |
|
204 | + $string = wp_specialchars_decode($string, ENT_QUOTES); |
|
205 | + $string = preg_replace('/\v(?:[\v\h]+){2,}/', "\r\n\r\n", $string); |
|
206 | + $string = str_replace('-o-^-o-', ' - ', $string); |
|
207 | + return html_entity_decode($string, ENT_QUOTES, 'UTF-8'); |
|
208 | + } |
|
209 | 209 | } |
@@ -42,15 +42,15 @@ discard block |
||
42 | 42 | /** |
43 | 43 | * @return Email |
44 | 44 | */ |
45 | - public function compose(array $email) |
|
45 | + public function compose( array $email ) |
|
46 | 46 | { |
47 | - $this->normalize($email); |
|
47 | + $this->normalize( $email ); |
|
48 | 48 | $this->attachments = $this->email['attachments']; |
49 | 49 | $this->headers = $this->buildHeaders(); |
50 | 50 | $this->message = $this->buildHtmlMessage(); |
51 | 51 | $this->subject = $this->email['subject']; |
52 | 52 | $this->to = $this->email['to']; |
53 | - add_action('phpmailer_init', [$this, 'buildPlainTextMessage']); |
|
53 | + add_action( 'phpmailer_init', [$this, 'buildPlainTextMessage'] ); |
|
54 | 54 | return $this; |
55 | 55 | } |
56 | 56 | |
@@ -58,11 +58,11 @@ discard block |
||
58 | 58 | * @param string $format |
59 | 59 | * @return string|null |
60 | 60 | */ |
61 | - public function read($format = '') |
|
61 | + public function read( $format = '' ) |
|
62 | 62 | { |
63 | - if ('plaintext' == $format) { |
|
64 | - $message = $this->stripHtmlTags($this->message); |
|
65 | - return apply_filters('site-reviews/email/message', $message, 'text', $this); |
|
63 | + if( 'plaintext' == $format ) { |
|
64 | + $message = $this->stripHtmlTags( $this->message ); |
|
65 | + return apply_filters( 'site-reviews/email/message', $message, 'text', $this ); |
|
66 | 66 | } |
67 | 67 | return $this->message; |
68 | 68 | } |
@@ -72,10 +72,10 @@ discard block |
||
72 | 72 | */ |
73 | 73 | public function send() |
74 | 74 | { |
75 | - if (!$this->message || !$this->subject || !$this->to) { |
|
75 | + if( !$this->message || !$this->subject || !$this->to ) { |
|
76 | 76 | return; |
77 | 77 | } |
78 | - add_action('wp_mail_failed', [$this, 'logMailError']); |
|
78 | + add_action( 'wp_mail_failed', [$this, 'logMailError'] ); |
|
79 | 79 | $sent = wp_mail( |
80 | 80 | $this->to, |
81 | 81 | $this->subject, |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | $this->headers, |
84 | 84 | $this->attachments |
85 | 85 | ); |
86 | - remove_action('wp_mail_failed', [$this, 'logMailError']); |
|
86 | + remove_action( 'wp_mail_failed', [$this, 'logMailError'] ); |
|
87 | 87 | $this->reset(); |
88 | 88 | return $sent; |
89 | 89 | } |
@@ -92,16 +92,16 @@ discard block |
||
92 | 92 | * @return void |
93 | 93 | * @action phpmailer_init |
94 | 94 | */ |
95 | - public function buildPlainTextMessage(PHPMailer $phpmailer) |
|
95 | + public function buildPlainTextMessage( PHPMailer $phpmailer ) |
|
96 | 96 | { |
97 | - if (empty($this->email)) { |
|
97 | + if( empty($this->email) ) { |
|
98 | 98 | return; |
99 | 99 | } |
100 | - if ('text/plain' === $phpmailer->ContentType || !empty($phpmailer->AltBody)) { |
|
100 | + if( 'text/plain' === $phpmailer->ContentType || !empty($phpmailer->AltBody) ) { |
|
101 | 101 | return; |
102 | 102 | } |
103 | - $message = $this->stripHtmlTags($phpmailer->Body); |
|
104 | - $phpmailer->AltBody = apply_filters('site-reviews/email/message', $message, 'text', $this); |
|
103 | + $message = $this->stripHtmlTags( $phpmailer->Body ); |
|
104 | + $phpmailer->AltBody = apply_filters( 'site-reviews/email/message', $message, 'text', $this ); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
@@ -112,14 +112,14 @@ discard block |
||
112 | 112 | $allowed = [ |
113 | 113 | 'bcc', 'cc', 'from', 'reply-to', |
114 | 114 | ]; |
115 | - $headers = array_intersect_key($this->email, array_flip($allowed)); |
|
116 | - $headers = array_filter($headers); |
|
117 | - foreach ($headers as $key => $value) { |
|
115 | + $headers = array_intersect_key( $this->email, array_flip( $allowed ) ); |
|
116 | + $headers = array_filter( $headers ); |
|
117 | + foreach( $headers as $key => $value ) { |
|
118 | 118 | unset($headers[$key]); |
119 | 119 | $headers[] = $key.': '.$value; |
120 | 120 | } |
121 | 121 | $headers[] = 'Content-Type: text/html'; |
122 | - return apply_filters('site-reviews/email/headers', $headers, $this); |
|
122 | + return apply_filters( 'site-reviews/email/headers', $headers, $this ); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
@@ -127,50 +127,50 @@ discard block |
||
127 | 127 | */ |
128 | 128 | protected function buildHtmlMessage() |
129 | 129 | { |
130 | - $template = trim(glsr(OptionManager::class)->get('settings.general.notification_message')); |
|
131 | - if (!empty($template)) { |
|
132 | - $message = glsr(Template::class)->interpolate($template, $this->email['template-tags'], $this->email['template']); |
|
133 | - } elseif ($this->email['template']) { |
|
134 | - $message = glsr(Template::class)->build('templates/'.$this->email['template'], [ |
|
130 | + $template = trim( glsr( OptionManager::class )->get( 'settings.general.notification_message' ) ); |
|
131 | + if( !empty($template) ) { |
|
132 | + $message = glsr( Template::class )->interpolate( $template, $this->email['template-tags'], $this->email['template'] ); |
|
133 | + } elseif( $this->email['template'] ) { |
|
134 | + $message = glsr( Template::class )->build( 'templates/'.$this->email['template'], [ |
|
135 | 135 | 'context' => $this->email['template-tags'], |
136 | - ]); |
|
136 | + ] ); |
|
137 | 137 | } |
138 | - if (!isset($message)) { |
|
138 | + if( !isset($message) ) { |
|
139 | 139 | $message = $this->email['message']; |
140 | 140 | } |
141 | 141 | $message = $this->email['before'].$message.$this->email['after']; |
142 | - $message = strip_shortcodes($message); |
|
143 | - $message = wptexturize($message); |
|
144 | - $message = wpautop($message); |
|
145 | - $message = str_replace('<> ', '', $message); |
|
146 | - $message = str_replace(']]>', ']]>', $message); |
|
147 | - $message = glsr(Template::class)->build('partials/email/index', [ |
|
142 | + $message = strip_shortcodes( $message ); |
|
143 | + $message = wptexturize( $message ); |
|
144 | + $message = wpautop( $message ); |
|
145 | + $message = str_replace( '<> ', '', $message ); |
|
146 | + $message = str_replace( ']]>', ']]>', $message ); |
|
147 | + $message = glsr( Template::class )->build( 'partials/email/index', [ |
|
148 | 148 | 'context' => ['message' => $message], |
149 | - ]); |
|
150 | - return apply_filters('site-reviews/email/message', stripslashes($message), 'html', $this); |
|
149 | + ] ); |
|
150 | + return apply_filters( 'site-reviews/email/message', stripslashes( $message ), 'html', $this ); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | /** |
154 | 154 | * @param \WP_Error $error |
155 | 155 | * @return void |
156 | 156 | */ |
157 | - protected function logMailError($error) |
|
157 | + protected function logMailError( $error ) |
|
158 | 158 | { |
159 | - glsr_log()->error('Email was not sent (wp_mail failed)') |
|
160 | - ->debug($this) |
|
161 | - ->debug($error); |
|
159 | + glsr_log()->error( 'Email was not sent (wp_mail failed)' ) |
|
160 | + ->debug( $this ) |
|
161 | + ->debug( $error ); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
165 | 165 | * @return void |
166 | 166 | */ |
167 | - protected function normalize(array $email = []) |
|
167 | + protected function normalize( array $email = [] ) |
|
168 | 168 | { |
169 | - $email = shortcode_atts(glsr(EmailDefaults::class)->defaults(), $email); |
|
170 | - if (empty($email['reply-to'])) { |
|
169 | + $email = shortcode_atts( glsr( EmailDefaults::class )->defaults(), $email ); |
|
170 | + if( empty($email['reply-to']) ) { |
|
171 | 171 | $email['reply-to'] = $email['from']; |
172 | 172 | } |
173 | - $this->email = apply_filters('site-reviews/email/compose', $email, $this); |
|
173 | + $this->email = apply_filters( 'site-reviews/email/compose', $email, $this ); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | /** |
@@ -189,21 +189,21 @@ discard block |
||
189 | 189 | /** |
190 | 190 | * @return string |
191 | 191 | */ |
192 | - protected function stripHtmlTags($string) |
|
192 | + protected function stripHtmlTags( $string ) |
|
193 | 193 | { |
194 | 194 | // remove invisible elements |
195 | - $string = preg_replace('@<(embed|head|noembed|noscript|object|script|style)[^>]*?>.*?</\\1>@siu', '', $string); |
|
195 | + $string = preg_replace( '@<(embed|head|noembed|noscript|object|script|style)[^>]*?>.*?</\\1>@siu', '', $string ); |
|
196 | 196 | // replace certain elements with a line-break |
197 | - $string = preg_replace('@</(div|h[1-9]|p|pre|tr)@iu', "\r\n\$0", $string); |
|
197 | + $string = preg_replace( '@</(div|h[1-9]|p|pre|tr)@iu', "\r\n\$0", $string ); |
|
198 | 198 | // replace other elements with a space |
199 | - $string = preg_replace('@</(td|th)@iu', ' $0', $string); |
|
199 | + $string = preg_replace( '@</(td|th)@iu', ' $0', $string ); |
|
200 | 200 | // add a placeholder for plain-text bullets to list elements |
201 | - $string = preg_replace('@<(li)[^>]*?>@siu', '$0-o-^-o-', $string); |
|
201 | + $string = preg_replace( '@<(li)[^>]*?>@siu', '$0-o-^-o-', $string ); |
|
202 | 202 | // strip all remaining HTML tags |
203 | - $string = wp_strip_all_tags($string); |
|
204 | - $string = wp_specialchars_decode($string, ENT_QUOTES); |
|
205 | - $string = preg_replace('/\v(?:[\v\h]+){2,}/', "\r\n\r\n", $string); |
|
206 | - $string = str_replace('-o-^-o-', ' - ', $string); |
|
207 | - return html_entity_decode($string, ENT_QUOTES, 'UTF-8'); |
|
203 | + $string = wp_strip_all_tags( $string ); |
|
204 | + $string = wp_specialchars_decode( $string, ENT_QUOTES ); |
|
205 | + $string = preg_replace( '/\v(?:[\v\h]+){2,}/', "\r\n\r\n", $string ); |
|
206 | + $string = str_replace( '-o-^-o-', ' - ', $string ); |
|
207 | + return html_entity_decode( $string, ENT_QUOTES, 'UTF-8' ); |
|
208 | 208 | } |
209 | 209 | } |
@@ -130,7 +130,8 @@ |
||
130 | 130 | $template = trim(glsr(OptionManager::class)->get('settings.general.notification_message')); |
131 | 131 | if (!empty($template)) { |
132 | 132 | $message = glsr(Template::class)->interpolate($template, $this->email['template-tags'], $this->email['template']); |
133 | - } elseif ($this->email['template']) { |
|
133 | + } |
|
134 | + elseif ($this->email['template']) { |
|
134 | 135 | $message = glsr(Template::class)->build('templates/'.$this->email['template'], [ |
135 | 136 | 'context' => $this->email['template-tags'], |
136 | 137 | ]); |
@@ -9,138 +9,138 @@ |
||
9 | 9 | |
10 | 10 | class Slack |
11 | 11 | { |
12 | - /** |
|
13 | - * @var string |
|
14 | - */ |
|
15 | - public $endpoint; |
|
12 | + /** |
|
13 | + * @var string |
|
14 | + */ |
|
15 | + public $endpoint; |
|
16 | 16 | |
17 | - /** |
|
18 | - * @var array |
|
19 | - */ |
|
20 | - public $notification; |
|
17 | + /** |
|
18 | + * @var array |
|
19 | + */ |
|
20 | + public $notification; |
|
21 | 21 | |
22 | - /** |
|
23 | - * @var Review |
|
24 | - */ |
|
25 | - public $review; |
|
22 | + /** |
|
23 | + * @var Review |
|
24 | + */ |
|
25 | + public $review; |
|
26 | 26 | |
27 | - public function __construct() |
|
28 | - { |
|
29 | - $this->endpoint = glsr(OptionManager::class)->get('settings.general.notification_slack'); |
|
30 | - } |
|
27 | + public function __construct() |
|
28 | + { |
|
29 | + $this->endpoint = glsr(OptionManager::class)->get('settings.general.notification_slack'); |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * @return Slack |
|
34 | - */ |
|
35 | - public function compose(Review $review, array $notification) |
|
36 | - { |
|
37 | - if (empty($this->endpoint)) { |
|
38 | - return $this; |
|
39 | - } |
|
40 | - $args = shortcode_atts(glsr(SlackDefaults::class)->defaults(), $notification); |
|
41 | - $this->review = $review; |
|
42 | - $notification = [ |
|
43 | - 'icon_url' => $args['icon_url'], |
|
44 | - 'username' => $args['username'], |
|
45 | - 'attachments' => [[ |
|
46 | - 'actions' => $this->buildAction($args), |
|
47 | - 'pretext' => $args['pretext'], |
|
48 | - 'color' => $args['color'], |
|
49 | - 'fallback' => $args['fallback'], |
|
50 | - 'fields' => $this->buildFields(), |
|
51 | - ]], |
|
52 | - ]; |
|
53 | - $this->notification = apply_filters('site-reviews/slack/compose', $notification, $this); |
|
54 | - return $this; |
|
55 | - } |
|
32 | + /** |
|
33 | + * @return Slack |
|
34 | + */ |
|
35 | + public function compose(Review $review, array $notification) |
|
36 | + { |
|
37 | + if (empty($this->endpoint)) { |
|
38 | + return $this; |
|
39 | + } |
|
40 | + $args = shortcode_atts(glsr(SlackDefaults::class)->defaults(), $notification); |
|
41 | + $this->review = $review; |
|
42 | + $notification = [ |
|
43 | + 'icon_url' => $args['icon_url'], |
|
44 | + 'username' => $args['username'], |
|
45 | + 'attachments' => [[ |
|
46 | + 'actions' => $this->buildAction($args), |
|
47 | + 'pretext' => $args['pretext'], |
|
48 | + 'color' => $args['color'], |
|
49 | + 'fallback' => $args['fallback'], |
|
50 | + 'fields' => $this->buildFields(), |
|
51 | + ]], |
|
52 | + ]; |
|
53 | + $this->notification = apply_filters('site-reviews/slack/compose', $notification, $this); |
|
54 | + return $this; |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * @return WP_Error|array |
|
59 | - */ |
|
60 | - public function send() |
|
61 | - { |
|
62 | - if (empty($this->endpoint)) { |
|
63 | - return new WP_Error('slack', 'Slack notification was not sent: missing endpoint'); |
|
64 | - } |
|
65 | - return wp_remote_post($this->endpoint, [ |
|
66 | - 'blocking' => false, |
|
67 | - 'body' => json_encode($this->notification), |
|
68 | - 'headers' => ['Content-Type' => 'application/json'], |
|
69 | - 'httpversion' => '1.0', |
|
70 | - 'method' => 'POST', |
|
71 | - 'redirection' => 5, |
|
72 | - 'sslverify' => false, |
|
73 | - 'timeout' => 45, |
|
74 | - ]); |
|
75 | - } |
|
57 | + /** |
|
58 | + * @return WP_Error|array |
|
59 | + */ |
|
60 | + public function send() |
|
61 | + { |
|
62 | + if (empty($this->endpoint)) { |
|
63 | + return new WP_Error('slack', 'Slack notification was not sent: missing endpoint'); |
|
64 | + } |
|
65 | + return wp_remote_post($this->endpoint, [ |
|
66 | + 'blocking' => false, |
|
67 | + 'body' => json_encode($this->notification), |
|
68 | + 'headers' => ['Content-Type' => 'application/json'], |
|
69 | + 'httpversion' => '1.0', |
|
70 | + 'method' => 'POST', |
|
71 | + 'redirection' => 5, |
|
72 | + 'sslverify' => false, |
|
73 | + 'timeout' => 45, |
|
74 | + ]); |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * @return array |
|
79 | - */ |
|
80 | - protected function buildAction(array $args) |
|
81 | - { |
|
82 | - return [[ |
|
83 | - 'text' => $args['button_text'], |
|
84 | - 'type' => 'button', |
|
85 | - 'url' => $args['button_url'], |
|
86 | - ]]; |
|
87 | - } |
|
77 | + /** |
|
78 | + * @return array |
|
79 | + */ |
|
80 | + protected function buildAction(array $args) |
|
81 | + { |
|
82 | + return [[ |
|
83 | + 'text' => $args['button_text'], |
|
84 | + 'type' => 'button', |
|
85 | + 'url' => $args['button_url'], |
|
86 | + ]]; |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * @return array |
|
91 | - */ |
|
92 | - protected function buildAuthorField() |
|
93 | - { |
|
94 | - $email = !empty($this->review->email) |
|
95 | - ? '<'.$this->review->email.'>' |
|
96 | - : ''; |
|
97 | - $author = trim(rtrim($this->review->author).' '.$email); |
|
98 | - return ['value' => implode(' - ', array_filter([$author, $this->review->ip_address]))]; |
|
99 | - } |
|
89 | + /** |
|
90 | + * @return array |
|
91 | + */ |
|
92 | + protected function buildAuthorField() |
|
93 | + { |
|
94 | + $email = !empty($this->review->email) |
|
95 | + ? '<'.$this->review->email.'>' |
|
96 | + : ''; |
|
97 | + $author = trim(rtrim($this->review->author).' '.$email); |
|
98 | + return ['value' => implode(' - ', array_filter([$author, $this->review->ip_address]))]; |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * @return array |
|
103 | - */ |
|
104 | - protected function buildContentField() |
|
105 | - { |
|
106 | - return !empty($this->review->content) |
|
107 | - ? ['value' => $this->review->content] |
|
108 | - : []; |
|
109 | - } |
|
101 | + /** |
|
102 | + * @return array |
|
103 | + */ |
|
104 | + protected function buildContentField() |
|
105 | + { |
|
106 | + return !empty($this->review->content) |
|
107 | + ? ['value' => $this->review->content] |
|
108 | + : []; |
|
109 | + } |
|
110 | 110 | |
111 | - /** |
|
112 | - * @return array |
|
113 | - */ |
|
114 | - protected function buildFields() |
|
115 | - { |
|
116 | - $fields = [ |
|
117 | - $this->buildStarsField(), |
|
118 | - $this->buildTitleField(), |
|
119 | - $this->buildContentField(), |
|
120 | - $this->buildAuthorField(), |
|
121 | - ]; |
|
122 | - return array_filter($fields); |
|
123 | - } |
|
111 | + /** |
|
112 | + * @return array |
|
113 | + */ |
|
114 | + protected function buildFields() |
|
115 | + { |
|
116 | + $fields = [ |
|
117 | + $this->buildStarsField(), |
|
118 | + $this->buildTitleField(), |
|
119 | + $this->buildContentField(), |
|
120 | + $this->buildAuthorField(), |
|
121 | + ]; |
|
122 | + return array_filter($fields); |
|
123 | + } |
|
124 | 124 | |
125 | - /** |
|
126 | - * @return array |
|
127 | - */ |
|
128 | - protected function buildStarsField() |
|
129 | - { |
|
130 | - $solidStars = str_repeat('★', $this->review->rating); |
|
131 | - $emptyStars = str_repeat('☆', max(0, glsr()->constant('MAX_RATING', Rating::class) - $this->review->rating)); |
|
132 | - $stars = $solidStars.$emptyStars; |
|
133 | - $stars = apply_filters('site-reviews/slack/stars', $stars, $this->review->rating, glsr()->constant('MAX_RATING', Rating::class)); |
|
134 | - return ['title' => $stars]; |
|
135 | - } |
|
125 | + /** |
|
126 | + * @return array |
|
127 | + */ |
|
128 | + protected function buildStarsField() |
|
129 | + { |
|
130 | + $solidStars = str_repeat('★', $this->review->rating); |
|
131 | + $emptyStars = str_repeat('☆', max(0, glsr()->constant('MAX_RATING', Rating::class) - $this->review->rating)); |
|
132 | + $stars = $solidStars.$emptyStars; |
|
133 | + $stars = apply_filters('site-reviews/slack/stars', $stars, $this->review->rating, glsr()->constant('MAX_RATING', Rating::class)); |
|
134 | + return ['title' => $stars]; |
|
135 | + } |
|
136 | 136 | |
137 | - /** |
|
138 | - * @return array |
|
139 | - */ |
|
140 | - protected function buildTitleField() |
|
141 | - { |
|
142 | - return !empty($this->review->title) |
|
143 | - ? ['title' => $this->review->title] |
|
144 | - : []; |
|
145 | - } |
|
137 | + /** |
|
138 | + * @return array |
|
139 | + */ |
|
140 | + protected function buildTitleField() |
|
141 | + { |
|
142 | + return !empty($this->review->title) |
|
143 | + ? ['title' => $this->review->title] |
|
144 | + : []; |
|
145 | + } |
|
146 | 146 | } |
@@ -26,31 +26,31 @@ discard block |
||
26 | 26 | |
27 | 27 | public function __construct() |
28 | 28 | { |
29 | - $this->endpoint = glsr(OptionManager::class)->get('settings.general.notification_slack'); |
|
29 | + $this->endpoint = glsr( OptionManager::class )->get( 'settings.general.notification_slack' ); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
33 | 33 | * @return Slack |
34 | 34 | */ |
35 | - public function compose(Review $review, array $notification) |
|
35 | + public function compose( Review $review, array $notification ) |
|
36 | 36 | { |
37 | - if (empty($this->endpoint)) { |
|
37 | + if( empty($this->endpoint) ) { |
|
38 | 38 | return $this; |
39 | 39 | } |
40 | - $args = shortcode_atts(glsr(SlackDefaults::class)->defaults(), $notification); |
|
40 | + $args = shortcode_atts( glsr( SlackDefaults::class )->defaults(), $notification ); |
|
41 | 41 | $this->review = $review; |
42 | 42 | $notification = [ |
43 | 43 | 'icon_url' => $args['icon_url'], |
44 | 44 | 'username' => $args['username'], |
45 | 45 | 'attachments' => [[ |
46 | - 'actions' => $this->buildAction($args), |
|
46 | + 'actions' => $this->buildAction( $args ), |
|
47 | 47 | 'pretext' => $args['pretext'], |
48 | 48 | 'color' => $args['color'], |
49 | 49 | 'fallback' => $args['fallback'], |
50 | 50 | 'fields' => $this->buildFields(), |
51 | 51 | ]], |
52 | 52 | ]; |
53 | - $this->notification = apply_filters('site-reviews/slack/compose', $notification, $this); |
|
53 | + $this->notification = apply_filters( 'site-reviews/slack/compose', $notification, $this ); |
|
54 | 54 | return $this; |
55 | 55 | } |
56 | 56 | |
@@ -59,25 +59,25 @@ discard block |
||
59 | 59 | */ |
60 | 60 | public function send() |
61 | 61 | { |
62 | - if (empty($this->endpoint)) { |
|
63 | - return new WP_Error('slack', 'Slack notification was not sent: missing endpoint'); |
|
62 | + if( empty($this->endpoint) ) { |
|
63 | + return new WP_Error( 'slack', 'Slack notification was not sent: missing endpoint' ); |
|
64 | 64 | } |
65 | - return wp_remote_post($this->endpoint, [ |
|
65 | + return wp_remote_post( $this->endpoint, [ |
|
66 | 66 | 'blocking' => false, |
67 | - 'body' => json_encode($this->notification), |
|
67 | + 'body' => json_encode( $this->notification ), |
|
68 | 68 | 'headers' => ['Content-Type' => 'application/json'], |
69 | 69 | 'httpversion' => '1.0', |
70 | 70 | 'method' => 'POST', |
71 | 71 | 'redirection' => 5, |
72 | 72 | 'sslverify' => false, |
73 | 73 | 'timeout' => 45, |
74 | - ]); |
|
74 | + ] ); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | /** |
78 | 78 | * @return array |
79 | 79 | */ |
80 | - protected function buildAction(array $args) |
|
80 | + protected function buildAction( array $args ) |
|
81 | 81 | { |
82 | 82 | return [[ |
83 | 83 | 'text' => $args['button_text'], |
@@ -94,8 +94,8 @@ discard block |
||
94 | 94 | $email = !empty($this->review->email) |
95 | 95 | ? '<'.$this->review->email.'>' |
96 | 96 | : ''; |
97 | - $author = trim(rtrim($this->review->author).' '.$email); |
|
98 | - return ['value' => implode(' - ', array_filter([$author, $this->review->ip_address]))]; |
|
97 | + $author = trim( rtrim( $this->review->author ).' '.$email ); |
|
98 | + return ['value' => implode( ' - ', array_filter( [$author, $this->review->ip_address] ) )]; |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | $this->buildContentField(), |
120 | 120 | $this->buildAuthorField(), |
121 | 121 | ]; |
122 | - return array_filter($fields); |
|
122 | + return array_filter( $fields ); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
@@ -127,10 +127,10 @@ discard block |
||
127 | 127 | */ |
128 | 128 | protected function buildStarsField() |
129 | 129 | { |
130 | - $solidStars = str_repeat('★', $this->review->rating); |
|
131 | - $emptyStars = str_repeat('☆', max(0, glsr()->constant('MAX_RATING', Rating::class) - $this->review->rating)); |
|
130 | + $solidStars = str_repeat( '★', $this->review->rating ); |
|
131 | + $emptyStars = str_repeat( '☆', max( 0, glsr()->constant( 'MAX_RATING', Rating::class ) - $this->review->rating ) ); |
|
132 | 132 | $stars = $solidStars.$emptyStars; |
133 | - $stars = apply_filters('site-reviews/slack/stars', $stars, $this->review->rating, glsr()->constant('MAX_RATING', Rating::class)); |
|
133 | + $stars = apply_filters( 'site-reviews/slack/stars', $stars, $this->review->rating, glsr()->constant( 'MAX_RATING', Rating::class ) ); |
|
134 | 134 | return ['title' => $stars]; |
135 | 135 | } |
136 | 136 |
@@ -4,49 +4,49 @@ |
||
4 | 4 | |
5 | 5 | class Date |
6 | 6 | { |
7 | - /** |
|
8 | - * [60, 1], |
|
9 | - * [60 * 100, 60], |
|
10 | - * [3600 * 70, 3600], |
|
11 | - * [3600 * 24 * 10, 3600 * 24], |
|
12 | - * [3600 * 24 * 30, 3600 * 24 * 7], |
|
13 | - * [3600 * 24 * 30 * 30, 3600 * 24 * 30], |
|
14 | - * [INF, 3600 * 24 * 265],. |
|
15 | - */ |
|
16 | - protected static $TIME_PERIODS = [ |
|
17 | - [60, 1], |
|
18 | - [6000, 60], |
|
19 | - [252000, 3600], |
|
20 | - [864000, 86400], |
|
21 | - [2592000, 604800], |
|
22 | - [77760000, 2592000], |
|
23 | - [INF, 22896000], |
|
24 | - ]; |
|
7 | + /** |
|
8 | + * [60, 1], |
|
9 | + * [60 * 100, 60], |
|
10 | + * [3600 * 70, 3600], |
|
11 | + * [3600 * 24 * 10, 3600 * 24], |
|
12 | + * [3600 * 24 * 30, 3600 * 24 * 7], |
|
13 | + * [3600 * 24 * 30 * 30, 3600 * 24 * 30], |
|
14 | + * [INF, 3600 * 24 * 265],. |
|
15 | + */ |
|
16 | + protected static $TIME_PERIODS = [ |
|
17 | + [60, 1], |
|
18 | + [6000, 60], |
|
19 | + [252000, 3600], |
|
20 | + [864000, 86400], |
|
21 | + [2592000, 604800], |
|
22 | + [77760000, 2592000], |
|
23 | + [INF, 22896000], |
|
24 | + ]; |
|
25 | 25 | |
26 | - /** |
|
27 | - * @return string |
|
28 | - */ |
|
29 | - public function relative($date) |
|
30 | - { |
|
31 | - $diff = time() - strtotime($date); |
|
32 | - foreach (static::$TIME_PERIODS as $i => $timePeriod) { |
|
33 | - if ($diff > $timePeriod[0]) { |
|
34 | - continue; |
|
35 | - } |
|
36 | - $unit = intval(floor($diff / $timePeriod[1])); |
|
37 | - $relativeDates = [ |
|
38 | - _n('%s second ago', '%s seconds ago', $unit, 'site-reviews'), |
|
39 | - _n('%s minute ago', '%s minutes ago', $unit, 'site-reviews'), |
|
40 | - _n('an hour ago', '%s hours ago', $unit, 'site-reviews'), |
|
41 | - _n('yesterday', '%s days ago', $unit, 'site-reviews'), |
|
42 | - _n('a week ago', '%s weeks ago', $unit, 'site-reviews'), |
|
43 | - _n('%s month ago', '%s months ago', $unit, 'site-reviews'), |
|
44 | - _n('%s year ago', '%s years ago', $unit, 'site-reviews'), |
|
45 | - ]; |
|
46 | - $relativeDate = $relativeDates[$i]; |
|
47 | - return false !== strpos($relativeDate, '%s') |
|
48 | - ? sprintf($relativeDate, $unit) |
|
49 | - : $relativeDate; |
|
50 | - } |
|
51 | - } |
|
26 | + /** |
|
27 | + * @return string |
|
28 | + */ |
|
29 | + public function relative($date) |
|
30 | + { |
|
31 | + $diff = time() - strtotime($date); |
|
32 | + foreach (static::$TIME_PERIODS as $i => $timePeriod) { |
|
33 | + if ($diff > $timePeriod[0]) { |
|
34 | + continue; |
|
35 | + } |
|
36 | + $unit = intval(floor($diff / $timePeriod[1])); |
|
37 | + $relativeDates = [ |
|
38 | + _n('%s second ago', '%s seconds ago', $unit, 'site-reviews'), |
|
39 | + _n('%s minute ago', '%s minutes ago', $unit, 'site-reviews'), |
|
40 | + _n('an hour ago', '%s hours ago', $unit, 'site-reviews'), |
|
41 | + _n('yesterday', '%s days ago', $unit, 'site-reviews'), |
|
42 | + _n('a week ago', '%s weeks ago', $unit, 'site-reviews'), |
|
43 | + _n('%s month ago', '%s months ago', $unit, 'site-reviews'), |
|
44 | + _n('%s year ago', '%s years ago', $unit, 'site-reviews'), |
|
45 | + ]; |
|
46 | + $relativeDate = $relativeDates[$i]; |
|
47 | + return false !== strpos($relativeDate, '%s') |
|
48 | + ? sprintf($relativeDate, $unit) |
|
49 | + : $relativeDate; |
|
50 | + } |
|
51 | + } |
|
52 | 52 | } |
@@ -26,26 +26,26 @@ |
||
26 | 26 | /** |
27 | 27 | * @return string |
28 | 28 | */ |
29 | - public function relative($date) |
|
29 | + public function relative( $date ) |
|
30 | 30 | { |
31 | - $diff = time() - strtotime($date); |
|
32 | - foreach (static::$TIME_PERIODS as $i => $timePeriod) { |
|
33 | - if ($diff > $timePeriod[0]) { |
|
31 | + $diff = time() - strtotime( $date ); |
|
32 | + foreach( static::$TIME_PERIODS as $i => $timePeriod ) { |
|
33 | + if( $diff > $timePeriod[0] ) { |
|
34 | 34 | continue; |
35 | 35 | } |
36 | - $unit = intval(floor($diff / $timePeriod[1])); |
|
36 | + $unit = intval( floor( $diff / $timePeriod[1] ) ); |
|
37 | 37 | $relativeDates = [ |
38 | - _n('%s second ago', '%s seconds ago', $unit, 'site-reviews'), |
|
39 | - _n('%s minute ago', '%s minutes ago', $unit, 'site-reviews'), |
|
40 | - _n('an hour ago', '%s hours ago', $unit, 'site-reviews'), |
|
41 | - _n('yesterday', '%s days ago', $unit, 'site-reviews'), |
|
42 | - _n('a week ago', '%s weeks ago', $unit, 'site-reviews'), |
|
43 | - _n('%s month ago', '%s months ago', $unit, 'site-reviews'), |
|
44 | - _n('%s year ago', '%s years ago', $unit, 'site-reviews'), |
|
38 | + _n( '%s second ago', '%s seconds ago', $unit, 'site-reviews' ), |
|
39 | + _n( '%s minute ago', '%s minutes ago', $unit, 'site-reviews' ), |
|
40 | + _n( 'an hour ago', '%s hours ago', $unit, 'site-reviews' ), |
|
41 | + _n( 'yesterday', '%s days ago', $unit, 'site-reviews' ), |
|
42 | + _n( 'a week ago', '%s weeks ago', $unit, 'site-reviews' ), |
|
43 | + _n( '%s month ago', '%s months ago', $unit, 'site-reviews' ), |
|
44 | + _n( '%s year ago', '%s years ago', $unit, 'site-reviews' ), |
|
45 | 45 | ]; |
46 | 46 | $relativeDate = $relativeDates[$i]; |
47 | - return false !== strpos($relativeDate, '%s') |
|
48 | - ? sprintf($relativeDate, $unit) |
|
47 | + return false !== strpos( $relativeDate, '%s' ) |
|
48 | + ? sprintf( $relativeDate, $unit ) |
|
49 | 49 | : $relativeDate; |
50 | 50 | } |
51 | 51 | } |
@@ -6,151 +6,151 @@ |
||
6 | 6 | |
7 | 7 | class Translator |
8 | 8 | { |
9 | - /** |
|
10 | - * @param string $translation |
|
11 | - * @param string $text |
|
12 | - * @param string $domain |
|
13 | - * @return string |
|
14 | - */ |
|
15 | - public function filterGettext($translation, $text, $domain) |
|
16 | - { |
|
17 | - return $this->translate($translation, $domain, [ |
|
18 | - 'single' => $text, |
|
19 | - ]); |
|
20 | - } |
|
9 | + /** |
|
10 | + * @param string $translation |
|
11 | + * @param string $text |
|
12 | + * @param string $domain |
|
13 | + * @return string |
|
14 | + */ |
|
15 | + public function filterGettext($translation, $text, $domain) |
|
16 | + { |
|
17 | + return $this->translate($translation, $domain, [ |
|
18 | + 'single' => $text, |
|
19 | + ]); |
|
20 | + } |
|
21 | 21 | |
22 | - /** |
|
23 | - * @param string $translation |
|
24 | - * @param string $text |
|
25 | - * @param string $context |
|
26 | - * @param string $domain |
|
27 | - * @return string |
|
28 | - */ |
|
29 | - public function filterGettextWithContext($translation, $text, $context, $domain) |
|
30 | - { |
|
31 | - return $this->translate($translation, $domain, [ |
|
32 | - 'context' => $context, |
|
33 | - 'single' => $text, |
|
34 | - ]); |
|
35 | - } |
|
22 | + /** |
|
23 | + * @param string $translation |
|
24 | + * @param string $text |
|
25 | + * @param string $context |
|
26 | + * @param string $domain |
|
27 | + * @return string |
|
28 | + */ |
|
29 | + public function filterGettextWithContext($translation, $text, $context, $domain) |
|
30 | + { |
|
31 | + return $this->translate($translation, $domain, [ |
|
32 | + 'context' => $context, |
|
33 | + 'single' => $text, |
|
34 | + ]); |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * @param string $translation |
|
39 | - * @param string $single |
|
40 | - * @param string $plural |
|
41 | - * @param int $number |
|
42 | - * @param string $domain |
|
43 | - * @return string |
|
44 | - */ |
|
45 | - public function filterNgettext($translation, $single, $plural, $number, $domain) |
|
46 | - { |
|
47 | - return $this->translate($translation, $domain, [ |
|
48 | - 'number' => $number, |
|
49 | - 'plural' => $plural, |
|
50 | - 'single' => $single, |
|
51 | - ]); |
|
52 | - } |
|
37 | + /** |
|
38 | + * @param string $translation |
|
39 | + * @param string $single |
|
40 | + * @param string $plural |
|
41 | + * @param int $number |
|
42 | + * @param string $domain |
|
43 | + * @return string |
|
44 | + */ |
|
45 | + public function filterNgettext($translation, $single, $plural, $number, $domain) |
|
46 | + { |
|
47 | + return $this->translate($translation, $domain, [ |
|
48 | + 'number' => $number, |
|
49 | + 'plural' => $plural, |
|
50 | + 'single' => $single, |
|
51 | + ]); |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * @param string $translation |
|
56 | - * @param string $single |
|
57 | - * @param string $plural |
|
58 | - * @param int $number |
|
59 | - * @param string $context |
|
60 | - * @param string $domain |
|
61 | - * @return string |
|
62 | - */ |
|
63 | - public function filterNgettextWithContext($translation, $single, $plural, $number, $context, $domain) |
|
64 | - { |
|
65 | - return $this->translate($translation, $domain, [ |
|
66 | - 'context' => $context, |
|
67 | - 'number' => $number, |
|
68 | - 'plural' => $plural, |
|
69 | - 'single' => $single, |
|
70 | - ]); |
|
71 | - } |
|
54 | + /** |
|
55 | + * @param string $translation |
|
56 | + * @param string $single |
|
57 | + * @param string $plural |
|
58 | + * @param int $number |
|
59 | + * @param string $context |
|
60 | + * @param string $domain |
|
61 | + * @return string |
|
62 | + */ |
|
63 | + public function filterNgettextWithContext($translation, $single, $plural, $number, $context, $domain) |
|
64 | + { |
|
65 | + return $this->translate($translation, $domain, [ |
|
66 | + 'context' => $context, |
|
67 | + 'number' => $number, |
|
68 | + 'plural' => $plural, |
|
69 | + 'single' => $single, |
|
70 | + ]); |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * @param string $original |
|
75 | - * @param string $domain |
|
76 | - * @return string |
|
77 | - */ |
|
78 | - public function translate($original, $domain, array $args) |
|
79 | - { |
|
80 | - $domains = apply_filters('site-reviews/translator/domains', [Application::ID]); |
|
81 | - if (!in_array($domain, $domains)) { |
|
82 | - return $original; |
|
83 | - } |
|
84 | - $args = $this->normalizeTranslationArgs($args); |
|
85 | - $strings = $this->getTranslationStrings($args['single'], $args['plural']); |
|
86 | - if (empty($strings)) { |
|
87 | - return $original; |
|
88 | - } |
|
89 | - $string = current($strings); |
|
90 | - return 'plural' == $string['type'] |
|
91 | - ? $this->translatePlural($domain, $string, $args) |
|
92 | - : $this->translateSingle($domain, $string, $args); |
|
93 | - } |
|
73 | + /** |
|
74 | + * @param string $original |
|
75 | + * @param string $domain |
|
76 | + * @return string |
|
77 | + */ |
|
78 | + public function translate($original, $domain, array $args) |
|
79 | + { |
|
80 | + $domains = apply_filters('site-reviews/translator/domains', [Application::ID]); |
|
81 | + if (!in_array($domain, $domains)) { |
|
82 | + return $original; |
|
83 | + } |
|
84 | + $args = $this->normalizeTranslationArgs($args); |
|
85 | + $strings = $this->getTranslationStrings($args['single'], $args['plural']); |
|
86 | + if (empty($strings)) { |
|
87 | + return $original; |
|
88 | + } |
|
89 | + $string = current($strings); |
|
90 | + return 'plural' == $string['type'] |
|
91 | + ? $this->translatePlural($domain, $string, $args) |
|
92 | + : $this->translateSingle($domain, $string, $args); |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * @param string $single |
|
97 | - * @param string $plural |
|
98 | - * @return array |
|
99 | - */ |
|
100 | - protected function getTranslationStrings($single, $plural) |
|
101 | - { |
|
102 | - return array_filter(glsr(Translation::class)->translations(), function ($string) use ($single, $plural) { |
|
103 | - return $string['s1'] == html_entity_decode($single, ENT_COMPAT, 'UTF-8') |
|
104 | - && $string['p1'] == html_entity_decode($plural, ENT_COMPAT, 'UTF-8'); |
|
105 | - }); |
|
106 | - } |
|
95 | + /** |
|
96 | + * @param string $single |
|
97 | + * @param string $plural |
|
98 | + * @return array |
|
99 | + */ |
|
100 | + protected function getTranslationStrings($single, $plural) |
|
101 | + { |
|
102 | + return array_filter(glsr(Translation::class)->translations(), function ($string) use ($single, $plural) { |
|
103 | + return $string['s1'] == html_entity_decode($single, ENT_COMPAT, 'UTF-8') |
|
104 | + && $string['p1'] == html_entity_decode($plural, ENT_COMPAT, 'UTF-8'); |
|
105 | + }); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * @return array |
|
110 | - */ |
|
111 | - protected function normalizeTranslationArgs(array $args) |
|
112 | - { |
|
113 | - $defaults = [ |
|
114 | - 'context' => '', |
|
115 | - 'number' => 1, |
|
116 | - 'plural' => '', |
|
117 | - 'single' => '', |
|
118 | - ]; |
|
119 | - return shortcode_atts($defaults, $args); |
|
120 | - } |
|
108 | + /** |
|
109 | + * @return array |
|
110 | + */ |
|
111 | + protected function normalizeTranslationArgs(array $args) |
|
112 | + { |
|
113 | + $defaults = [ |
|
114 | + 'context' => '', |
|
115 | + 'number' => 1, |
|
116 | + 'plural' => '', |
|
117 | + 'single' => '', |
|
118 | + ]; |
|
119 | + return shortcode_atts($defaults, $args); |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * @param string $domain |
|
124 | - * @return string |
|
125 | - */ |
|
126 | - protected function translatePlural($domain, array $string, array $args) |
|
127 | - { |
|
128 | - if (!empty($string['s2'])) { |
|
129 | - $args['single'] = $string['s2']; |
|
130 | - } |
|
131 | - if (!empty($string['p2'])) { |
|
132 | - $args['plural'] = $string['p2']; |
|
133 | - } |
|
134 | - return get_translations_for_domain($domain)->translate_plural( |
|
135 | - $args['single'], |
|
136 | - $args['plural'], |
|
137 | - $args['number'], |
|
138 | - $args['context'] |
|
139 | - ); |
|
140 | - } |
|
122 | + /** |
|
123 | + * @param string $domain |
|
124 | + * @return string |
|
125 | + */ |
|
126 | + protected function translatePlural($domain, array $string, array $args) |
|
127 | + { |
|
128 | + if (!empty($string['s2'])) { |
|
129 | + $args['single'] = $string['s2']; |
|
130 | + } |
|
131 | + if (!empty($string['p2'])) { |
|
132 | + $args['plural'] = $string['p2']; |
|
133 | + } |
|
134 | + return get_translations_for_domain($domain)->translate_plural( |
|
135 | + $args['single'], |
|
136 | + $args['plural'], |
|
137 | + $args['number'], |
|
138 | + $args['context'] |
|
139 | + ); |
|
140 | + } |
|
141 | 141 | |
142 | - /** |
|
143 | - * @param string $domain |
|
144 | - * @return string |
|
145 | - */ |
|
146 | - protected function translateSingle($domain, array $string, array $args) |
|
147 | - { |
|
148 | - if (!empty($string['s2'])) { |
|
149 | - $args['single'] = $string['s2']; |
|
150 | - } |
|
151 | - return get_translations_for_domain($domain)->translate( |
|
152 | - $args['single'], |
|
153 | - $args['context'] |
|
154 | - ); |
|
155 | - } |
|
142 | + /** |
|
143 | + * @param string $domain |
|
144 | + * @return string |
|
145 | + */ |
|
146 | + protected function translateSingle($domain, array $string, array $args) |
|
147 | + { |
|
148 | + if (!empty($string['s2'])) { |
|
149 | + $args['single'] = $string['s2']; |
|
150 | + } |
|
151 | + return get_translations_for_domain($domain)->translate( |
|
152 | + $args['single'], |
|
153 | + $args['context'] |
|
154 | + ); |
|
155 | + } |
|
156 | 156 | } |
@@ -12,11 +12,11 @@ discard block |
||
12 | 12 | * @param string $domain |
13 | 13 | * @return string |
14 | 14 | */ |
15 | - public function filterGettext($translation, $text, $domain) |
|
15 | + public function filterGettext( $translation, $text, $domain ) |
|
16 | 16 | { |
17 | - return $this->translate($translation, $domain, [ |
|
17 | + return $this->translate( $translation, $domain, [ |
|
18 | 18 | 'single' => $text, |
19 | - ]); |
|
19 | + ] ); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
@@ -26,12 +26,12 @@ discard block |
||
26 | 26 | * @param string $domain |
27 | 27 | * @return string |
28 | 28 | */ |
29 | - public function filterGettextWithContext($translation, $text, $context, $domain) |
|
29 | + public function filterGettextWithContext( $translation, $text, $context, $domain ) |
|
30 | 30 | { |
31 | - return $this->translate($translation, $domain, [ |
|
31 | + return $this->translate( $translation, $domain, [ |
|
32 | 32 | 'context' => $context, |
33 | 33 | 'single' => $text, |
34 | - ]); |
|
34 | + ] ); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | /** |
@@ -42,13 +42,13 @@ discard block |
||
42 | 42 | * @param string $domain |
43 | 43 | * @return string |
44 | 44 | */ |
45 | - public function filterNgettext($translation, $single, $plural, $number, $domain) |
|
45 | + public function filterNgettext( $translation, $single, $plural, $number, $domain ) |
|
46 | 46 | { |
47 | - return $this->translate($translation, $domain, [ |
|
47 | + return $this->translate( $translation, $domain, [ |
|
48 | 48 | 'number' => $number, |
49 | 49 | 'plural' => $plural, |
50 | 50 | 'single' => $single, |
51 | - ]); |
|
51 | + ] ); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
@@ -60,14 +60,14 @@ discard block |
||
60 | 60 | * @param string $domain |
61 | 61 | * @return string |
62 | 62 | */ |
63 | - public function filterNgettextWithContext($translation, $single, $plural, $number, $context, $domain) |
|
63 | + public function filterNgettextWithContext( $translation, $single, $plural, $number, $context, $domain ) |
|
64 | 64 | { |
65 | - return $this->translate($translation, $domain, [ |
|
65 | + return $this->translate( $translation, $domain, [ |
|
66 | 66 | 'context' => $context, |
67 | 67 | 'number' => $number, |
68 | 68 | 'plural' => $plural, |
69 | 69 | 'single' => $single, |
70 | - ]); |
|
70 | + ] ); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
@@ -75,21 +75,21 @@ discard block |
||
75 | 75 | * @param string $domain |
76 | 76 | * @return string |
77 | 77 | */ |
78 | - public function translate($original, $domain, array $args) |
|
78 | + public function translate( $original, $domain, array $args ) |
|
79 | 79 | { |
80 | - $domains = apply_filters('site-reviews/translator/domains', [Application::ID]); |
|
81 | - if (!in_array($domain, $domains)) { |
|
80 | + $domains = apply_filters( 'site-reviews/translator/domains', [Application::ID] ); |
|
81 | + if( !in_array( $domain, $domains ) ) { |
|
82 | 82 | return $original; |
83 | 83 | } |
84 | - $args = $this->normalizeTranslationArgs($args); |
|
85 | - $strings = $this->getTranslationStrings($args['single'], $args['plural']); |
|
86 | - if (empty($strings)) { |
|
84 | + $args = $this->normalizeTranslationArgs( $args ); |
|
85 | + $strings = $this->getTranslationStrings( $args['single'], $args['plural'] ); |
|
86 | + if( empty($strings) ) { |
|
87 | 87 | return $original; |
88 | 88 | } |
89 | - $string = current($strings); |
|
89 | + $string = current( $strings ); |
|
90 | 90 | return 'plural' == $string['type'] |
91 | - ? $this->translatePlural($domain, $string, $args) |
|
92 | - : $this->translateSingle($domain, $string, $args); |
|
91 | + ? $this->translatePlural( $domain, $string, $args ) |
|
92 | + : $this->translateSingle( $domain, $string, $args ); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -97,18 +97,18 @@ discard block |
||
97 | 97 | * @param string $plural |
98 | 98 | * @return array |
99 | 99 | */ |
100 | - protected function getTranslationStrings($single, $plural) |
|
100 | + protected function getTranslationStrings( $single, $plural ) |
|
101 | 101 | { |
102 | - return array_filter(glsr(Translation::class)->translations(), function ($string) use ($single, $plural) { |
|
103 | - return $string['s1'] == html_entity_decode($single, ENT_COMPAT, 'UTF-8') |
|
104 | - && $string['p1'] == html_entity_decode($plural, ENT_COMPAT, 'UTF-8'); |
|
102 | + return array_filter( glsr( Translation::class )->translations(), function( $string ) use ($single, $plural) { |
|
103 | + return $string['s1'] == html_entity_decode( $single, ENT_COMPAT, 'UTF-8' ) |
|
104 | + && $string['p1'] == html_entity_decode( $plural, ENT_COMPAT, 'UTF-8' ); |
|
105 | 105 | }); |
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
109 | 109 | * @return array |
110 | 110 | */ |
111 | - protected function normalizeTranslationArgs(array $args) |
|
111 | + protected function normalizeTranslationArgs( array $args ) |
|
112 | 112 | { |
113 | 113 | $defaults = [ |
114 | 114 | 'context' => '', |
@@ -116,22 +116,22 @@ discard block |
||
116 | 116 | 'plural' => '', |
117 | 117 | 'single' => '', |
118 | 118 | ]; |
119 | - return shortcode_atts($defaults, $args); |
|
119 | + return shortcode_atts( $defaults, $args ); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
123 | 123 | * @param string $domain |
124 | 124 | * @return string |
125 | 125 | */ |
126 | - protected function translatePlural($domain, array $string, array $args) |
|
126 | + protected function translatePlural( $domain, array $string, array $args ) |
|
127 | 127 | { |
128 | - if (!empty($string['s2'])) { |
|
128 | + if( !empty($string['s2']) ) { |
|
129 | 129 | $args['single'] = $string['s2']; |
130 | 130 | } |
131 | - if (!empty($string['p2'])) { |
|
131 | + if( !empty($string['p2']) ) { |
|
132 | 132 | $args['plural'] = $string['p2']; |
133 | 133 | } |
134 | - return get_translations_for_domain($domain)->translate_plural( |
|
134 | + return get_translations_for_domain( $domain )->translate_plural( |
|
135 | 135 | $args['single'], |
136 | 136 | $args['plural'], |
137 | 137 | $args['number'], |
@@ -143,12 +143,12 @@ discard block |
||
143 | 143 | * @param string $domain |
144 | 144 | * @return string |
145 | 145 | */ |
146 | - protected function translateSingle($domain, array $string, array $args) |
|
146 | + protected function translateSingle( $domain, array $string, array $args ) |
|
147 | 147 | { |
148 | - if (!empty($string['s2'])) { |
|
148 | + if( !empty($string['s2']) ) { |
|
149 | 149 | $args['single'] = $string['s2']; |
150 | 150 | } |
151 | - return get_translations_for_domain($domain)->translate( |
|
151 | + return get_translations_for_domain( $domain )->translate( |
|
152 | 152 | $args['single'], |
153 | 153 | $args['context'] |
154 | 154 | ); |
@@ -216,7 +216,8 @@ |
||
216 | 216 | if (!empty($field['label'])) { |
217 | 217 | $field['legend'] = $field['label']; |
218 | 218 | unset($field['label']); |
219 | - } else { |
|
219 | + } |
|
220 | + else { |
|
220 | 221 | $field['is_valid'] = false; |
221 | 222 | glsr_log()->warning('Setting field is missing a label')->debug($field); |
222 | 223 | } |
@@ -11,239 +11,239 @@ |
||
11 | 11 | |
12 | 12 | class Settings |
13 | 13 | { |
14 | - /** |
|
15 | - * @var array |
|
16 | - */ |
|
17 | - public $settings; |
|
18 | - |
|
19 | - /** |
|
20 | - * @param string $id |
|
21 | - * @return string |
|
22 | - */ |
|
23 | - public function buildFields($id) |
|
24 | - { |
|
25 | - $this->settings = glsr(DefaultsManager::class)->settings(); |
|
26 | - $method = Helper::buildMethodName($id, 'getTemplateDataFor'); |
|
27 | - $data = !method_exists($this, $method) |
|
28 | - ? $this->getTemplateData($id) |
|
29 | - : $this->$method($id); |
|
30 | - return glsr(Template::class)->build('pages/settings/'.$id, $data); |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * @return string |
|
35 | - */ |
|
36 | - protected function getFieldDefault(array $field) |
|
37 | - { |
|
38 | - return Arr::get($field, 'default'); |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * @return string |
|
43 | - */ |
|
44 | - protected function getFieldNameForDependsOn($path) |
|
45 | - { |
|
46 | - $fieldName = Str::convertPathToName($path, OptionManager::databaseKey()); |
|
47 | - return $this->isMultiDependency($path) |
|
48 | - ? $fieldName.'[]' |
|
49 | - : $fieldName; |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * @return array |
|
54 | - */ |
|
55 | - protected function getSettingFields($path) |
|
56 | - { |
|
57 | - return array_filter($this->settings, function ($key) use ($path) { |
|
58 | - return Str::startsWith($path, $key); |
|
59 | - }, ARRAY_FILTER_USE_KEY); |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * @return string |
|
64 | - */ |
|
65 | - protected function getSettingRows(array $fields) |
|
66 | - { |
|
67 | - $rows = ''; |
|
68 | - foreach ($fields as $name => $field) { |
|
69 | - $field = wp_parse_args($field, [ |
|
70 | - 'is_setting' => true, |
|
71 | - 'name' => $name, |
|
72 | - ]); |
|
73 | - $rows.= new Field($this->normalize($field)); |
|
74 | - } |
|
75 | - return $rows; |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * @param string $id |
|
80 | - * @return array |
|
81 | - */ |
|
82 | - protected function getTemplateData($id) |
|
83 | - { |
|
84 | - $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
85 | - return [ |
|
86 | - 'context' => [ |
|
87 | - 'rows' => $this->getSettingRows($fields), |
|
88 | - ], |
|
89 | - ]; |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * @param string $id |
|
94 | - * @return array |
|
95 | - */ |
|
96 | - protected function getTemplateDataForAddons($id) |
|
97 | - { |
|
98 | - $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
99 | - $settings = Arr::convertDotNotationArray($fields); |
|
100 | - $settingKeys = array_keys($settings['settings']['addons']); |
|
101 | - $results = []; |
|
102 | - foreach ($settingKeys as $key) { |
|
103 | - $addonFields = array_filter($fields, function ($path) use ($key) { |
|
104 | - return Str::startsWith('settings.addons.'.$key, $path); |
|
105 | - }, ARRAY_FILTER_USE_KEY); |
|
106 | - $results[$key] = $this->getSettingRows($addonFields); |
|
107 | - } |
|
108 | - ksort($results); |
|
109 | - return [ |
|
110 | - 'settings' => $results, |
|
111 | - ]; |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * @param string $id |
|
116 | - * @return array |
|
117 | - */ |
|
118 | - protected function getTemplateDataForLicenses($id) |
|
119 | - { |
|
120 | - $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
121 | - ksort($fields); |
|
122 | - return [ |
|
123 | - 'context' => [ |
|
124 | - 'rows' => $this->getSettingRows($fields), |
|
125 | - ], |
|
126 | - ]; |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * @return array |
|
131 | - */ |
|
132 | - protected function getTemplateDataForTranslations() |
|
133 | - { |
|
134 | - $translations = glsr(Translation::class)->renderAll(); |
|
135 | - $class = empty($translations) |
|
136 | - ? 'glsr-hidden' |
|
137 | - : ''; |
|
138 | - return [ |
|
139 | - 'context' => [ |
|
140 | - 'class' => $class, |
|
141 | - 'database_key' => OptionManager::databaseKey(), |
|
142 | - 'translations' => $translations, |
|
143 | - ], |
|
144 | - ]; |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * @param string $path |
|
149 | - * @param string|array $expectedValue |
|
150 | - * @return bool |
|
151 | - */ |
|
152 | - protected function isFieldHidden($path, $expectedValue) |
|
153 | - { |
|
154 | - $optionValue = glsr(OptionManager::class)->get( |
|
155 | - $path, |
|
156 | - Arr::get(glsr()->defaults, $path) |
|
157 | - ); |
|
158 | - if (is_array($expectedValue)) { |
|
159 | - return is_array($optionValue) |
|
160 | - ? 0 === count(array_intersect($optionValue, $expectedValue)) |
|
161 | - : !in_array($optionValue, $expectedValue); |
|
162 | - } |
|
163 | - return $optionValue != $expectedValue; |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * @return bool |
|
168 | - */ |
|
169 | - protected function isMultiDependency($path) |
|
170 | - { |
|
171 | - if (isset($this->settings[$path])) { |
|
172 | - $field = $this->settings[$path]; |
|
173 | - return ('checkbox' == $field['type'] && !empty($field['options'])) |
|
174 | - || !empty($field['multiple']); |
|
175 | - } |
|
176 | - return false; |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * @return array |
|
181 | - */ |
|
182 | - protected function normalize(array $field) |
|
183 | - { |
|
184 | - $field = $this->normalizeDependsOn($field); |
|
185 | - $field = $this->normalizeLabelAndLegend($field); |
|
186 | - $field = $this->normalizeValue($field); |
|
187 | - return $field; |
|
188 | - } |
|
189 | - |
|
190 | - /** |
|
191 | - * @return array |
|
192 | - */ |
|
193 | - protected function normalizeDependsOn(array $field) |
|
194 | - { |
|
195 | - if (!empty($field['depends_on']) && is_array($field['depends_on'])) { |
|
196 | - $isFieldHidden = false; |
|
197 | - $conditions = []; |
|
198 | - foreach ($field['depends_on'] as $path => $value) { |
|
199 | - $conditions[] = [ |
|
200 | - 'name' => $this->getFieldNameForDependsOn($path), |
|
201 | - 'value' => $value, |
|
202 | - ]; |
|
203 | - if ($this->isFieldHidden($path, $value)) { |
|
204 | - $isFieldHidden = true; |
|
205 | - } |
|
206 | - } |
|
207 | - $field['data-depends'] = json_encode($conditions, JSON_HEX_APOS | JSON_HEX_QUOT); |
|
208 | - $field['is_hidden'] = $isFieldHidden; |
|
209 | - } |
|
210 | - return $field; |
|
211 | - } |
|
212 | - |
|
213 | - /** |
|
214 | - * @return array |
|
215 | - */ |
|
216 | - protected function normalizeLabelAndLegend(array $field) |
|
217 | - { |
|
218 | - if (!empty($field['label'])) { |
|
219 | - $field['legend'] = $field['label']; |
|
220 | - unset($field['label']); |
|
221 | - } else { |
|
222 | - $field['is_valid'] = false; |
|
223 | - glsr_log()->warning('Setting field is missing a label')->debug($field); |
|
224 | - } |
|
225 | - return $field; |
|
226 | - } |
|
227 | - |
|
228 | - /** |
|
229 | - * @return array |
|
230 | - */ |
|
231 | - protected function normalizeValue(array $field) |
|
232 | - { |
|
233 | - if (!isset($field['value'])) { |
|
234 | - $field['value'] = glsr(OptionManager::class)->get( |
|
235 | - $field['name'], |
|
236 | - $this->getFieldDefault($field) |
|
237 | - ); |
|
238 | - } |
|
239 | - return $field; |
|
240 | - } |
|
241 | - |
|
242 | - /** |
|
243 | - * @return string |
|
244 | - */ |
|
245 | - protected function normalizeSettingPath($path) |
|
246 | - { |
|
247 | - return Str::prefix('settings.', rtrim($path, '.')); |
|
248 | - } |
|
14 | + /** |
|
15 | + * @var array |
|
16 | + */ |
|
17 | + public $settings; |
|
18 | + |
|
19 | + /** |
|
20 | + * @param string $id |
|
21 | + * @return string |
|
22 | + */ |
|
23 | + public function buildFields($id) |
|
24 | + { |
|
25 | + $this->settings = glsr(DefaultsManager::class)->settings(); |
|
26 | + $method = Helper::buildMethodName($id, 'getTemplateDataFor'); |
|
27 | + $data = !method_exists($this, $method) |
|
28 | + ? $this->getTemplateData($id) |
|
29 | + : $this->$method($id); |
|
30 | + return glsr(Template::class)->build('pages/settings/'.$id, $data); |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * @return string |
|
35 | + */ |
|
36 | + protected function getFieldDefault(array $field) |
|
37 | + { |
|
38 | + return Arr::get($field, 'default'); |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * @return string |
|
43 | + */ |
|
44 | + protected function getFieldNameForDependsOn($path) |
|
45 | + { |
|
46 | + $fieldName = Str::convertPathToName($path, OptionManager::databaseKey()); |
|
47 | + return $this->isMultiDependency($path) |
|
48 | + ? $fieldName.'[]' |
|
49 | + : $fieldName; |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * @return array |
|
54 | + */ |
|
55 | + protected function getSettingFields($path) |
|
56 | + { |
|
57 | + return array_filter($this->settings, function ($key) use ($path) { |
|
58 | + return Str::startsWith($path, $key); |
|
59 | + }, ARRAY_FILTER_USE_KEY); |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * @return string |
|
64 | + */ |
|
65 | + protected function getSettingRows(array $fields) |
|
66 | + { |
|
67 | + $rows = ''; |
|
68 | + foreach ($fields as $name => $field) { |
|
69 | + $field = wp_parse_args($field, [ |
|
70 | + 'is_setting' => true, |
|
71 | + 'name' => $name, |
|
72 | + ]); |
|
73 | + $rows.= new Field($this->normalize($field)); |
|
74 | + } |
|
75 | + return $rows; |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * @param string $id |
|
80 | + * @return array |
|
81 | + */ |
|
82 | + protected function getTemplateData($id) |
|
83 | + { |
|
84 | + $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
85 | + return [ |
|
86 | + 'context' => [ |
|
87 | + 'rows' => $this->getSettingRows($fields), |
|
88 | + ], |
|
89 | + ]; |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * @param string $id |
|
94 | + * @return array |
|
95 | + */ |
|
96 | + protected function getTemplateDataForAddons($id) |
|
97 | + { |
|
98 | + $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
99 | + $settings = Arr::convertDotNotationArray($fields); |
|
100 | + $settingKeys = array_keys($settings['settings']['addons']); |
|
101 | + $results = []; |
|
102 | + foreach ($settingKeys as $key) { |
|
103 | + $addonFields = array_filter($fields, function ($path) use ($key) { |
|
104 | + return Str::startsWith('settings.addons.'.$key, $path); |
|
105 | + }, ARRAY_FILTER_USE_KEY); |
|
106 | + $results[$key] = $this->getSettingRows($addonFields); |
|
107 | + } |
|
108 | + ksort($results); |
|
109 | + return [ |
|
110 | + 'settings' => $results, |
|
111 | + ]; |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * @param string $id |
|
116 | + * @return array |
|
117 | + */ |
|
118 | + protected function getTemplateDataForLicenses($id) |
|
119 | + { |
|
120 | + $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
121 | + ksort($fields); |
|
122 | + return [ |
|
123 | + 'context' => [ |
|
124 | + 'rows' => $this->getSettingRows($fields), |
|
125 | + ], |
|
126 | + ]; |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * @return array |
|
131 | + */ |
|
132 | + protected function getTemplateDataForTranslations() |
|
133 | + { |
|
134 | + $translations = glsr(Translation::class)->renderAll(); |
|
135 | + $class = empty($translations) |
|
136 | + ? 'glsr-hidden' |
|
137 | + : ''; |
|
138 | + return [ |
|
139 | + 'context' => [ |
|
140 | + 'class' => $class, |
|
141 | + 'database_key' => OptionManager::databaseKey(), |
|
142 | + 'translations' => $translations, |
|
143 | + ], |
|
144 | + ]; |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * @param string $path |
|
149 | + * @param string|array $expectedValue |
|
150 | + * @return bool |
|
151 | + */ |
|
152 | + protected function isFieldHidden($path, $expectedValue) |
|
153 | + { |
|
154 | + $optionValue = glsr(OptionManager::class)->get( |
|
155 | + $path, |
|
156 | + Arr::get(glsr()->defaults, $path) |
|
157 | + ); |
|
158 | + if (is_array($expectedValue)) { |
|
159 | + return is_array($optionValue) |
|
160 | + ? 0 === count(array_intersect($optionValue, $expectedValue)) |
|
161 | + : !in_array($optionValue, $expectedValue); |
|
162 | + } |
|
163 | + return $optionValue != $expectedValue; |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * @return bool |
|
168 | + */ |
|
169 | + protected function isMultiDependency($path) |
|
170 | + { |
|
171 | + if (isset($this->settings[$path])) { |
|
172 | + $field = $this->settings[$path]; |
|
173 | + return ('checkbox' == $field['type'] && !empty($field['options'])) |
|
174 | + || !empty($field['multiple']); |
|
175 | + } |
|
176 | + return false; |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * @return array |
|
181 | + */ |
|
182 | + protected function normalize(array $field) |
|
183 | + { |
|
184 | + $field = $this->normalizeDependsOn($field); |
|
185 | + $field = $this->normalizeLabelAndLegend($field); |
|
186 | + $field = $this->normalizeValue($field); |
|
187 | + return $field; |
|
188 | + } |
|
189 | + |
|
190 | + /** |
|
191 | + * @return array |
|
192 | + */ |
|
193 | + protected function normalizeDependsOn(array $field) |
|
194 | + { |
|
195 | + if (!empty($field['depends_on']) && is_array($field['depends_on'])) { |
|
196 | + $isFieldHidden = false; |
|
197 | + $conditions = []; |
|
198 | + foreach ($field['depends_on'] as $path => $value) { |
|
199 | + $conditions[] = [ |
|
200 | + 'name' => $this->getFieldNameForDependsOn($path), |
|
201 | + 'value' => $value, |
|
202 | + ]; |
|
203 | + if ($this->isFieldHidden($path, $value)) { |
|
204 | + $isFieldHidden = true; |
|
205 | + } |
|
206 | + } |
|
207 | + $field['data-depends'] = json_encode($conditions, JSON_HEX_APOS | JSON_HEX_QUOT); |
|
208 | + $field['is_hidden'] = $isFieldHidden; |
|
209 | + } |
|
210 | + return $field; |
|
211 | + } |
|
212 | + |
|
213 | + /** |
|
214 | + * @return array |
|
215 | + */ |
|
216 | + protected function normalizeLabelAndLegend(array $field) |
|
217 | + { |
|
218 | + if (!empty($field['label'])) { |
|
219 | + $field['legend'] = $field['label']; |
|
220 | + unset($field['label']); |
|
221 | + } else { |
|
222 | + $field['is_valid'] = false; |
|
223 | + glsr_log()->warning('Setting field is missing a label')->debug($field); |
|
224 | + } |
|
225 | + return $field; |
|
226 | + } |
|
227 | + |
|
228 | + /** |
|
229 | + * @return array |
|
230 | + */ |
|
231 | + protected function normalizeValue(array $field) |
|
232 | + { |
|
233 | + if (!isset($field['value'])) { |
|
234 | + $field['value'] = glsr(OptionManager::class)->get( |
|
235 | + $field['name'], |
|
236 | + $this->getFieldDefault($field) |
|
237 | + ); |
|
238 | + } |
|
239 | + return $field; |
|
240 | + } |
|
241 | + |
|
242 | + /** |
|
243 | + * @return string |
|
244 | + */ |
|
245 | + protected function normalizeSettingPath($path) |
|
246 | + { |
|
247 | + return Str::prefix('settings.', rtrim($path, '.')); |
|
248 | + } |
|
249 | 249 | } |
@@ -20,31 +20,31 @@ discard block |
||
20 | 20 | * @param string $id |
21 | 21 | * @return string |
22 | 22 | */ |
23 | - public function buildFields($id) |
|
23 | + public function buildFields( $id ) |
|
24 | 24 | { |
25 | - $this->settings = glsr(DefaultsManager::class)->settings(); |
|
26 | - $method = Helper::buildMethodName($id, 'getTemplateDataFor'); |
|
27 | - $data = !method_exists($this, $method) |
|
28 | - ? $this->getTemplateData($id) |
|
29 | - : $this->$method($id); |
|
30 | - return glsr(Template::class)->build('pages/settings/'.$id, $data); |
|
25 | + $this->settings = glsr( DefaultsManager::class )->settings(); |
|
26 | + $method = Helper::buildMethodName( $id, 'getTemplateDataFor' ); |
|
27 | + $data = !method_exists( $this, $method ) |
|
28 | + ? $this->getTemplateData( $id ) |
|
29 | + : $this->$method( $id ); |
|
30 | + return glsr( Template::class )->build( 'pages/settings/'.$id, $data ); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
34 | 34 | * @return string |
35 | 35 | */ |
36 | - protected function getFieldDefault(array $field) |
|
36 | + protected function getFieldDefault( array $field ) |
|
37 | 37 | { |
38 | - return Arr::get($field, 'default'); |
|
38 | + return Arr::get( $field, 'default' ); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
42 | 42 | * @return string |
43 | 43 | */ |
44 | - protected function getFieldNameForDependsOn($path) |
|
44 | + protected function getFieldNameForDependsOn( $path ) |
|
45 | 45 | { |
46 | - $fieldName = Str::convertPathToName($path, OptionManager::databaseKey()); |
|
47 | - return $this->isMultiDependency($path) |
|
46 | + $fieldName = Str::convertPathToName( $path, OptionManager::databaseKey() ); |
|
47 | + return $this->isMultiDependency( $path ) |
|
48 | 48 | ? $fieldName.'[]' |
49 | 49 | : $fieldName; |
50 | 50 | } |
@@ -52,25 +52,25 @@ discard block |
||
52 | 52 | /** |
53 | 53 | * @return array |
54 | 54 | */ |
55 | - protected function getSettingFields($path) |
|
55 | + protected function getSettingFields( $path ) |
|
56 | 56 | { |
57 | - return array_filter($this->settings, function ($key) use ($path) { |
|
58 | - return Str::startsWith($path, $key); |
|
59 | - }, ARRAY_FILTER_USE_KEY); |
|
57 | + return array_filter( $this->settings, function( $key ) use ($path) { |
|
58 | + return Str::startsWith( $path, $key ); |
|
59 | + }, ARRAY_FILTER_USE_KEY ); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
63 | 63 | * @return string |
64 | 64 | */ |
65 | - protected function getSettingRows(array $fields) |
|
65 | + protected function getSettingRows( array $fields ) |
|
66 | 66 | { |
67 | 67 | $rows = ''; |
68 | - foreach ($fields as $name => $field) { |
|
69 | - $field = wp_parse_args($field, [ |
|
68 | + foreach( $fields as $name => $field ) { |
|
69 | + $field = wp_parse_args( $field, [ |
|
70 | 70 | 'is_setting' => true, |
71 | 71 | 'name' => $name, |
72 | - ]); |
|
73 | - $rows.= new Field($this->normalize($field)); |
|
72 | + ] ); |
|
73 | + $rows .= new Field( $this->normalize( $field ) ); |
|
74 | 74 | } |
75 | 75 | return $rows; |
76 | 76 | } |
@@ -79,12 +79,12 @@ discard block |
||
79 | 79 | * @param string $id |
80 | 80 | * @return array |
81 | 81 | */ |
82 | - protected function getTemplateData($id) |
|
82 | + protected function getTemplateData( $id ) |
|
83 | 83 | { |
84 | - $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
84 | + $fields = $this->getSettingFields( $this->normalizeSettingPath( $id ) ); |
|
85 | 85 | return [ |
86 | 86 | 'context' => [ |
87 | - 'rows' => $this->getSettingRows($fields), |
|
87 | + 'rows' => $this->getSettingRows( $fields ), |
|
88 | 88 | ], |
89 | 89 | ]; |
90 | 90 | } |
@@ -93,19 +93,19 @@ discard block |
||
93 | 93 | * @param string $id |
94 | 94 | * @return array |
95 | 95 | */ |
96 | - protected function getTemplateDataForAddons($id) |
|
96 | + protected function getTemplateDataForAddons( $id ) |
|
97 | 97 | { |
98 | - $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
99 | - $settings = Arr::convertDotNotationArray($fields); |
|
100 | - $settingKeys = array_keys($settings['settings']['addons']); |
|
98 | + $fields = $this->getSettingFields( $this->normalizeSettingPath( $id ) ); |
|
99 | + $settings = Arr::convertDotNotationArray( $fields ); |
|
100 | + $settingKeys = array_keys( $settings['settings']['addons'] ); |
|
101 | 101 | $results = []; |
102 | - foreach ($settingKeys as $key) { |
|
103 | - $addonFields = array_filter($fields, function ($path) use ($key) { |
|
104 | - return Str::startsWith('settings.addons.'.$key, $path); |
|
105 | - }, ARRAY_FILTER_USE_KEY); |
|
106 | - $results[$key] = $this->getSettingRows($addonFields); |
|
102 | + foreach( $settingKeys as $key ) { |
|
103 | + $addonFields = array_filter( $fields, function( $path ) use ($key) { |
|
104 | + return Str::startsWith( 'settings.addons.'.$key, $path ); |
|
105 | + }, ARRAY_FILTER_USE_KEY ); |
|
106 | + $results[$key] = $this->getSettingRows( $addonFields ); |
|
107 | 107 | } |
108 | - ksort($results); |
|
108 | + ksort( $results ); |
|
109 | 109 | return [ |
110 | 110 | 'settings' => $results, |
111 | 111 | ]; |
@@ -115,13 +115,13 @@ discard block |
||
115 | 115 | * @param string $id |
116 | 116 | * @return array |
117 | 117 | */ |
118 | - protected function getTemplateDataForLicenses($id) |
|
118 | + protected function getTemplateDataForLicenses( $id ) |
|
119 | 119 | { |
120 | - $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
121 | - ksort($fields); |
|
120 | + $fields = $this->getSettingFields( $this->normalizeSettingPath( $id ) ); |
|
121 | + ksort( $fields ); |
|
122 | 122 | return [ |
123 | 123 | 'context' => [ |
124 | - 'rows' => $this->getSettingRows($fields), |
|
124 | + 'rows' => $this->getSettingRows( $fields ), |
|
125 | 125 | ], |
126 | 126 | ]; |
127 | 127 | } |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | */ |
132 | 132 | protected function getTemplateDataForTranslations() |
133 | 133 | { |
134 | - $translations = glsr(Translation::class)->renderAll(); |
|
134 | + $translations = glsr( Translation::class )->renderAll(); |
|
135 | 135 | $class = empty($translations) |
136 | 136 | ? 'glsr-hidden' |
137 | 137 | : ''; |
@@ -149,16 +149,16 @@ discard block |
||
149 | 149 | * @param string|array $expectedValue |
150 | 150 | * @return bool |
151 | 151 | */ |
152 | - protected function isFieldHidden($path, $expectedValue) |
|
152 | + protected function isFieldHidden( $path, $expectedValue ) |
|
153 | 153 | { |
154 | - $optionValue = glsr(OptionManager::class)->get( |
|
154 | + $optionValue = glsr( OptionManager::class )->get( |
|
155 | 155 | $path, |
156 | - Arr::get(glsr()->defaults, $path) |
|
156 | + Arr::get( glsr()->defaults, $path ) |
|
157 | 157 | ); |
158 | - if (is_array($expectedValue)) { |
|
159 | - return is_array($optionValue) |
|
160 | - ? 0 === count(array_intersect($optionValue, $expectedValue)) |
|
161 | - : !in_array($optionValue, $expectedValue); |
|
158 | + if( is_array( $expectedValue ) ) { |
|
159 | + return is_array( $optionValue ) |
|
160 | + ? 0 === count( array_intersect( $optionValue, $expectedValue ) ) |
|
161 | + : !in_array( $optionValue, $expectedValue ); |
|
162 | 162 | } |
163 | 163 | return $optionValue != $expectedValue; |
164 | 164 | } |
@@ -166,9 +166,9 @@ discard block |
||
166 | 166 | /** |
167 | 167 | * @return bool |
168 | 168 | */ |
169 | - protected function isMultiDependency($path) |
|
169 | + protected function isMultiDependency( $path ) |
|
170 | 170 | { |
171 | - if (isset($this->settings[$path])) { |
|
171 | + if( isset($this->settings[$path]) ) { |
|
172 | 172 | $field = $this->settings[$path]; |
173 | 173 | return ('checkbox' == $field['type'] && !empty($field['options'])) |
174 | 174 | || !empty($field['multiple']); |
@@ -179,32 +179,32 @@ discard block |
||
179 | 179 | /** |
180 | 180 | * @return array |
181 | 181 | */ |
182 | - protected function normalize(array $field) |
|
182 | + protected function normalize( array $field ) |
|
183 | 183 | { |
184 | - $field = $this->normalizeDependsOn($field); |
|
185 | - $field = $this->normalizeLabelAndLegend($field); |
|
186 | - $field = $this->normalizeValue($field); |
|
184 | + $field = $this->normalizeDependsOn( $field ); |
|
185 | + $field = $this->normalizeLabelAndLegend( $field ); |
|
186 | + $field = $this->normalizeValue( $field ); |
|
187 | 187 | return $field; |
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
191 | 191 | * @return array |
192 | 192 | */ |
193 | - protected function normalizeDependsOn(array $field) |
|
193 | + protected function normalizeDependsOn( array $field ) |
|
194 | 194 | { |
195 | - if (!empty($field['depends_on']) && is_array($field['depends_on'])) { |
|
195 | + if( !empty($field['depends_on']) && is_array( $field['depends_on'] ) ) { |
|
196 | 196 | $isFieldHidden = false; |
197 | 197 | $conditions = []; |
198 | - foreach ($field['depends_on'] as $path => $value) { |
|
198 | + foreach( $field['depends_on'] as $path => $value ) { |
|
199 | 199 | $conditions[] = [ |
200 | - 'name' => $this->getFieldNameForDependsOn($path), |
|
200 | + 'name' => $this->getFieldNameForDependsOn( $path ), |
|
201 | 201 | 'value' => $value, |
202 | 202 | ]; |
203 | - if ($this->isFieldHidden($path, $value)) { |
|
203 | + if( $this->isFieldHidden( $path, $value ) ) { |
|
204 | 204 | $isFieldHidden = true; |
205 | 205 | } |
206 | 206 | } |
207 | - $field['data-depends'] = json_encode($conditions, JSON_HEX_APOS | JSON_HEX_QUOT); |
|
207 | + $field['data-depends'] = json_encode( $conditions, JSON_HEX_APOS | JSON_HEX_QUOT ); |
|
208 | 208 | $field['is_hidden'] = $isFieldHidden; |
209 | 209 | } |
210 | 210 | return $field; |
@@ -213,14 +213,14 @@ discard block |
||
213 | 213 | /** |
214 | 214 | * @return array |
215 | 215 | */ |
216 | - protected function normalizeLabelAndLegend(array $field) |
|
216 | + protected function normalizeLabelAndLegend( array $field ) |
|
217 | 217 | { |
218 | - if (!empty($field['label'])) { |
|
218 | + if( !empty($field['label']) ) { |
|
219 | 219 | $field['legend'] = $field['label']; |
220 | 220 | unset($field['label']); |
221 | 221 | } else { |
222 | 222 | $field['is_valid'] = false; |
223 | - glsr_log()->warning('Setting field is missing a label')->debug($field); |
|
223 | + glsr_log()->warning( 'Setting field is missing a label' )->debug( $field ); |
|
224 | 224 | } |
225 | 225 | return $field; |
226 | 226 | } |
@@ -228,12 +228,12 @@ discard block |
||
228 | 228 | /** |
229 | 229 | * @return array |
230 | 230 | */ |
231 | - protected function normalizeValue(array $field) |
|
231 | + protected function normalizeValue( array $field ) |
|
232 | 232 | { |
233 | - if (!isset($field['value'])) { |
|
234 | - $field['value'] = glsr(OptionManager::class)->get( |
|
233 | + if( !isset($field['value']) ) { |
|
234 | + $field['value'] = glsr( OptionManager::class )->get( |
|
235 | 235 | $field['name'], |
236 | - $this->getFieldDefault($field) |
|
236 | + $this->getFieldDefault( $field ) |
|
237 | 237 | ); |
238 | 238 | } |
239 | 239 | return $field; |
@@ -242,8 +242,8 @@ discard block |
||
242 | 242 | /** |
243 | 243 | * @return string |
244 | 244 | */ |
245 | - protected function normalizeSettingPath($path) |
|
245 | + protected function normalizeSettingPath( $path ) |
|
246 | 246 | { |
247 | - return Str::prefix('settings.', rtrim($path, '.')); |
|
247 | + return Str::prefix( 'settings.', rtrim( $path, '.' ) ); |
|
248 | 248 | } |
249 | 249 | } |
@@ -328,7 +328,8 @@ |
||
328 | 328 | } |
329 | 329 | if (is_array($params[0])) { |
330 | 330 | $this->args += $params[0]; |
331 | - } elseif (is_array($params[1])) { |
|
331 | + } |
|
332 | + elseif (is_array($params[1])) { |
|
332 | 333 | $this->args += $params[1]; |
333 | 334 | } |
334 | 335 | if (!isset($this->args['is_public'])) { |
@@ -18,346 +18,346 @@ |
||
18 | 18 | */ |
19 | 19 | class Builder |
20 | 20 | { |
21 | - const INPUT_TYPES = [ |
|
22 | - 'checkbox', 'date', 'datetime-local', 'email', 'file', 'hidden', 'image', 'month', |
|
23 | - 'number', 'password', 'radio', 'range', 'reset', 'search', 'submit', 'tel', 'text', 'time', |
|
24 | - 'url', 'week', |
|
25 | - ]; |
|
26 | - |
|
27 | - const TAGS_FORM = [ |
|
28 | - 'input', 'select', 'textarea', |
|
29 | - ]; |
|
30 | - |
|
31 | - const TAGS_SINGLE = [ |
|
32 | - 'img', |
|
33 | - ]; |
|
34 | - |
|
35 | - const TAGS_STRUCTURE = [ |
|
36 | - 'div', 'form', 'nav', 'ol', 'section', 'ul', |
|
37 | - ]; |
|
38 | - |
|
39 | - const TAGS_TEXT = [ |
|
40 | - 'a', 'button', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'i', 'label', 'li', 'option', 'p', 'pre', |
|
41 | - 'small', 'span', |
|
42 | - ]; |
|
43 | - |
|
44 | - /** |
|
45 | - * @var array |
|
46 | - */ |
|
47 | - public $args = []; |
|
48 | - |
|
49 | - /** |
|
50 | - * @var bool |
|
51 | - */ |
|
52 | - public $render = false; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var string |
|
56 | - */ |
|
57 | - public $tag; |
|
58 | - |
|
59 | - /** |
|
60 | - * @param string $method |
|
61 | - * @param array $args |
|
62 | - * @return string|void |
|
63 | - */ |
|
64 | - public function __call($method, $args) |
|
65 | - { |
|
66 | - $instance = new static(); |
|
67 | - $instance->setTagFromMethod($method); |
|
68 | - call_user_func_array([$instance, 'normalize'], $args += ['', '']); |
|
69 | - $tags = array_merge(static::TAGS_FORM, static::TAGS_SINGLE, static::TAGS_STRUCTURE, static::TAGS_TEXT); |
|
70 | - do_action_ref_array('site-reviews/builder', [$instance]); |
|
71 | - $generatedTag = in_array($instance->tag, $tags) |
|
72 | - ? $instance->buildTag() |
|
73 | - : $instance->buildCustomField(); |
|
74 | - $generatedTag = apply_filters('site-reviews/builder/result', $generatedTag, $instance); |
|
75 | - if (!$this->render) { |
|
76 | - return $generatedTag; |
|
77 | - } |
|
78 | - echo $generatedTag; |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * @param string $property |
|
83 | - * @param mixed $value |
|
84 | - * @return void |
|
85 | - */ |
|
86 | - public function __set($property, $value) |
|
87 | - { |
|
88 | - $properties = [ |
|
89 | - 'args' => 'is_array', |
|
90 | - 'render' => 'is_bool', |
|
91 | - 'tag' => 'is_string', |
|
92 | - ]; |
|
93 | - if (!isset($properties[$property]) |
|
94 | - || empty(array_filter([$value], $properties[$property])) |
|
95 | - ) { |
|
96 | - return; |
|
97 | - } |
|
98 | - $this->$property = $value; |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * @return void|string |
|
103 | - */ |
|
104 | - public function getClosingTag() |
|
105 | - { |
|
106 | - if (empty($this->tag)) { |
|
107 | - return; |
|
108 | - } |
|
109 | - return '</'.$this->tag.'>'; |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * @return void|string |
|
114 | - */ |
|
115 | - public function getOpeningTag() |
|
116 | - { |
|
117 | - if (empty($this->tag)) { |
|
118 | - return; |
|
119 | - } |
|
120 | - $attributes = glsr(Attributes::class)->{$this->tag}($this->args)->toString(); |
|
121 | - return '<'.trim($this->tag.' '.$attributes).'>'; |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * @return void|string |
|
126 | - */ |
|
127 | - public function getTag() |
|
128 | - { |
|
129 | - if (in_array($this->tag, static::TAGS_SINGLE)) { |
|
130 | - return $this->getOpeningTag(); |
|
131 | - } |
|
132 | - if (!in_array($this->tag, static::TAGS_FORM)) { |
|
133 | - return $this->buildDefaultTag(); |
|
134 | - } |
|
135 | - return call_user_func([$this, 'buildForm'.ucfirst($this->tag)]).$this->buildFieldDescription(); |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * @return string |
|
140 | - */ |
|
141 | - public function raw(array $field) |
|
142 | - { |
|
143 | - unset($field['label']); |
|
144 | - return $this->{$field['type']}($field); |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * @return string|void |
|
149 | - */ |
|
150 | - protected function buildCustomField() |
|
151 | - { |
|
152 | - $className = $this->getCustomFieldClassName(); |
|
153 | - if (class_exists($className)) { |
|
154 | - return (new $className($this))->build(); |
|
155 | - } |
|
156 | - glsr_log()->error('Field missing: '.$className); |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * @return string|void |
|
161 | - */ |
|
162 | - protected function buildDefaultTag($text = '') |
|
163 | - { |
|
164 | - if (empty($text)) { |
|
165 | - $text = $this->args['text']; |
|
166 | - } |
|
167 | - return $this->getOpeningTag().$text.$this->getClosingTag(); |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * @return string|void |
|
172 | - */ |
|
173 | - protected function buildFieldDescription() |
|
174 | - { |
|
175 | - if (empty($this->args['description'])) { |
|
176 | - return; |
|
177 | - } |
|
178 | - if ($this->args['is_widget']) { |
|
179 | - return $this->small($this->args['description']); |
|
180 | - } |
|
181 | - return $this->p($this->args['description'], ['class' => 'description']); |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * @return string|void |
|
186 | - */ |
|
187 | - protected function buildFormInput() |
|
188 | - { |
|
189 | - if (!in_array($this->args['type'], ['checkbox', 'radio'])) { |
|
190 | - if (isset($this->args['multiple'])) { |
|
191 | - $this->args['name'].= '[]'; |
|
192 | - } |
|
193 | - return $this->buildFormLabel().$this->getOpeningTag(); |
|
194 | - } |
|
195 | - return empty($this->args['options']) |
|
196 | - ? $this->buildFormInputChoice() |
|
197 | - : $this->buildFormInputMultiChoice(); |
|
198 | - } |
|
199 | - |
|
200 | - /** |
|
201 | - * @return string|void |
|
202 | - */ |
|
203 | - protected function buildFormInputChoice() |
|
204 | - { |
|
205 | - if (!empty($this->args['text'])) { |
|
206 | - $this->args['label'] = $this->args['text']; |
|
207 | - } |
|
208 | - if (!$this->args['is_public']) { |
|
209 | - return $this->buildFormLabel([ |
|
210 | - 'class' => 'glsr-'.$this->args['type'].'-label', |
|
211 | - 'text' => $this->getOpeningTag().' '.$this->args['label'].'<span></span>', |
|
212 | - ]); |
|
213 | - } |
|
214 | - return $this->getOpeningTag().$this->buildFormLabel([ |
|
215 | - 'class' => 'glsr-'.$this->args['type'].'-label', |
|
216 | - 'text' => $this->args['label'].'<span></span>', |
|
217 | - ]); |
|
218 | - } |
|
219 | - |
|
220 | - /** |
|
221 | - * @return string|void |
|
222 | - */ |
|
223 | - protected function buildFormInputMultiChoice() |
|
224 | - { |
|
225 | - if ('checkbox' == $this->args['type']) { |
|
226 | - $this->args['name'].= '[]'; |
|
227 | - } |
|
228 | - $index = 0; |
|
229 | - $options = array_reduce(array_keys($this->args['options']), function ($carry, $key) use (&$index) { |
|
230 | - return $carry.$this->li($this->{$this->args['type']}([ |
|
231 | - 'checked' => in_array($key, (array) $this->args['value']), |
|
232 | - 'id' => $this->args['id'].'-'.$index++, |
|
233 | - 'name' => $this->args['name'], |
|
234 | - 'text' => $this->args['options'][$key], |
|
235 | - 'value' => $key, |
|
236 | - ])); |
|
237 | - }); |
|
238 | - return $this->ul($options, [ |
|
239 | - 'class' => $this->args['class'], |
|
240 | - 'id' => $this->args['id'], |
|
241 | - ]); |
|
242 | - } |
|
243 | - |
|
244 | - /** |
|
245 | - * @return void|string |
|
246 | - */ |
|
247 | - protected function buildFormLabel(array $customArgs = []) |
|
248 | - { |
|
249 | - if (empty($this->args['label']) || 'hidden' == $this->args['type']) { |
|
250 | - return; |
|
251 | - } |
|
252 | - return $this->label(wp_parse_args($customArgs, [ |
|
253 | - 'for' => $this->args['id'], |
|
254 | - 'is_public' => $this->args['is_public'], |
|
255 | - 'text' => $this->args['label'], |
|
256 | - 'type' => $this->args['type'], |
|
257 | - ])); |
|
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * @return string|void |
|
262 | - */ |
|
263 | - protected function buildFormSelect() |
|
264 | - { |
|
265 | - return $this->buildFormLabel().$this->buildDefaultTag($this->buildFormSelectOptions()); |
|
266 | - } |
|
267 | - |
|
268 | - /** |
|
269 | - * @return string|void |
|
270 | - */ |
|
271 | - protected function buildFormSelectOptions() |
|
272 | - { |
|
273 | - return array_reduce(array_keys($this->args['options']), function ($carry, $key) { |
|
274 | - return $carry.$this->option([ |
|
275 | - 'selected' => $this->args['value'] == $key, |
|
276 | - 'text' => $this->args['options'][$key], |
|
277 | - 'value' => $key, |
|
278 | - ]); |
|
279 | - }); |
|
280 | - } |
|
281 | - |
|
282 | - /** |
|
283 | - * @return string|void |
|
284 | - */ |
|
285 | - protected function buildFormTextarea() |
|
286 | - { |
|
287 | - return $this->buildFormLabel().$this->buildDefaultTag($this->args['value']); |
|
288 | - } |
|
289 | - |
|
290 | - /** |
|
291 | - * @return string|void |
|
292 | - */ |
|
293 | - protected function buildTag() |
|
294 | - { |
|
295 | - $this->mergeArgsWithRequiredDefaults(); |
|
296 | - return $this->getTag(); |
|
297 | - } |
|
298 | - |
|
299 | - /** |
|
300 | - * @return string |
|
301 | - */ |
|
302 | - protected function getCustomFieldClassName() |
|
303 | - { |
|
304 | - $classname = Helper::buildClassName($this->tag, __NAMESPACE__.'\Fields'); |
|
305 | - return apply_filters('site-reviews/builder/field/'.$this->tag, $classname); |
|
306 | - } |
|
307 | - |
|
308 | - /** |
|
309 | - * @return void |
|
310 | - */ |
|
311 | - protected function mergeArgsWithRequiredDefaults() |
|
312 | - { |
|
313 | - $className = $this->getCustomFieldClassName(); |
|
314 | - if (class_exists($className)) { |
|
315 | - $this->args = $className::merge($this->args); |
|
316 | - } |
|
317 | - $this->args = glsr(BuilderDefaults::class)->merge($this->args); |
|
318 | - } |
|
319 | - |
|
320 | - /** |
|
321 | - * @param string|array ...$params |
|
322 | - * @return void |
|
323 | - */ |
|
324 | - protected function normalize(...$params) |
|
325 | - { |
|
326 | - if (is_string($params[0]) || is_numeric($params[0])) { |
|
327 | - $this->setNameOrTextAttributeForTag($params[0]); |
|
328 | - } |
|
329 | - if (is_array($params[0])) { |
|
330 | - $this->args += $params[0]; |
|
331 | - } elseif (is_array($params[1])) { |
|
332 | - $this->args += $params[1]; |
|
333 | - } |
|
334 | - if (!isset($this->args['is_public'])) { |
|
335 | - $this->args['is_public'] = false; |
|
336 | - } |
|
337 | - } |
|
338 | - |
|
339 | - /** |
|
340 | - * @param string $value |
|
341 | - * @return void |
|
342 | - */ |
|
343 | - protected function setNameOrTextAttributeForTag($value) |
|
344 | - { |
|
345 | - $attribute = in_array($this->tag, static::TAGS_FORM) |
|
346 | - ? 'name' |
|
347 | - : 'text'; |
|
348 | - $this->args[$attribute] = $value; |
|
349 | - } |
|
350 | - |
|
351 | - /** |
|
352 | - * @param string $method |
|
353 | - * @return void |
|
354 | - */ |
|
355 | - protected function setTagFromMethod($method) |
|
356 | - { |
|
357 | - $this->tag = strtolower($method); |
|
358 | - if (in_array($this->tag, static::INPUT_TYPES)) { |
|
359 | - $this->args['type'] = $this->tag; |
|
360 | - $this->tag = 'input'; |
|
361 | - } |
|
362 | - } |
|
21 | + const INPUT_TYPES = [ |
|
22 | + 'checkbox', 'date', 'datetime-local', 'email', 'file', 'hidden', 'image', 'month', |
|
23 | + 'number', 'password', 'radio', 'range', 'reset', 'search', 'submit', 'tel', 'text', 'time', |
|
24 | + 'url', 'week', |
|
25 | + ]; |
|
26 | + |
|
27 | + const TAGS_FORM = [ |
|
28 | + 'input', 'select', 'textarea', |
|
29 | + ]; |
|
30 | + |
|
31 | + const TAGS_SINGLE = [ |
|
32 | + 'img', |
|
33 | + ]; |
|
34 | + |
|
35 | + const TAGS_STRUCTURE = [ |
|
36 | + 'div', 'form', 'nav', 'ol', 'section', 'ul', |
|
37 | + ]; |
|
38 | + |
|
39 | + const TAGS_TEXT = [ |
|
40 | + 'a', 'button', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'i', 'label', 'li', 'option', 'p', 'pre', |
|
41 | + 'small', 'span', |
|
42 | + ]; |
|
43 | + |
|
44 | + /** |
|
45 | + * @var array |
|
46 | + */ |
|
47 | + public $args = []; |
|
48 | + |
|
49 | + /** |
|
50 | + * @var bool |
|
51 | + */ |
|
52 | + public $render = false; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var string |
|
56 | + */ |
|
57 | + public $tag; |
|
58 | + |
|
59 | + /** |
|
60 | + * @param string $method |
|
61 | + * @param array $args |
|
62 | + * @return string|void |
|
63 | + */ |
|
64 | + public function __call($method, $args) |
|
65 | + { |
|
66 | + $instance = new static(); |
|
67 | + $instance->setTagFromMethod($method); |
|
68 | + call_user_func_array([$instance, 'normalize'], $args += ['', '']); |
|
69 | + $tags = array_merge(static::TAGS_FORM, static::TAGS_SINGLE, static::TAGS_STRUCTURE, static::TAGS_TEXT); |
|
70 | + do_action_ref_array('site-reviews/builder', [$instance]); |
|
71 | + $generatedTag = in_array($instance->tag, $tags) |
|
72 | + ? $instance->buildTag() |
|
73 | + : $instance->buildCustomField(); |
|
74 | + $generatedTag = apply_filters('site-reviews/builder/result', $generatedTag, $instance); |
|
75 | + if (!$this->render) { |
|
76 | + return $generatedTag; |
|
77 | + } |
|
78 | + echo $generatedTag; |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * @param string $property |
|
83 | + * @param mixed $value |
|
84 | + * @return void |
|
85 | + */ |
|
86 | + public function __set($property, $value) |
|
87 | + { |
|
88 | + $properties = [ |
|
89 | + 'args' => 'is_array', |
|
90 | + 'render' => 'is_bool', |
|
91 | + 'tag' => 'is_string', |
|
92 | + ]; |
|
93 | + if (!isset($properties[$property]) |
|
94 | + || empty(array_filter([$value], $properties[$property])) |
|
95 | + ) { |
|
96 | + return; |
|
97 | + } |
|
98 | + $this->$property = $value; |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * @return void|string |
|
103 | + */ |
|
104 | + public function getClosingTag() |
|
105 | + { |
|
106 | + if (empty($this->tag)) { |
|
107 | + return; |
|
108 | + } |
|
109 | + return '</'.$this->tag.'>'; |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * @return void|string |
|
114 | + */ |
|
115 | + public function getOpeningTag() |
|
116 | + { |
|
117 | + if (empty($this->tag)) { |
|
118 | + return; |
|
119 | + } |
|
120 | + $attributes = glsr(Attributes::class)->{$this->tag}($this->args)->toString(); |
|
121 | + return '<'.trim($this->tag.' '.$attributes).'>'; |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * @return void|string |
|
126 | + */ |
|
127 | + public function getTag() |
|
128 | + { |
|
129 | + if (in_array($this->tag, static::TAGS_SINGLE)) { |
|
130 | + return $this->getOpeningTag(); |
|
131 | + } |
|
132 | + if (!in_array($this->tag, static::TAGS_FORM)) { |
|
133 | + return $this->buildDefaultTag(); |
|
134 | + } |
|
135 | + return call_user_func([$this, 'buildForm'.ucfirst($this->tag)]).$this->buildFieldDescription(); |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * @return string |
|
140 | + */ |
|
141 | + public function raw(array $field) |
|
142 | + { |
|
143 | + unset($field['label']); |
|
144 | + return $this->{$field['type']}($field); |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * @return string|void |
|
149 | + */ |
|
150 | + protected function buildCustomField() |
|
151 | + { |
|
152 | + $className = $this->getCustomFieldClassName(); |
|
153 | + if (class_exists($className)) { |
|
154 | + return (new $className($this))->build(); |
|
155 | + } |
|
156 | + glsr_log()->error('Field missing: '.$className); |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * @return string|void |
|
161 | + */ |
|
162 | + protected function buildDefaultTag($text = '') |
|
163 | + { |
|
164 | + if (empty($text)) { |
|
165 | + $text = $this->args['text']; |
|
166 | + } |
|
167 | + return $this->getOpeningTag().$text.$this->getClosingTag(); |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * @return string|void |
|
172 | + */ |
|
173 | + protected function buildFieldDescription() |
|
174 | + { |
|
175 | + if (empty($this->args['description'])) { |
|
176 | + return; |
|
177 | + } |
|
178 | + if ($this->args['is_widget']) { |
|
179 | + return $this->small($this->args['description']); |
|
180 | + } |
|
181 | + return $this->p($this->args['description'], ['class' => 'description']); |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * @return string|void |
|
186 | + */ |
|
187 | + protected function buildFormInput() |
|
188 | + { |
|
189 | + if (!in_array($this->args['type'], ['checkbox', 'radio'])) { |
|
190 | + if (isset($this->args['multiple'])) { |
|
191 | + $this->args['name'].= '[]'; |
|
192 | + } |
|
193 | + return $this->buildFormLabel().$this->getOpeningTag(); |
|
194 | + } |
|
195 | + return empty($this->args['options']) |
|
196 | + ? $this->buildFormInputChoice() |
|
197 | + : $this->buildFormInputMultiChoice(); |
|
198 | + } |
|
199 | + |
|
200 | + /** |
|
201 | + * @return string|void |
|
202 | + */ |
|
203 | + protected function buildFormInputChoice() |
|
204 | + { |
|
205 | + if (!empty($this->args['text'])) { |
|
206 | + $this->args['label'] = $this->args['text']; |
|
207 | + } |
|
208 | + if (!$this->args['is_public']) { |
|
209 | + return $this->buildFormLabel([ |
|
210 | + 'class' => 'glsr-'.$this->args['type'].'-label', |
|
211 | + 'text' => $this->getOpeningTag().' '.$this->args['label'].'<span></span>', |
|
212 | + ]); |
|
213 | + } |
|
214 | + return $this->getOpeningTag().$this->buildFormLabel([ |
|
215 | + 'class' => 'glsr-'.$this->args['type'].'-label', |
|
216 | + 'text' => $this->args['label'].'<span></span>', |
|
217 | + ]); |
|
218 | + } |
|
219 | + |
|
220 | + /** |
|
221 | + * @return string|void |
|
222 | + */ |
|
223 | + protected function buildFormInputMultiChoice() |
|
224 | + { |
|
225 | + if ('checkbox' == $this->args['type']) { |
|
226 | + $this->args['name'].= '[]'; |
|
227 | + } |
|
228 | + $index = 0; |
|
229 | + $options = array_reduce(array_keys($this->args['options']), function ($carry, $key) use (&$index) { |
|
230 | + return $carry.$this->li($this->{$this->args['type']}([ |
|
231 | + 'checked' => in_array($key, (array) $this->args['value']), |
|
232 | + 'id' => $this->args['id'].'-'.$index++, |
|
233 | + 'name' => $this->args['name'], |
|
234 | + 'text' => $this->args['options'][$key], |
|
235 | + 'value' => $key, |
|
236 | + ])); |
|
237 | + }); |
|
238 | + return $this->ul($options, [ |
|
239 | + 'class' => $this->args['class'], |
|
240 | + 'id' => $this->args['id'], |
|
241 | + ]); |
|
242 | + } |
|
243 | + |
|
244 | + /** |
|
245 | + * @return void|string |
|
246 | + */ |
|
247 | + protected function buildFormLabel(array $customArgs = []) |
|
248 | + { |
|
249 | + if (empty($this->args['label']) || 'hidden' == $this->args['type']) { |
|
250 | + return; |
|
251 | + } |
|
252 | + return $this->label(wp_parse_args($customArgs, [ |
|
253 | + 'for' => $this->args['id'], |
|
254 | + 'is_public' => $this->args['is_public'], |
|
255 | + 'text' => $this->args['label'], |
|
256 | + 'type' => $this->args['type'], |
|
257 | + ])); |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * @return string|void |
|
262 | + */ |
|
263 | + protected function buildFormSelect() |
|
264 | + { |
|
265 | + return $this->buildFormLabel().$this->buildDefaultTag($this->buildFormSelectOptions()); |
|
266 | + } |
|
267 | + |
|
268 | + /** |
|
269 | + * @return string|void |
|
270 | + */ |
|
271 | + protected function buildFormSelectOptions() |
|
272 | + { |
|
273 | + return array_reduce(array_keys($this->args['options']), function ($carry, $key) { |
|
274 | + return $carry.$this->option([ |
|
275 | + 'selected' => $this->args['value'] == $key, |
|
276 | + 'text' => $this->args['options'][$key], |
|
277 | + 'value' => $key, |
|
278 | + ]); |
|
279 | + }); |
|
280 | + } |
|
281 | + |
|
282 | + /** |
|
283 | + * @return string|void |
|
284 | + */ |
|
285 | + protected function buildFormTextarea() |
|
286 | + { |
|
287 | + return $this->buildFormLabel().$this->buildDefaultTag($this->args['value']); |
|
288 | + } |
|
289 | + |
|
290 | + /** |
|
291 | + * @return string|void |
|
292 | + */ |
|
293 | + protected function buildTag() |
|
294 | + { |
|
295 | + $this->mergeArgsWithRequiredDefaults(); |
|
296 | + return $this->getTag(); |
|
297 | + } |
|
298 | + |
|
299 | + /** |
|
300 | + * @return string |
|
301 | + */ |
|
302 | + protected function getCustomFieldClassName() |
|
303 | + { |
|
304 | + $classname = Helper::buildClassName($this->tag, __NAMESPACE__.'\Fields'); |
|
305 | + return apply_filters('site-reviews/builder/field/'.$this->tag, $classname); |
|
306 | + } |
|
307 | + |
|
308 | + /** |
|
309 | + * @return void |
|
310 | + */ |
|
311 | + protected function mergeArgsWithRequiredDefaults() |
|
312 | + { |
|
313 | + $className = $this->getCustomFieldClassName(); |
|
314 | + if (class_exists($className)) { |
|
315 | + $this->args = $className::merge($this->args); |
|
316 | + } |
|
317 | + $this->args = glsr(BuilderDefaults::class)->merge($this->args); |
|
318 | + } |
|
319 | + |
|
320 | + /** |
|
321 | + * @param string|array ...$params |
|
322 | + * @return void |
|
323 | + */ |
|
324 | + protected function normalize(...$params) |
|
325 | + { |
|
326 | + if (is_string($params[0]) || is_numeric($params[0])) { |
|
327 | + $this->setNameOrTextAttributeForTag($params[0]); |
|
328 | + } |
|
329 | + if (is_array($params[0])) { |
|
330 | + $this->args += $params[0]; |
|
331 | + } elseif (is_array($params[1])) { |
|
332 | + $this->args += $params[1]; |
|
333 | + } |
|
334 | + if (!isset($this->args['is_public'])) { |
|
335 | + $this->args['is_public'] = false; |
|
336 | + } |
|
337 | + } |
|
338 | + |
|
339 | + /** |
|
340 | + * @param string $value |
|
341 | + * @return void |
|
342 | + */ |
|
343 | + protected function setNameOrTextAttributeForTag($value) |
|
344 | + { |
|
345 | + $attribute = in_array($this->tag, static::TAGS_FORM) |
|
346 | + ? 'name' |
|
347 | + : 'text'; |
|
348 | + $this->args[$attribute] = $value; |
|
349 | + } |
|
350 | + |
|
351 | + /** |
|
352 | + * @param string $method |
|
353 | + * @return void |
|
354 | + */ |
|
355 | + protected function setTagFromMethod($method) |
|
356 | + { |
|
357 | + $this->tag = strtolower($method); |
|
358 | + if (in_array($this->tag, static::INPUT_TYPES)) { |
|
359 | + $this->args['type'] = $this->tag; |
|
360 | + $this->tag = 'input'; |
|
361 | + } |
|
362 | + } |
|
363 | 363 | } |
@@ -61,18 +61,18 @@ discard block |
||
61 | 61 | * @param array $args |
62 | 62 | * @return string|void |
63 | 63 | */ |
64 | - public function __call($method, $args) |
|
64 | + public function __call( $method, $args ) |
|
65 | 65 | { |
66 | 66 | $instance = new static(); |
67 | - $instance->setTagFromMethod($method); |
|
68 | - call_user_func_array([$instance, 'normalize'], $args += ['', '']); |
|
69 | - $tags = array_merge(static::TAGS_FORM, static::TAGS_SINGLE, static::TAGS_STRUCTURE, static::TAGS_TEXT); |
|
70 | - do_action_ref_array('site-reviews/builder', [$instance]); |
|
71 | - $generatedTag = in_array($instance->tag, $tags) |
|
67 | + $instance->setTagFromMethod( $method ); |
|
68 | + call_user_func_array( [$instance, 'normalize'], $args += ['', ''] ); |
|
69 | + $tags = array_merge( static::TAGS_FORM, static::TAGS_SINGLE, static::TAGS_STRUCTURE, static::TAGS_TEXT ); |
|
70 | + do_action_ref_array( 'site-reviews/builder', [$instance] ); |
|
71 | + $generatedTag = in_array( $instance->tag, $tags ) |
|
72 | 72 | ? $instance->buildTag() |
73 | 73 | : $instance->buildCustomField(); |
74 | - $generatedTag = apply_filters('site-reviews/builder/result', $generatedTag, $instance); |
|
75 | - if (!$this->render) { |
|
74 | + $generatedTag = apply_filters( 'site-reviews/builder/result', $generatedTag, $instance ); |
|
75 | + if( !$this->render ) { |
|
76 | 76 | return $generatedTag; |
77 | 77 | } |
78 | 78 | echo $generatedTag; |
@@ -83,15 +83,15 @@ discard block |
||
83 | 83 | * @param mixed $value |
84 | 84 | * @return void |
85 | 85 | */ |
86 | - public function __set($property, $value) |
|
86 | + public function __set( $property, $value ) |
|
87 | 87 | { |
88 | 88 | $properties = [ |
89 | 89 | 'args' => 'is_array', |
90 | 90 | 'render' => 'is_bool', |
91 | 91 | 'tag' => 'is_string', |
92 | 92 | ]; |
93 | - if (!isset($properties[$property]) |
|
94 | - || empty(array_filter([$value], $properties[$property])) |
|
93 | + if( !isset($properties[$property]) |
|
94 | + || empty(array_filter( [$value], $properties[$property] )) |
|
95 | 95 | ) { |
96 | 96 | return; |
97 | 97 | } |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | */ |
104 | 104 | public function getClosingTag() |
105 | 105 | { |
106 | - if (empty($this->tag)) { |
|
106 | + if( empty($this->tag) ) { |
|
107 | 107 | return; |
108 | 108 | } |
109 | 109 | return '</'.$this->tag.'>'; |
@@ -114,11 +114,11 @@ discard block |
||
114 | 114 | */ |
115 | 115 | public function getOpeningTag() |
116 | 116 | { |
117 | - if (empty($this->tag)) { |
|
117 | + if( empty($this->tag) ) { |
|
118 | 118 | return; |
119 | 119 | } |
120 | - $attributes = glsr(Attributes::class)->{$this->tag}($this->args)->toString(); |
|
121 | - return '<'.trim($this->tag.' '.$attributes).'>'; |
|
120 | + $attributes = glsr( Attributes::class )->{$this->tag}($this->args)->toString(); |
|
121 | + return '<'.trim( $this->tag.' '.$attributes ).'>'; |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
@@ -126,19 +126,19 @@ discard block |
||
126 | 126 | */ |
127 | 127 | public function getTag() |
128 | 128 | { |
129 | - if (in_array($this->tag, static::TAGS_SINGLE)) { |
|
129 | + if( in_array( $this->tag, static::TAGS_SINGLE ) ) { |
|
130 | 130 | return $this->getOpeningTag(); |
131 | 131 | } |
132 | - if (!in_array($this->tag, static::TAGS_FORM)) { |
|
132 | + if( !in_array( $this->tag, static::TAGS_FORM ) ) { |
|
133 | 133 | return $this->buildDefaultTag(); |
134 | 134 | } |
135 | - return call_user_func([$this, 'buildForm'.ucfirst($this->tag)]).$this->buildFieldDescription(); |
|
135 | + return call_user_func( [$this, 'buildForm'.ucfirst( $this->tag )] ).$this->buildFieldDescription(); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
139 | 139 | * @return string |
140 | 140 | */ |
141 | - public function raw(array $field) |
|
141 | + public function raw( array $field ) |
|
142 | 142 | { |
143 | 143 | unset($field['label']); |
144 | 144 | return $this->{$field['type']}($field); |
@@ -150,18 +150,18 @@ discard block |
||
150 | 150 | protected function buildCustomField() |
151 | 151 | { |
152 | 152 | $className = $this->getCustomFieldClassName(); |
153 | - if (class_exists($className)) { |
|
154 | - return (new $className($this))->build(); |
|
153 | + if( class_exists( $className ) ) { |
|
154 | + return (new $className( $this ))->build(); |
|
155 | 155 | } |
156 | - glsr_log()->error('Field missing: '.$className); |
|
156 | + glsr_log()->error( 'Field missing: '.$className ); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
160 | 160 | * @return string|void |
161 | 161 | */ |
162 | - protected function buildDefaultTag($text = '') |
|
162 | + protected function buildDefaultTag( $text = '' ) |
|
163 | 163 | { |
164 | - if (empty($text)) { |
|
164 | + if( empty($text) ) { |
|
165 | 165 | $text = $this->args['text']; |
166 | 166 | } |
167 | 167 | return $this->getOpeningTag().$text.$this->getClosingTag(); |
@@ -172,13 +172,13 @@ discard block |
||
172 | 172 | */ |
173 | 173 | protected function buildFieldDescription() |
174 | 174 | { |
175 | - if (empty($this->args['description'])) { |
|
175 | + if( empty($this->args['description']) ) { |
|
176 | 176 | return; |
177 | 177 | } |
178 | - if ($this->args['is_widget']) { |
|
179 | - return $this->small($this->args['description']); |
|
178 | + if( $this->args['is_widget'] ) { |
|
179 | + return $this->small( $this->args['description'] ); |
|
180 | 180 | } |
181 | - return $this->p($this->args['description'], ['class' => 'description']); |
|
181 | + return $this->p( $this->args['description'], ['class' => 'description'] ); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
@@ -186,9 +186,9 @@ discard block |
||
186 | 186 | */ |
187 | 187 | protected function buildFormInput() |
188 | 188 | { |
189 | - if (!in_array($this->args['type'], ['checkbox', 'radio'])) { |
|
190 | - if (isset($this->args['multiple'])) { |
|
191 | - $this->args['name'].= '[]'; |
|
189 | + if( !in_array( $this->args['type'], ['checkbox', 'radio'] ) ) { |
|
190 | + if( isset($this->args['multiple']) ) { |
|
191 | + $this->args['name'] .= '[]'; |
|
192 | 192 | } |
193 | 193 | return $this->buildFormLabel().$this->getOpeningTag(); |
194 | 194 | } |
@@ -202,19 +202,19 @@ discard block |
||
202 | 202 | */ |
203 | 203 | protected function buildFormInputChoice() |
204 | 204 | { |
205 | - if (!empty($this->args['text'])) { |
|
205 | + if( !empty($this->args['text']) ) { |
|
206 | 206 | $this->args['label'] = $this->args['text']; |
207 | 207 | } |
208 | - if (!$this->args['is_public']) { |
|
209 | - return $this->buildFormLabel([ |
|
208 | + if( !$this->args['is_public'] ) { |
|
209 | + return $this->buildFormLabel( [ |
|
210 | 210 | 'class' => 'glsr-'.$this->args['type'].'-label', |
211 | 211 | 'text' => $this->getOpeningTag().' '.$this->args['label'].'<span></span>', |
212 | - ]); |
|
212 | + ] ); |
|
213 | 213 | } |
214 | - return $this->getOpeningTag().$this->buildFormLabel([ |
|
214 | + return $this->getOpeningTag().$this->buildFormLabel( [ |
|
215 | 215 | 'class' => 'glsr-'.$this->args['type'].'-label', |
216 | 216 | 'text' => $this->args['label'].'<span></span>', |
217 | - ]); |
|
217 | + ] ); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | /** |
@@ -222,39 +222,39 @@ discard block |
||
222 | 222 | */ |
223 | 223 | protected function buildFormInputMultiChoice() |
224 | 224 | { |
225 | - if ('checkbox' == $this->args['type']) { |
|
226 | - $this->args['name'].= '[]'; |
|
225 | + if( 'checkbox' == $this->args['type'] ) { |
|
226 | + $this->args['name'] .= '[]'; |
|
227 | 227 | } |
228 | 228 | $index = 0; |
229 | - $options = array_reduce(array_keys($this->args['options']), function ($carry, $key) use (&$index) { |
|
230 | - return $carry.$this->li($this->{$this->args['type']}([ |
|
231 | - 'checked' => in_array($key, (array) $this->args['value']), |
|
229 | + $options = array_reduce( array_keys( $this->args['options'] ), function( $carry, $key ) use (&$index) { |
|
230 | + return $carry.$this->li( $this->{$this->args['type']}([ |
|
231 | + 'checked' => in_array( $key, (array)$this->args['value'] ), |
|
232 | 232 | 'id' => $this->args['id'].'-'.$index++, |
233 | 233 | 'name' => $this->args['name'], |
234 | 234 | 'text' => $this->args['options'][$key], |
235 | 235 | 'value' => $key, |
236 | - ])); |
|
236 | + ]) ); |
|
237 | 237 | }); |
238 | - return $this->ul($options, [ |
|
238 | + return $this->ul( $options, [ |
|
239 | 239 | 'class' => $this->args['class'], |
240 | 240 | 'id' => $this->args['id'], |
241 | - ]); |
|
241 | + ] ); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | /** |
245 | 245 | * @return void|string |
246 | 246 | */ |
247 | - protected function buildFormLabel(array $customArgs = []) |
|
247 | + protected function buildFormLabel( array $customArgs = [] ) |
|
248 | 248 | { |
249 | - if (empty($this->args['label']) || 'hidden' == $this->args['type']) { |
|
249 | + if( empty($this->args['label']) || 'hidden' == $this->args['type'] ) { |
|
250 | 250 | return; |
251 | 251 | } |
252 | - return $this->label(wp_parse_args($customArgs, [ |
|
252 | + return $this->label( wp_parse_args( $customArgs, [ |
|
253 | 253 | 'for' => $this->args['id'], |
254 | 254 | 'is_public' => $this->args['is_public'], |
255 | 255 | 'text' => $this->args['label'], |
256 | 256 | 'type' => $this->args['type'], |
257 | - ])); |
|
257 | + ] ) ); |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | /** |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | */ |
263 | 263 | protected function buildFormSelect() |
264 | 264 | { |
265 | - return $this->buildFormLabel().$this->buildDefaultTag($this->buildFormSelectOptions()); |
|
265 | + return $this->buildFormLabel().$this->buildDefaultTag( $this->buildFormSelectOptions() ); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | /** |
@@ -270,12 +270,12 @@ discard block |
||
270 | 270 | */ |
271 | 271 | protected function buildFormSelectOptions() |
272 | 272 | { |
273 | - return array_reduce(array_keys($this->args['options']), function ($carry, $key) { |
|
274 | - return $carry.$this->option([ |
|
273 | + return array_reduce( array_keys( $this->args['options'] ), function( $carry, $key ) { |
|
274 | + return $carry.$this->option( [ |
|
275 | 275 | 'selected' => $this->args['value'] == $key, |
276 | 276 | 'text' => $this->args['options'][$key], |
277 | 277 | 'value' => $key, |
278 | - ]); |
|
278 | + ] ); |
|
279 | 279 | }); |
280 | 280 | } |
281 | 281 | |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | */ |
285 | 285 | protected function buildFormTextarea() |
286 | 286 | { |
287 | - return $this->buildFormLabel().$this->buildDefaultTag($this->args['value']); |
|
287 | + return $this->buildFormLabel().$this->buildDefaultTag( $this->args['value'] ); |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | /** |
@@ -301,8 +301,8 @@ discard block |
||
301 | 301 | */ |
302 | 302 | protected function getCustomFieldClassName() |
303 | 303 | { |
304 | - $classname = Helper::buildClassName($this->tag, __NAMESPACE__.'\Fields'); |
|
305 | - return apply_filters('site-reviews/builder/field/'.$this->tag, $classname); |
|
304 | + $classname = Helper::buildClassName( $this->tag, __NAMESPACE__.'\Fields' ); |
|
305 | + return apply_filters( 'site-reviews/builder/field/'.$this->tag, $classname ); |
|
306 | 306 | } |
307 | 307 | |
308 | 308 | /** |
@@ -311,27 +311,27 @@ discard block |
||
311 | 311 | protected function mergeArgsWithRequiredDefaults() |
312 | 312 | { |
313 | 313 | $className = $this->getCustomFieldClassName(); |
314 | - if (class_exists($className)) { |
|
315 | - $this->args = $className::merge($this->args); |
|
314 | + if( class_exists( $className ) ) { |
|
315 | + $this->args = $className::merge( $this->args ); |
|
316 | 316 | } |
317 | - $this->args = glsr(BuilderDefaults::class)->merge($this->args); |
|
317 | + $this->args = glsr( BuilderDefaults::class )->merge( $this->args ); |
|
318 | 318 | } |
319 | 319 | |
320 | 320 | /** |
321 | 321 | * @param string|array ...$params |
322 | 322 | * @return void |
323 | 323 | */ |
324 | - protected function normalize(...$params) |
|
324 | + protected function normalize( ...$params ) |
|
325 | 325 | { |
326 | - if (is_string($params[0]) || is_numeric($params[0])) { |
|
327 | - $this->setNameOrTextAttributeForTag($params[0]); |
|
326 | + if( is_string( $params[0] ) || is_numeric( $params[0] ) ) { |
|
327 | + $this->setNameOrTextAttributeForTag( $params[0] ); |
|
328 | 328 | } |
329 | - if (is_array($params[0])) { |
|
329 | + if( is_array( $params[0] ) ) { |
|
330 | 330 | $this->args += $params[0]; |
331 | - } elseif (is_array($params[1])) { |
|
331 | + } elseif( is_array( $params[1] ) ) { |
|
332 | 332 | $this->args += $params[1]; |
333 | 333 | } |
334 | - if (!isset($this->args['is_public'])) { |
|
334 | + if( !isset($this->args['is_public']) ) { |
|
335 | 335 | $this->args['is_public'] = false; |
336 | 336 | } |
337 | 337 | } |
@@ -340,9 +340,9 @@ discard block |
||
340 | 340 | * @param string $value |
341 | 341 | * @return void |
342 | 342 | */ |
343 | - protected function setNameOrTextAttributeForTag($value) |
|
343 | + protected function setNameOrTextAttributeForTag( $value ) |
|
344 | 344 | { |
345 | - $attribute = in_array($this->tag, static::TAGS_FORM) |
|
345 | + $attribute = in_array( $this->tag, static::TAGS_FORM ) |
|
346 | 346 | ? 'name' |
347 | 347 | : 'text'; |
348 | 348 | $this->args[$attribute] = $value; |
@@ -352,10 +352,10 @@ discard block |
||
352 | 352 | * @param string $method |
353 | 353 | * @return void |
354 | 354 | */ |
355 | - protected function setTagFromMethod($method) |
|
355 | + protected function setTagFromMethod( $method ) |
|
356 | 356 | { |
357 | - $this->tag = strtolower($method); |
|
358 | - if (in_array($this->tag, static::INPUT_TYPES)) { |
|
357 | + $this->tag = strtolower( $method ); |
|
358 | + if( in_array( $this->tag, static::INPUT_TYPES ) ) { |
|
359 | 359 | $this->args['type'] = $this->tag; |
360 | 360 | $this->tag = 'input'; |
361 | 361 | } |
@@ -4,13 +4,13 @@ |
||
4 | 4 | |
5 | 5 | class Hidden extends Field |
6 | 6 | { |
7 | - /** |
|
8 | - * @return array |
|
9 | - */ |
|
10 | - public static function required() |
|
11 | - { |
|
12 | - return [ |
|
13 | - 'is_raw' => true, |
|
14 | - ]; |
|
15 | - } |
|
7 | + /** |
|
8 | + * @return array |
|
9 | + */ |
|
10 | + public static function required() |
|
11 | + { |
|
12 | + return [ |
|
13 | + 'is_raw' => true, |
|
14 | + ]; |
|
15 | + } |
|
16 | 16 | } |