@@ -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 | ]); |
@@ -8,164 +8,164 @@ |
||
8 | 8 | |
9 | 9 | class Notification |
10 | 10 | { |
11 | - /** |
|
12 | - * @var bool |
|
13 | - */ |
|
14 | - protected $email; |
|
11 | + /** |
|
12 | + * @var bool |
|
13 | + */ |
|
14 | + protected $email; |
|
15 | 15 | |
16 | - /** |
|
17 | - * @var Review |
|
18 | - */ |
|
19 | - protected $review; |
|
16 | + /** |
|
17 | + * @var Review |
|
18 | + */ |
|
19 | + protected $review; |
|
20 | 20 | |
21 | - /** |
|
22 | - * @var bool |
|
23 | - */ |
|
24 | - protected $slack; |
|
21 | + /** |
|
22 | + * @var bool |
|
23 | + */ |
|
24 | + protected $slack; |
|
25 | 25 | |
26 | - /** |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - protected $types; |
|
26 | + /** |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + protected $types; |
|
30 | 30 | |
31 | - public function __construct() |
|
32 | - { |
|
33 | - $types = glsr(OptionManager::class)->get('settings.general.notifications', []); |
|
34 | - $this->email = count(array_intersect(['admin', 'custom'], $types)) > 0; |
|
35 | - $this->slack = in_array('slack', $types); |
|
36 | - $this->types = $types; |
|
37 | - } |
|
31 | + public function __construct() |
|
32 | + { |
|
33 | + $types = glsr(OptionManager::class)->get('settings.general.notifications', []); |
|
34 | + $this->email = count(array_intersect(['admin', 'custom'], $types)) > 0; |
|
35 | + $this->slack = in_array('slack', $types); |
|
36 | + $this->types = $types; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * @return void |
|
41 | - */ |
|
42 | - public function send(Review $review) |
|
43 | - { |
|
44 | - if (empty($this->types)) { |
|
45 | - return; |
|
46 | - } |
|
47 | - $this->review = $review; |
|
48 | - $args = [ |
|
49 | - 'link' => $this->getLink(), |
|
50 | - 'title' => $this->getTitle(), |
|
51 | - ]; |
|
52 | - $this->sendToEmail($args); |
|
53 | - $this->sendToSlack($args); |
|
54 | - } |
|
39 | + /** |
|
40 | + * @return void |
|
41 | + */ |
|
42 | + public function send(Review $review) |
|
43 | + { |
|
44 | + if (empty($this->types)) { |
|
45 | + return; |
|
46 | + } |
|
47 | + $this->review = $review; |
|
48 | + $args = [ |
|
49 | + 'link' => $this->getLink(), |
|
50 | + 'title' => $this->getTitle(), |
|
51 | + ]; |
|
52 | + $this->sendToEmail($args); |
|
53 | + $this->sendToSlack($args); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * @return Email |
|
58 | - */ |
|
59 | - protected function buildEmail(array $args) |
|
60 | - { |
|
61 | - return glsr(Email::class)->compose([ |
|
62 | - 'to' => $this->getEmailAddresses(), |
|
63 | - 'subject' => $args['title'], |
|
64 | - 'template' => 'email-notification', |
|
65 | - 'template-tags' => [ |
|
66 | - 'review_author' => $this->review->author ?: __('Anonymous', 'site-reviews'), |
|
67 | - 'review_content' => $this->review->content, |
|
68 | - 'review_email' => $this->review->email, |
|
69 | - 'review_ip' => $this->review->ip_address, |
|
70 | - 'review_link' => sprintf('<a href="%1$s">%1$s</a>', $args['link']), |
|
71 | - 'review_rating' => $this->review->rating, |
|
72 | - 'review_title' => $this->review->title, |
|
73 | - ], |
|
74 | - ]); |
|
75 | - } |
|
56 | + /** |
|
57 | + * @return Email |
|
58 | + */ |
|
59 | + protected function buildEmail(array $args) |
|
60 | + { |
|
61 | + return glsr(Email::class)->compose([ |
|
62 | + 'to' => $this->getEmailAddresses(), |
|
63 | + 'subject' => $args['title'], |
|
64 | + 'template' => 'email-notification', |
|
65 | + 'template-tags' => [ |
|
66 | + 'review_author' => $this->review->author ?: __('Anonymous', 'site-reviews'), |
|
67 | + 'review_content' => $this->review->content, |
|
68 | + 'review_email' => $this->review->email, |
|
69 | + 'review_ip' => $this->review->ip_address, |
|
70 | + 'review_link' => sprintf('<a href="%1$s">%1$s</a>', $args['link']), |
|
71 | + 'review_rating' => $this->review->rating, |
|
72 | + 'review_title' => $this->review->title, |
|
73 | + ], |
|
74 | + ]); |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * @return Slack |
|
79 | - */ |
|
80 | - protected function buildSlackNotification(array $args) |
|
81 | - { |
|
82 | - return glsr(Slack::class)->compose($this->review, [ |
|
83 | - 'button_url' => $args['link'], |
|
84 | - 'fallback' => $this->buildEmail($args)->read('plaintext'), |
|
85 | - 'pretext' => $args['title'], |
|
86 | - ]); |
|
87 | - } |
|
77 | + /** |
|
78 | + * @return Slack |
|
79 | + */ |
|
80 | + protected function buildSlackNotification(array $args) |
|
81 | + { |
|
82 | + return glsr(Slack::class)->compose($this->review, [ |
|
83 | + 'button_url' => $args['link'], |
|
84 | + 'fallback' => $this->buildEmail($args)->read('plaintext'), |
|
85 | + 'pretext' => $args['title'], |
|
86 | + ]); |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * @return array |
|
91 | - */ |
|
92 | - protected function getEmailAddresses() |
|
93 | - { |
|
94 | - $emails = []; |
|
95 | - if (in_array('admin', $this->types)) { |
|
96 | - $emails[] = get_option('admin_email'); |
|
97 | - } |
|
98 | - if (in_array('author', $this->types)) { |
|
99 | - $assignedPost = get_post(intval($this->review->assigned_to)); |
|
100 | - if ($assignedPost instanceof WP_Post) { |
|
101 | - $this->email = true; |
|
102 | - $emails[] = get_the_author_meta('user_email', intval($assignedPost->post_author)); |
|
103 | - } |
|
104 | - } |
|
105 | - if (in_array('custom', $this->types)) { |
|
106 | - $customEmails = glsr(OptionManager::class)->get('settings.general.notification_email'); |
|
107 | - $customEmails = str_replace([' ', ',', ';'], ',', $customEmails); |
|
108 | - $customEmails = explode(',', $customEmails); |
|
109 | - $emails = array_merge($emails, $customEmails); |
|
110 | - } |
|
111 | - $emails = array_filter(array_keys(array_flip($emails))); |
|
112 | - return apply_filters('site-reviews/notification/emails', $emails, $this->review); |
|
113 | - } |
|
89 | + /** |
|
90 | + * @return array |
|
91 | + */ |
|
92 | + protected function getEmailAddresses() |
|
93 | + { |
|
94 | + $emails = []; |
|
95 | + if (in_array('admin', $this->types)) { |
|
96 | + $emails[] = get_option('admin_email'); |
|
97 | + } |
|
98 | + if (in_array('author', $this->types)) { |
|
99 | + $assignedPost = get_post(intval($this->review->assigned_to)); |
|
100 | + if ($assignedPost instanceof WP_Post) { |
|
101 | + $this->email = true; |
|
102 | + $emails[] = get_the_author_meta('user_email', intval($assignedPost->post_author)); |
|
103 | + } |
|
104 | + } |
|
105 | + if (in_array('custom', $this->types)) { |
|
106 | + $customEmails = glsr(OptionManager::class)->get('settings.general.notification_email'); |
|
107 | + $customEmails = str_replace([' ', ',', ';'], ',', $customEmails); |
|
108 | + $customEmails = explode(',', $customEmails); |
|
109 | + $emails = array_merge($emails, $customEmails); |
|
110 | + } |
|
111 | + $emails = array_filter(array_keys(array_flip($emails))); |
|
112 | + return apply_filters('site-reviews/notification/emails', $emails, $this->review); |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * @return string |
|
117 | - */ |
|
118 | - protected function getLink() |
|
119 | - { |
|
120 | - return admin_url('post.php?post='.$this->review->ID.'&action=edit'); |
|
121 | - } |
|
115 | + /** |
|
116 | + * @return string |
|
117 | + */ |
|
118 | + protected function getLink() |
|
119 | + { |
|
120 | + return admin_url('post.php?post='.$this->review->ID.'&action=edit'); |
|
121 | + } |
|
122 | 122 | |
123 | - /** |
|
124 | - * @return string |
|
125 | - */ |
|
126 | - protected function getTitle() |
|
127 | - { |
|
128 | - $assignedTitle = get_the_title(intval($this->review->assigned_to)); |
|
129 | - $title = _nx( |
|
130 | - 'New %s-star review', |
|
131 | - 'New %s-star review of: %s', |
|
132 | - intval(empty($assignedTitle)), |
|
133 | - 'This string differs depending on whether or not the review has been assigned to a post.', |
|
134 | - 'site-reviews' |
|
135 | - ); |
|
136 | - $title = sprintf('[%s] %s', |
|
137 | - wp_specialchars_decode(strval(get_option('blogname')), ENT_QUOTES), |
|
138 | - sprintf($title, $this->review->rating, $assignedTitle) |
|
139 | - ); |
|
140 | - return apply_filters('site-reviews/notification/title', $title, $this->review); |
|
141 | - } |
|
123 | + /** |
|
124 | + * @return string |
|
125 | + */ |
|
126 | + protected function getTitle() |
|
127 | + { |
|
128 | + $assignedTitle = get_the_title(intval($this->review->assigned_to)); |
|
129 | + $title = _nx( |
|
130 | + 'New %s-star review', |
|
131 | + 'New %s-star review of: %s', |
|
132 | + intval(empty($assignedTitle)), |
|
133 | + 'This string differs depending on whether or not the review has been assigned to a post.', |
|
134 | + 'site-reviews' |
|
135 | + ); |
|
136 | + $title = sprintf('[%s] %s', |
|
137 | + wp_specialchars_decode(strval(get_option('blogname')), ENT_QUOTES), |
|
138 | + sprintf($title, $this->review->rating, $assignedTitle) |
|
139 | + ); |
|
140 | + return apply_filters('site-reviews/notification/title', $title, $this->review); |
|
141 | + } |
|
142 | 142 | |
143 | - /** |
|
144 | - * @return void |
|
145 | - */ |
|
146 | - protected function sendToEmail(array $args) |
|
147 | - { |
|
148 | - $email = $this->buildEmail($args); |
|
149 | - if (empty($email->to)) { |
|
150 | - glsr_log()->error('Email notification was not sent (missing email address)'); |
|
151 | - return; |
|
152 | - } |
|
153 | - $email->send(); |
|
154 | - } |
|
143 | + /** |
|
144 | + * @return void |
|
145 | + */ |
|
146 | + protected function sendToEmail(array $args) |
|
147 | + { |
|
148 | + $email = $this->buildEmail($args); |
|
149 | + if (empty($email->to)) { |
|
150 | + glsr_log()->error('Email notification was not sent (missing email address)'); |
|
151 | + return; |
|
152 | + } |
|
153 | + $email->send(); |
|
154 | + } |
|
155 | 155 | |
156 | - /** |
|
157 | - * @return void |
|
158 | - */ |
|
159 | - protected function sendToSlack(array $args) |
|
160 | - { |
|
161 | - if (!$this->slack) { |
|
162 | - return; |
|
163 | - } |
|
164 | - $notification = $this->buildSlackNotification($args); |
|
165 | - $result = $notification->send(); |
|
166 | - if (is_wp_error($result)) { |
|
167 | - $notification->review = null; |
|
168 | - glsr_log()->error($result->get_error_message())->debug($notification); |
|
169 | - } |
|
170 | - } |
|
156 | + /** |
|
157 | + * @return void |
|
158 | + */ |
|
159 | + protected function sendToSlack(array $args) |
|
160 | + { |
|
161 | + if (!$this->slack) { |
|
162 | + return; |
|
163 | + } |
|
164 | + $notification = $this->buildSlackNotification($args); |
|
165 | + $result = $notification->send(); |
|
166 | + if (is_wp_error($result)) { |
|
167 | + $notification->review = null; |
|
168 | + glsr_log()->error($result->get_error_message())->debug($notification); |
|
169 | + } |
|
170 | + } |
|
171 | 171 | } |
@@ -30,18 +30,18 @@ discard block |
||
30 | 30 | |
31 | 31 | public function __construct() |
32 | 32 | { |
33 | - $types = glsr(OptionManager::class)->get('settings.general.notifications', []); |
|
34 | - $this->email = count(array_intersect(['admin', 'custom'], $types)) > 0; |
|
35 | - $this->slack = in_array('slack', $types); |
|
33 | + $types = glsr( OptionManager::class )->get( 'settings.general.notifications', [] ); |
|
34 | + $this->email = count( array_intersect( ['admin', 'custom'], $types ) ) > 0; |
|
35 | + $this->slack = in_array( 'slack', $types ); |
|
36 | 36 | $this->types = $types; |
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
40 | 40 | * @return void |
41 | 41 | */ |
42 | - public function send(Review $review) |
|
42 | + public function send( Review $review ) |
|
43 | 43 | { |
44 | - if (empty($this->types)) { |
|
44 | + if( empty($this->types) ) { |
|
45 | 45 | return; |
46 | 46 | } |
47 | 47 | $this->review = $review; |
@@ -49,41 +49,41 @@ discard block |
||
49 | 49 | 'link' => $this->getLink(), |
50 | 50 | 'title' => $this->getTitle(), |
51 | 51 | ]; |
52 | - $this->sendToEmail($args); |
|
53 | - $this->sendToSlack($args); |
|
52 | + $this->sendToEmail( $args ); |
|
53 | + $this->sendToSlack( $args ); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | /** |
57 | 57 | * @return Email |
58 | 58 | */ |
59 | - protected function buildEmail(array $args) |
|
59 | + protected function buildEmail( array $args ) |
|
60 | 60 | { |
61 | - return glsr(Email::class)->compose([ |
|
61 | + return glsr( Email::class )->compose( [ |
|
62 | 62 | 'to' => $this->getEmailAddresses(), |
63 | 63 | 'subject' => $args['title'], |
64 | 64 | 'template' => 'email-notification', |
65 | 65 | 'template-tags' => [ |
66 | - 'review_author' => $this->review->author ?: __('Anonymous', 'site-reviews'), |
|
66 | + 'review_author' => $this->review->author ?: __( 'Anonymous', 'site-reviews' ), |
|
67 | 67 | 'review_content' => $this->review->content, |
68 | 68 | 'review_email' => $this->review->email, |
69 | 69 | 'review_ip' => $this->review->ip_address, |
70 | - 'review_link' => sprintf('<a href="%1$s">%1$s</a>', $args['link']), |
|
70 | + 'review_link' => sprintf( '<a href="%1$s">%1$s</a>', $args['link'] ), |
|
71 | 71 | 'review_rating' => $this->review->rating, |
72 | 72 | 'review_title' => $this->review->title, |
73 | 73 | ], |
74 | - ]); |
|
74 | + ] ); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | /** |
78 | 78 | * @return Slack |
79 | 79 | */ |
80 | - protected function buildSlackNotification(array $args) |
|
80 | + protected function buildSlackNotification( array $args ) |
|
81 | 81 | { |
82 | - return glsr(Slack::class)->compose($this->review, [ |
|
82 | + return glsr( Slack::class )->compose( $this->review, [ |
|
83 | 83 | 'button_url' => $args['link'], |
84 | - 'fallback' => $this->buildEmail($args)->read('plaintext'), |
|
84 | + 'fallback' => $this->buildEmail( $args )->read( 'plaintext' ), |
|
85 | 85 | 'pretext' => $args['title'], |
86 | - ]); |
|
86 | + ] ); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -92,24 +92,24 @@ discard block |
||
92 | 92 | protected function getEmailAddresses() |
93 | 93 | { |
94 | 94 | $emails = []; |
95 | - if (in_array('admin', $this->types)) { |
|
96 | - $emails[] = get_option('admin_email'); |
|
95 | + if( in_array( 'admin', $this->types ) ) { |
|
96 | + $emails[] = get_option( 'admin_email' ); |
|
97 | 97 | } |
98 | - if (in_array('author', $this->types)) { |
|
99 | - $assignedPost = get_post(intval($this->review->assigned_to)); |
|
100 | - if ($assignedPost instanceof WP_Post) { |
|
98 | + if( in_array( 'author', $this->types ) ) { |
|
99 | + $assignedPost = get_post( intval( $this->review->assigned_to ) ); |
|
100 | + if( $assignedPost instanceof WP_Post ) { |
|
101 | 101 | $this->email = true; |
102 | - $emails[] = get_the_author_meta('user_email', intval($assignedPost->post_author)); |
|
102 | + $emails[] = get_the_author_meta( 'user_email', intval( $assignedPost->post_author ) ); |
|
103 | 103 | } |
104 | 104 | } |
105 | - if (in_array('custom', $this->types)) { |
|
106 | - $customEmails = glsr(OptionManager::class)->get('settings.general.notification_email'); |
|
107 | - $customEmails = str_replace([' ', ',', ';'], ',', $customEmails); |
|
108 | - $customEmails = explode(',', $customEmails); |
|
109 | - $emails = array_merge($emails, $customEmails); |
|
105 | + if( in_array( 'custom', $this->types ) ) { |
|
106 | + $customEmails = glsr( OptionManager::class )->get( 'settings.general.notification_email' ); |
|
107 | + $customEmails = str_replace( [' ', ',', ';'], ',', $customEmails ); |
|
108 | + $customEmails = explode( ',', $customEmails ); |
|
109 | + $emails = array_merge( $emails, $customEmails ); |
|
110 | 110 | } |
111 | - $emails = array_filter(array_keys(array_flip($emails))); |
|
112 | - return apply_filters('site-reviews/notification/emails', $emails, $this->review); |
|
111 | + $emails = array_filter( array_keys( array_flip( $emails ) ) ); |
|
112 | + return apply_filters( 'site-reviews/notification/emails', $emails, $this->review ); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | */ |
118 | 118 | protected function getLink() |
119 | 119 | { |
120 | - return admin_url('post.php?post='.$this->review->ID.'&action=edit'); |
|
120 | + return admin_url( 'post.php?post='.$this->review->ID.'&action=edit' ); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -125,29 +125,29 @@ discard block |
||
125 | 125 | */ |
126 | 126 | protected function getTitle() |
127 | 127 | { |
128 | - $assignedTitle = get_the_title(intval($this->review->assigned_to)); |
|
128 | + $assignedTitle = get_the_title( intval( $this->review->assigned_to ) ); |
|
129 | 129 | $title = _nx( |
130 | 130 | 'New %s-star review', |
131 | 131 | 'New %s-star review of: %s', |
132 | - intval(empty($assignedTitle)), |
|
132 | + intval( empty($assignedTitle) ), |
|
133 | 133 | 'This string differs depending on whether or not the review has been assigned to a post.', |
134 | 134 | 'site-reviews' |
135 | 135 | ); |
136 | - $title = sprintf('[%s] %s', |
|
137 | - wp_specialchars_decode(strval(get_option('blogname')), ENT_QUOTES), |
|
138 | - sprintf($title, $this->review->rating, $assignedTitle) |
|
136 | + $title = sprintf( '[%s] %s', |
|
137 | + wp_specialchars_decode( strval( get_option( 'blogname' ) ), ENT_QUOTES ), |
|
138 | + sprintf( $title, $this->review->rating, $assignedTitle ) |
|
139 | 139 | ); |
140 | - return apply_filters('site-reviews/notification/title', $title, $this->review); |
|
140 | + return apply_filters( 'site-reviews/notification/title', $title, $this->review ); |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | /** |
144 | 144 | * @return void |
145 | 145 | */ |
146 | - protected function sendToEmail(array $args) |
|
146 | + protected function sendToEmail( array $args ) |
|
147 | 147 | { |
148 | - $email = $this->buildEmail($args); |
|
149 | - if (empty($email->to)) { |
|
150 | - glsr_log()->error('Email notification was not sent (missing email address)'); |
|
148 | + $email = $this->buildEmail( $args ); |
|
149 | + if( empty($email->to) ) { |
|
150 | + glsr_log()->error( 'Email notification was not sent (missing email address)' ); |
|
151 | 151 | return; |
152 | 152 | } |
153 | 153 | $email->send(); |
@@ -156,16 +156,16 @@ discard block |
||
156 | 156 | /** |
157 | 157 | * @return void |
158 | 158 | */ |
159 | - protected function sendToSlack(array $args) |
|
159 | + protected function sendToSlack( array $args ) |
|
160 | 160 | { |
161 | - if (!$this->slack) { |
|
161 | + if( !$this->slack ) { |
|
162 | 162 | return; |
163 | 163 | } |
164 | - $notification = $this->buildSlackNotification($args); |
|
164 | + $notification = $this->buildSlackNotification( $args ); |
|
165 | 165 | $result = $notification->send(); |
166 | - if (is_wp_error($result)) { |
|
166 | + if( is_wp_error( $result ) ) { |
|
167 | 167 | $notification->review = null; |
168 | - glsr_log()->error($result->get_error_message())->debug($notification); |
|
168 | + glsr_log()->error( $result->get_error_message() )->debug( $notification ); |
|
169 | 169 | } |
170 | 170 | } |
171 | 171 | } |
@@ -10,368 +10,368 @@ |
||
10 | 10 | |
11 | 11 | class System |
12 | 12 | { |
13 | - const PAD = 40; |
|
13 | + const PAD = 40; |
|
14 | 14 | |
15 | - /** |
|
16 | - * @return string |
|
17 | - */ |
|
18 | - public function __toString() |
|
19 | - { |
|
20 | - return $this->get(); |
|
21 | - } |
|
15 | + /** |
|
16 | + * @return string |
|
17 | + */ |
|
18 | + public function __toString() |
|
19 | + { |
|
20 | + return $this->get(); |
|
21 | + } |
|
22 | 22 | |
23 | - /** |
|
24 | - * @return string |
|
25 | - */ |
|
26 | - public function get() |
|
27 | - { |
|
28 | - $details = [ |
|
29 | - 'plugin' => 'Plugin Details', |
|
30 | - 'addon' => 'Addon Details', |
|
31 | - 'browser' => 'Browser Details', |
|
32 | - 'server' => 'Server Details', |
|
33 | - 'php' => 'PHP Configuration', |
|
34 | - 'wordpress' => 'WordPress Configuration', |
|
35 | - 'mu-plugin' => 'Must-Use Plugins', |
|
36 | - 'multisite-plugin' => 'Network Active Plugins', |
|
37 | - 'active-plugin' => 'Active Plugins', |
|
38 | - 'inactive-plugin' => 'Inactive Plugins', |
|
39 | - 'setting' => 'Plugin Settings', |
|
40 | - 'reviews' => 'Review Counts', |
|
41 | - ]; |
|
42 | - $systemInfo = array_reduce(array_keys($details), function ($carry, $key) use ($details) { |
|
43 | - $methodName = glsr(Helper::class)->buildMethodName('get-'.$key.'-details'); |
|
44 | - if (method_exists($this, $methodName) && $systemDetails = $this->$methodName()) { |
|
45 | - return $carry.$this->implode( |
|
46 | - strtoupper($details[$key]), |
|
47 | - apply_filters('site-reviews/system/'.$key, $systemDetails) |
|
48 | - ); |
|
49 | - } |
|
50 | - return $carry; |
|
51 | - }); |
|
52 | - return trim($systemInfo); |
|
53 | - } |
|
23 | + /** |
|
24 | + * @return string |
|
25 | + */ |
|
26 | + public function get() |
|
27 | + { |
|
28 | + $details = [ |
|
29 | + 'plugin' => 'Plugin Details', |
|
30 | + 'addon' => 'Addon Details', |
|
31 | + 'browser' => 'Browser Details', |
|
32 | + 'server' => 'Server Details', |
|
33 | + 'php' => 'PHP Configuration', |
|
34 | + 'wordpress' => 'WordPress Configuration', |
|
35 | + 'mu-plugin' => 'Must-Use Plugins', |
|
36 | + 'multisite-plugin' => 'Network Active Plugins', |
|
37 | + 'active-plugin' => 'Active Plugins', |
|
38 | + 'inactive-plugin' => 'Inactive Plugins', |
|
39 | + 'setting' => 'Plugin Settings', |
|
40 | + 'reviews' => 'Review Counts', |
|
41 | + ]; |
|
42 | + $systemInfo = array_reduce(array_keys($details), function ($carry, $key) use ($details) { |
|
43 | + $methodName = glsr(Helper::class)->buildMethodName('get-'.$key.'-details'); |
|
44 | + if (method_exists($this, $methodName) && $systemDetails = $this->$methodName()) { |
|
45 | + return $carry.$this->implode( |
|
46 | + strtoupper($details[$key]), |
|
47 | + apply_filters('site-reviews/system/'.$key, $systemDetails) |
|
48 | + ); |
|
49 | + } |
|
50 | + return $carry; |
|
51 | + }); |
|
52 | + return trim($systemInfo); |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * @return array |
|
57 | - */ |
|
58 | - public function getActivePluginDetails() |
|
59 | - { |
|
60 | - $plugins = get_plugins(); |
|
61 | - $activePlugins = (array) get_option('active_plugins', []); |
|
62 | - $inactive = array_diff_key($plugins, array_flip($activePlugins)); |
|
63 | - return $this->normalizePluginList(array_diff_key($plugins, $inactive)); |
|
64 | - } |
|
55 | + /** |
|
56 | + * @return array |
|
57 | + */ |
|
58 | + public function getActivePluginDetails() |
|
59 | + { |
|
60 | + $plugins = get_plugins(); |
|
61 | + $activePlugins = (array) get_option('active_plugins', []); |
|
62 | + $inactive = array_diff_key($plugins, array_flip($activePlugins)); |
|
63 | + return $this->normalizePluginList(array_diff_key($plugins, $inactive)); |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @return array |
|
68 | - */ |
|
69 | - public function getAddonDetails() |
|
70 | - { |
|
71 | - $details = apply_filters('site-reviews/addon/system-info', []); |
|
72 | - ksort($details); |
|
73 | - return $details; |
|
74 | - } |
|
66 | + /** |
|
67 | + * @return array |
|
68 | + */ |
|
69 | + public function getAddonDetails() |
|
70 | + { |
|
71 | + $details = apply_filters('site-reviews/addon/system-info', []); |
|
72 | + ksort($details); |
|
73 | + return $details; |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * @return array |
|
78 | - */ |
|
79 | - public function getBrowserDetails() |
|
80 | - { |
|
81 | - $browser = new Browser(); |
|
82 | - $name = esc_attr($browser->getName()); |
|
83 | - $userAgent = esc_attr($browser->getUserAgent()->getUserAgentString()); |
|
84 | - $version = esc_attr($browser->getVersion()); |
|
85 | - return [ |
|
86 | - 'Browser Name' => sprintf('%s %s', $name, $version), |
|
87 | - 'Browser UA' => $userAgent, |
|
88 | - ]; |
|
89 | - } |
|
76 | + /** |
|
77 | + * @return array |
|
78 | + */ |
|
79 | + public function getBrowserDetails() |
|
80 | + { |
|
81 | + $browser = new Browser(); |
|
82 | + $name = esc_attr($browser->getName()); |
|
83 | + $userAgent = esc_attr($browser->getUserAgent()->getUserAgentString()); |
|
84 | + $version = esc_attr($browser->getVersion()); |
|
85 | + return [ |
|
86 | + 'Browser Name' => sprintf('%s %s', $name, $version), |
|
87 | + 'Browser UA' => $userAgent, |
|
88 | + ]; |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * @return array |
|
93 | - */ |
|
94 | - public function getInactivePluginDetails() |
|
95 | - { |
|
96 | - $activePlugins = (array) get_option('active_plugins', []); |
|
97 | - $inactivePlugins = $this->normalizePluginList(array_diff_key(get_plugins(), array_flip($activePlugins))); |
|
98 | - $multisitePlugins = $this->getMultisitePluginDetails(); |
|
99 | - return is_array($multisitePlugins) |
|
100 | - ? array_diff($inactivePlugins, $multisitePlugins) |
|
101 | - : $inactivePlugins; |
|
102 | - } |
|
91 | + /** |
|
92 | + * @return array |
|
93 | + */ |
|
94 | + public function getInactivePluginDetails() |
|
95 | + { |
|
96 | + $activePlugins = (array) get_option('active_plugins', []); |
|
97 | + $inactivePlugins = $this->normalizePluginList(array_diff_key(get_plugins(), array_flip($activePlugins))); |
|
98 | + $multisitePlugins = $this->getMultisitePluginDetails(); |
|
99 | + return is_array($multisitePlugins) |
|
100 | + ? array_diff($inactivePlugins, $multisitePlugins) |
|
101 | + : $inactivePlugins; |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
105 | - * @return void|array |
|
106 | - */ |
|
107 | - public function getMuPluginDetails() |
|
108 | - { |
|
109 | - if (empty($plugins = get_mu_plugins())) { |
|
110 | - return; |
|
111 | - } |
|
112 | - return $this->normalizePluginList($plugins); |
|
113 | - } |
|
104 | + /** |
|
105 | + * @return void|array |
|
106 | + */ |
|
107 | + public function getMuPluginDetails() |
|
108 | + { |
|
109 | + if (empty($plugins = get_mu_plugins())) { |
|
110 | + return; |
|
111 | + } |
|
112 | + return $this->normalizePluginList($plugins); |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * @return void|array |
|
117 | - */ |
|
118 | - public function getMultisitePluginDetails() |
|
119 | - { |
|
120 | - $activePlugins = (array) get_site_option('active_sitewide_plugins', []); |
|
121 | - if (!is_multisite() || empty($activePlugins)) { |
|
122 | - return; |
|
123 | - } |
|
124 | - return $this->normalizePluginList(array_intersect_key(get_plugins(), $activePlugins)); |
|
125 | - } |
|
115 | + /** |
|
116 | + * @return void|array |
|
117 | + */ |
|
118 | + public function getMultisitePluginDetails() |
|
119 | + { |
|
120 | + $activePlugins = (array) get_site_option('active_sitewide_plugins', []); |
|
121 | + if (!is_multisite() || empty($activePlugins)) { |
|
122 | + return; |
|
123 | + } |
|
124 | + return $this->normalizePluginList(array_intersect_key(get_plugins(), $activePlugins)); |
|
125 | + } |
|
126 | 126 | |
127 | - /** |
|
128 | - * @return array |
|
129 | - */ |
|
130 | - public function getPhpDetails() |
|
131 | - { |
|
132 | - $displayErrors = ini_get('display_errors') |
|
133 | - ? 'On ('.ini_get('display_errors').')' |
|
134 | - : 'N/A'; |
|
135 | - $intlSupport = extension_loaded('intl') |
|
136 | - ? phpversion('intl') |
|
137 | - : 'false'; |
|
138 | - return [ |
|
139 | - 'cURL' => var_export(function_exists('curl_init'), true), |
|
140 | - 'Default Charset' => ini_get('default_charset'), |
|
141 | - 'Display Errors' => $displayErrors, |
|
142 | - 'fsockopen' => var_export(function_exists('fsockopen'), true), |
|
143 | - 'Intl' => $intlSupport, |
|
144 | - 'IPv6' => var_export(defined('AF_INET6'), true), |
|
145 | - 'Max Execution Time' => ini_get('max_execution_time'), |
|
146 | - 'Max Input Nesting Level' => ini_get('max_input_nesting_level'), |
|
147 | - 'Max Input Vars' => ini_get('max_input_vars'), |
|
148 | - 'Memory Limit' => ini_get('memory_limit'), |
|
149 | - 'Post Max Size' => ini_get('post_max_size'), |
|
150 | - 'Sendmail Path' => ini_get('sendmail_path'), |
|
151 | - 'Session Cookie Path' => esc_html(ini_get('session.cookie_path')), |
|
152 | - 'Session Name' => esc_html(ini_get('session.name')), |
|
153 | - 'Session Save Path' => esc_html(ini_get('session.save_path')), |
|
154 | - 'Session Use Cookies' => var_export(wp_validate_boolean(ini_get('session.use_cookies')), true), |
|
155 | - 'Session Use Only Cookies' => var_export(wp_validate_boolean(ini_get('session.use_only_cookies')), true), |
|
156 | - 'Upload Max Filesize' => ini_get('upload_max_filesize'), |
|
157 | - ]; |
|
158 | - } |
|
127 | + /** |
|
128 | + * @return array |
|
129 | + */ |
|
130 | + public function getPhpDetails() |
|
131 | + { |
|
132 | + $displayErrors = ini_get('display_errors') |
|
133 | + ? 'On ('.ini_get('display_errors').')' |
|
134 | + : 'N/A'; |
|
135 | + $intlSupport = extension_loaded('intl') |
|
136 | + ? phpversion('intl') |
|
137 | + : 'false'; |
|
138 | + return [ |
|
139 | + 'cURL' => var_export(function_exists('curl_init'), true), |
|
140 | + 'Default Charset' => ini_get('default_charset'), |
|
141 | + 'Display Errors' => $displayErrors, |
|
142 | + 'fsockopen' => var_export(function_exists('fsockopen'), true), |
|
143 | + 'Intl' => $intlSupport, |
|
144 | + 'IPv6' => var_export(defined('AF_INET6'), true), |
|
145 | + 'Max Execution Time' => ini_get('max_execution_time'), |
|
146 | + 'Max Input Nesting Level' => ini_get('max_input_nesting_level'), |
|
147 | + 'Max Input Vars' => ini_get('max_input_vars'), |
|
148 | + 'Memory Limit' => ini_get('memory_limit'), |
|
149 | + 'Post Max Size' => ini_get('post_max_size'), |
|
150 | + 'Sendmail Path' => ini_get('sendmail_path'), |
|
151 | + 'Session Cookie Path' => esc_html(ini_get('session.cookie_path')), |
|
152 | + 'Session Name' => esc_html(ini_get('session.name')), |
|
153 | + 'Session Save Path' => esc_html(ini_get('session.save_path')), |
|
154 | + 'Session Use Cookies' => var_export(wp_validate_boolean(ini_get('session.use_cookies')), true), |
|
155 | + 'Session Use Only Cookies' => var_export(wp_validate_boolean(ini_get('session.use_only_cookies')), true), |
|
156 | + 'Upload Max Filesize' => ini_get('upload_max_filesize'), |
|
157 | + ]; |
|
158 | + } |
|
159 | 159 | |
160 | - /** |
|
161 | - * @return array |
|
162 | - */ |
|
163 | - public function getReviewsDetails() |
|
164 | - { |
|
165 | - $counts = glsr(CountsManager::class)->getCounts(); |
|
166 | - $counts = glsr(Helper::class)->flattenArray($counts); |
|
167 | - array_walk($counts, function (&$ratings) use ($counts) { |
|
168 | - if (!is_array($ratings)) { |
|
169 | - glsr_log() |
|
170 | - ->error('$ratings is not an array, possibly due to incorrectly imported reviews.') |
|
171 | - ->debug($ratings) |
|
172 | - ->debug($counts); |
|
173 | - return; |
|
174 | - } |
|
175 | - $ratings = array_sum($ratings).' ('.implode(', ', $ratings).')'; |
|
176 | - }); |
|
177 | - ksort($counts); |
|
178 | - return $counts; |
|
179 | - } |
|
160 | + /** |
|
161 | + * @return array |
|
162 | + */ |
|
163 | + public function getReviewsDetails() |
|
164 | + { |
|
165 | + $counts = glsr(CountsManager::class)->getCounts(); |
|
166 | + $counts = glsr(Helper::class)->flattenArray($counts); |
|
167 | + array_walk($counts, function (&$ratings) use ($counts) { |
|
168 | + if (!is_array($ratings)) { |
|
169 | + glsr_log() |
|
170 | + ->error('$ratings is not an array, possibly due to incorrectly imported reviews.') |
|
171 | + ->debug($ratings) |
|
172 | + ->debug($counts); |
|
173 | + return; |
|
174 | + } |
|
175 | + $ratings = array_sum($ratings).' ('.implode(', ', $ratings).')'; |
|
176 | + }); |
|
177 | + ksort($counts); |
|
178 | + return $counts; |
|
179 | + } |
|
180 | 180 | |
181 | - /** |
|
182 | - * @return array |
|
183 | - */ |
|
184 | - public function getServerDetails() |
|
185 | - { |
|
186 | - global $wpdb; |
|
187 | - return [ |
|
188 | - 'Host Name' => $this->getHostName(), |
|
189 | - 'MySQL Version' => $wpdb->db_version(), |
|
190 | - 'PHP Version' => PHP_VERSION, |
|
191 | - 'Server Software' => filter_input(INPUT_SERVER, 'SERVER_SOFTWARE'), |
|
192 | - ]; |
|
193 | - } |
|
181 | + /** |
|
182 | + * @return array |
|
183 | + */ |
|
184 | + public function getServerDetails() |
|
185 | + { |
|
186 | + global $wpdb; |
|
187 | + return [ |
|
188 | + 'Host Name' => $this->getHostName(), |
|
189 | + 'MySQL Version' => $wpdb->db_version(), |
|
190 | + 'PHP Version' => PHP_VERSION, |
|
191 | + 'Server Software' => filter_input(INPUT_SERVER, 'SERVER_SOFTWARE'), |
|
192 | + ]; |
|
193 | + } |
|
194 | 194 | |
195 | - /** |
|
196 | - * @return array |
|
197 | - */ |
|
198 | - public function getSettingDetails() |
|
199 | - { |
|
200 | - $helper = glsr(Helper::class); |
|
201 | - $settings = glsr(OptionManager::class)->get('settings', []); |
|
202 | - $settings = $helper->flattenArray($settings, true); |
|
203 | - $settings = $this->purgeSensitiveData($settings); |
|
204 | - ksort($settings); |
|
205 | - $details = []; |
|
206 | - foreach ($settings as $key => $value) { |
|
207 | - if ($helper->startsWith('strings', $key) && $helper->endsWith('id', $key)) { |
|
208 | - continue; |
|
209 | - } |
|
210 | - $value = htmlspecialchars(trim(preg_replace('/\s\s+/', '\\n', $value)), ENT_QUOTES, 'UTF-8'); |
|
211 | - $details[$key] = $value; |
|
212 | - } |
|
213 | - return $details; |
|
214 | - } |
|
195 | + /** |
|
196 | + * @return array |
|
197 | + */ |
|
198 | + public function getSettingDetails() |
|
199 | + { |
|
200 | + $helper = glsr(Helper::class); |
|
201 | + $settings = glsr(OptionManager::class)->get('settings', []); |
|
202 | + $settings = $helper->flattenArray($settings, true); |
|
203 | + $settings = $this->purgeSensitiveData($settings); |
|
204 | + ksort($settings); |
|
205 | + $details = []; |
|
206 | + foreach ($settings as $key => $value) { |
|
207 | + if ($helper->startsWith('strings', $key) && $helper->endsWith('id', $key)) { |
|
208 | + continue; |
|
209 | + } |
|
210 | + $value = htmlspecialchars(trim(preg_replace('/\s\s+/', '\\n', $value)), ENT_QUOTES, 'UTF-8'); |
|
211 | + $details[$key] = $value; |
|
212 | + } |
|
213 | + return $details; |
|
214 | + } |
|
215 | 215 | |
216 | - /** |
|
217 | - * @return array |
|
218 | - */ |
|
219 | - public function getPluginDetails() |
|
220 | - { |
|
221 | - return [ |
|
222 | - 'Console level' => glsr(Console::class)->humanLevel(), |
|
223 | - 'Console size' => glsr(Console::class)->humanSize('0'), |
|
224 | - 'Last Rating Count' => date_i18n('Y-m-d H:i', glsr(OptionManager::class)->get('last_review_count')), |
|
225 | - 'Version (current)' => glsr()->version, |
|
226 | - 'Version (previous)' => glsr(OptionManager::class)->get('version_upgraded_from'), |
|
227 | - ]; |
|
228 | - } |
|
216 | + /** |
|
217 | + * @return array |
|
218 | + */ |
|
219 | + public function getPluginDetails() |
|
220 | + { |
|
221 | + return [ |
|
222 | + 'Console level' => glsr(Console::class)->humanLevel(), |
|
223 | + 'Console size' => glsr(Console::class)->humanSize('0'), |
|
224 | + 'Last Rating Count' => date_i18n('Y-m-d H:i', glsr(OptionManager::class)->get('last_review_count')), |
|
225 | + 'Version (current)' => glsr()->version, |
|
226 | + 'Version (previous)' => glsr(OptionManager::class)->get('version_upgraded_from'), |
|
227 | + ]; |
|
228 | + } |
|
229 | 229 | |
230 | - /** |
|
231 | - * @return array |
|
232 | - */ |
|
233 | - public function getWordpressDetails() |
|
234 | - { |
|
235 | - global $wpdb; |
|
236 | - $theme = wp_get_theme(); |
|
237 | - return [ |
|
238 | - 'Active Theme' => sprintf('%s v%s', (string) $theme->Name, (string) $theme->Version), |
|
239 | - 'Email Domain' => substr(strrchr(get_option('admin_email'), '@'), 1), |
|
240 | - 'Home URL' => home_url(), |
|
241 | - 'Language' => get_locale(), |
|
242 | - 'Memory Limit' => WP_MEMORY_LIMIT, |
|
243 | - 'Multisite' => var_export(is_multisite(), true), |
|
244 | - 'Page For Posts ID' => get_option('page_for_posts'), |
|
245 | - 'Page On Front ID' => get_option('page_on_front'), |
|
246 | - 'Permalink Structure' => get_option('permalink_structure', 'default'), |
|
247 | - 'Post Stati' => implode(', ', get_post_stati()), |
|
248 | - 'Remote Post' => glsr(Cache::class)->getRemotePostTest(), |
|
249 | - 'Show On Front' => get_option('show_on_front'), |
|
250 | - 'Site URL' => site_url(), |
|
251 | - 'Timezone' => glsr(OptionManager::class)->getWP('timezone_string', ini_get('date.timezone').' (PHP)'), |
|
252 | - 'Version' => get_bloginfo('version'), |
|
253 | - 'WP Debug' => var_export(defined('WP_DEBUG'), true), |
|
254 | - 'WP Max Upload Size' => size_format(wp_max_upload_size()), |
|
255 | - 'WP Memory Limit' => WP_MEMORY_LIMIT, |
|
256 | - ]; |
|
257 | - } |
|
230 | + /** |
|
231 | + * @return array |
|
232 | + */ |
|
233 | + public function getWordpressDetails() |
|
234 | + { |
|
235 | + global $wpdb; |
|
236 | + $theme = wp_get_theme(); |
|
237 | + return [ |
|
238 | + 'Active Theme' => sprintf('%s v%s', (string) $theme->Name, (string) $theme->Version), |
|
239 | + 'Email Domain' => substr(strrchr(get_option('admin_email'), '@'), 1), |
|
240 | + 'Home URL' => home_url(), |
|
241 | + 'Language' => get_locale(), |
|
242 | + 'Memory Limit' => WP_MEMORY_LIMIT, |
|
243 | + 'Multisite' => var_export(is_multisite(), true), |
|
244 | + 'Page For Posts ID' => get_option('page_for_posts'), |
|
245 | + 'Page On Front ID' => get_option('page_on_front'), |
|
246 | + 'Permalink Structure' => get_option('permalink_structure', 'default'), |
|
247 | + 'Post Stati' => implode(', ', get_post_stati()), |
|
248 | + 'Remote Post' => glsr(Cache::class)->getRemotePostTest(), |
|
249 | + 'Show On Front' => get_option('show_on_front'), |
|
250 | + 'Site URL' => site_url(), |
|
251 | + 'Timezone' => glsr(OptionManager::class)->getWP('timezone_string', ini_get('date.timezone').' (PHP)'), |
|
252 | + 'Version' => get_bloginfo('version'), |
|
253 | + 'WP Debug' => var_export(defined('WP_DEBUG'), true), |
|
254 | + 'WP Max Upload Size' => size_format(wp_max_upload_size()), |
|
255 | + 'WP Memory Limit' => WP_MEMORY_LIMIT, |
|
256 | + ]; |
|
257 | + } |
|
258 | 258 | |
259 | - /** |
|
260 | - * @return string |
|
261 | - */ |
|
262 | - protected function detectWebhostProvider() |
|
263 | - { |
|
264 | - $checks = [ |
|
265 | - '.accountservergroup.com' => 'Site5', |
|
266 | - '.gridserver.com' => 'MediaTemple Grid', |
|
267 | - '.inmotionhosting.com' => 'InMotion Hosting', |
|
268 | - '.ovh.net' => 'OVH', |
|
269 | - '.pair.com' => 'pair Networks', |
|
270 | - '.stabletransit.com' => 'Rackspace Cloud', |
|
271 | - '.stratoserver.net' => 'STRATO', |
|
272 | - '.sysfix.eu' => 'SysFix.eu Power Hosting', |
|
273 | - 'bluehost.com' => 'Bluehost', |
|
274 | - 'DH_USER' => 'DreamHost', |
|
275 | - 'Flywheel' => 'Flywheel', |
|
276 | - 'ipagemysql.com' => 'iPage', |
|
277 | - 'ipowermysql.com' => 'IPower', |
|
278 | - 'localhost:/tmp/mysql5.sock' => 'ICDSoft', |
|
279 | - 'mysqlv5' => 'NetworkSolutions', |
|
280 | - 'PAGELYBIN' => 'Pagely', |
|
281 | - 'secureserver.net' => 'GoDaddy', |
|
282 | - 'WPE_APIKEY' => 'WP Engine', |
|
283 | - ]; |
|
284 | - foreach ($checks as $key => $value) { |
|
285 | - if (!$this->isWebhostCheckValid($key)) { |
|
286 | - continue; |
|
287 | - } |
|
288 | - return $value; |
|
289 | - } |
|
290 | - return implode(',', array_filter([DB_HOST, filter_input(INPUT_SERVER, 'SERVER_NAME')])); |
|
291 | - } |
|
259 | + /** |
|
260 | + * @return string |
|
261 | + */ |
|
262 | + protected function detectWebhostProvider() |
|
263 | + { |
|
264 | + $checks = [ |
|
265 | + '.accountservergroup.com' => 'Site5', |
|
266 | + '.gridserver.com' => 'MediaTemple Grid', |
|
267 | + '.inmotionhosting.com' => 'InMotion Hosting', |
|
268 | + '.ovh.net' => 'OVH', |
|
269 | + '.pair.com' => 'pair Networks', |
|
270 | + '.stabletransit.com' => 'Rackspace Cloud', |
|
271 | + '.stratoserver.net' => 'STRATO', |
|
272 | + '.sysfix.eu' => 'SysFix.eu Power Hosting', |
|
273 | + 'bluehost.com' => 'Bluehost', |
|
274 | + 'DH_USER' => 'DreamHost', |
|
275 | + 'Flywheel' => 'Flywheel', |
|
276 | + 'ipagemysql.com' => 'iPage', |
|
277 | + 'ipowermysql.com' => 'IPower', |
|
278 | + 'localhost:/tmp/mysql5.sock' => 'ICDSoft', |
|
279 | + 'mysqlv5' => 'NetworkSolutions', |
|
280 | + 'PAGELYBIN' => 'Pagely', |
|
281 | + 'secureserver.net' => 'GoDaddy', |
|
282 | + 'WPE_APIKEY' => 'WP Engine', |
|
283 | + ]; |
|
284 | + foreach ($checks as $key => $value) { |
|
285 | + if (!$this->isWebhostCheckValid($key)) { |
|
286 | + continue; |
|
287 | + } |
|
288 | + return $value; |
|
289 | + } |
|
290 | + return implode(',', array_filter([DB_HOST, filter_input(INPUT_SERVER, 'SERVER_NAME')])); |
|
291 | + } |
|
292 | 292 | |
293 | - /** |
|
294 | - * @return string |
|
295 | - */ |
|
296 | - protected function getHostName() |
|
297 | - { |
|
298 | - return sprintf('%s (%s)', |
|
299 | - $this->detectWebhostProvider(), |
|
300 | - glsr(Helper::class)->getIpAddress() |
|
301 | - ); |
|
302 | - } |
|
293 | + /** |
|
294 | + * @return string |
|
295 | + */ |
|
296 | + protected function getHostName() |
|
297 | + { |
|
298 | + return sprintf('%s (%s)', |
|
299 | + $this->detectWebhostProvider(), |
|
300 | + glsr(Helper::class)->getIpAddress() |
|
301 | + ); |
|
302 | + } |
|
303 | 303 | |
304 | - /** |
|
305 | - * @return array |
|
306 | - */ |
|
307 | - protected function getWordpressPlugins() |
|
308 | - { |
|
309 | - $plugins = get_plugins(); |
|
310 | - $activePlugins = (array) get_option('active_plugins', []); |
|
311 | - $inactive = $this->normalizePluginList(array_diff_key($plugins, array_flip($activePlugins))); |
|
312 | - $active = $this->normalizePluginList(array_diff_key($plugins, $inactive)); |
|
313 | - return $active + $inactive; |
|
314 | - } |
|
304 | + /** |
|
305 | + * @return array |
|
306 | + */ |
|
307 | + protected function getWordpressPlugins() |
|
308 | + { |
|
309 | + $plugins = get_plugins(); |
|
310 | + $activePlugins = (array) get_option('active_plugins', []); |
|
311 | + $inactive = $this->normalizePluginList(array_diff_key($plugins, array_flip($activePlugins))); |
|
312 | + $active = $this->normalizePluginList(array_diff_key($plugins, $inactive)); |
|
313 | + return $active + $inactive; |
|
314 | + } |
|
315 | 315 | |
316 | - /** |
|
317 | - * @param string $title |
|
318 | - * @return string |
|
319 | - */ |
|
320 | - protected function implode($title, array $details) |
|
321 | - { |
|
322 | - $strings = ['['.$title.']']; |
|
323 | - $padding = max(array_map('strlen', array_keys($details))); |
|
324 | - $padding = max([$padding, static::PAD]); |
|
325 | - foreach ($details as $key => $value) { |
|
326 | - $strings[] = is_string($key) |
|
327 | - ? sprintf('%s : %s', str_pad($key, $padding, '.'), $value) |
|
328 | - : ' - '.$value; |
|
329 | - } |
|
330 | - return implode(PHP_EOL, $strings).PHP_EOL.PHP_EOL; |
|
331 | - } |
|
316 | + /** |
|
317 | + * @param string $title |
|
318 | + * @return string |
|
319 | + */ |
|
320 | + protected function implode($title, array $details) |
|
321 | + { |
|
322 | + $strings = ['['.$title.']']; |
|
323 | + $padding = max(array_map('strlen', array_keys($details))); |
|
324 | + $padding = max([$padding, static::PAD]); |
|
325 | + foreach ($details as $key => $value) { |
|
326 | + $strings[] = is_string($key) |
|
327 | + ? sprintf('%s : %s', str_pad($key, $padding, '.'), $value) |
|
328 | + : ' - '.$value; |
|
329 | + } |
|
330 | + return implode(PHP_EOL, $strings).PHP_EOL.PHP_EOL; |
|
331 | + } |
|
332 | 332 | |
333 | - /** |
|
334 | - * @param string $key |
|
335 | - * @return bool |
|
336 | - */ |
|
337 | - protected function isWebhostCheckValid($key) |
|
338 | - { |
|
339 | - return defined($key) |
|
340 | - || filter_input(INPUT_SERVER, $key) |
|
341 | - || false !== strpos(filter_input(INPUT_SERVER, 'SERVER_NAME'), $key) |
|
342 | - || false !== strpos(DB_HOST, $key) |
|
343 | - || false !== strpos(php_uname(), $key); |
|
344 | - } |
|
333 | + /** |
|
334 | + * @param string $key |
|
335 | + * @return bool |
|
336 | + */ |
|
337 | + protected function isWebhostCheckValid($key) |
|
338 | + { |
|
339 | + return defined($key) |
|
340 | + || filter_input(INPUT_SERVER, $key) |
|
341 | + || false !== strpos(filter_input(INPUT_SERVER, 'SERVER_NAME'), $key) |
|
342 | + || false !== strpos(DB_HOST, $key) |
|
343 | + || false !== strpos(php_uname(), $key); |
|
344 | + } |
|
345 | 345 | |
346 | - /** |
|
347 | - * @return array |
|
348 | - */ |
|
349 | - protected function normalizePluginList(array $plugins) |
|
350 | - { |
|
351 | - $plugins = array_map(function ($plugin) { |
|
352 | - return sprintf('%s v%s', glsr_get($plugin, 'Name'), glsr_get($plugin, 'Version')); |
|
353 | - }, $plugins); |
|
354 | - natcasesort($plugins); |
|
355 | - return array_flip($plugins); |
|
356 | - } |
|
346 | + /** |
|
347 | + * @return array |
|
348 | + */ |
|
349 | + protected function normalizePluginList(array $plugins) |
|
350 | + { |
|
351 | + $plugins = array_map(function ($plugin) { |
|
352 | + return sprintf('%s v%s', glsr_get($plugin, 'Name'), glsr_get($plugin, 'Version')); |
|
353 | + }, $plugins); |
|
354 | + natcasesort($plugins); |
|
355 | + return array_flip($plugins); |
|
356 | + } |
|
357 | 357 | |
358 | - /** |
|
359 | - * @return array |
|
360 | - */ |
|
361 | - protected function purgeSensitiveData(array $settings) |
|
362 | - { |
|
363 | - $keys = [ |
|
364 | - 'licenses.', 'submissions.recaptcha.key', 'submissions.recaptcha.secret', |
|
365 | - ]; |
|
366 | - array_walk($settings, function (&$value, $setting) use ($keys) { |
|
367 | - foreach ($keys as $key) { |
|
368 | - if (!glsr(Helper::class)->startsWith($key, $setting) || empty($value)) { |
|
369 | - continue; |
|
370 | - } |
|
371 | - $value = str_repeat('•', 13); |
|
372 | - return; |
|
373 | - } |
|
374 | - }); |
|
375 | - return $settings; |
|
376 | - } |
|
358 | + /** |
|
359 | + * @return array |
|
360 | + */ |
|
361 | + protected function purgeSensitiveData(array $settings) |
|
362 | + { |
|
363 | + $keys = [ |
|
364 | + 'licenses.', 'submissions.recaptcha.key', 'submissions.recaptcha.secret', |
|
365 | + ]; |
|
366 | + array_walk($settings, function (&$value, $setting) use ($keys) { |
|
367 | + foreach ($keys as $key) { |
|
368 | + if (!glsr(Helper::class)->startsWith($key, $setting) || empty($value)) { |
|
369 | + continue; |
|
370 | + } |
|
371 | + $value = str_repeat('•', 13); |
|
372 | + return; |
|
373 | + } |
|
374 | + }); |
|
375 | + return $settings; |
|
376 | + } |
|
377 | 377 | } |
@@ -39,17 +39,17 @@ discard block |
||
39 | 39 | 'setting' => 'Plugin Settings', |
40 | 40 | 'reviews' => 'Review Counts', |
41 | 41 | ]; |
42 | - $systemInfo = array_reduce(array_keys($details), function ($carry, $key) use ($details) { |
|
43 | - $methodName = glsr(Helper::class)->buildMethodName('get-'.$key.'-details'); |
|
44 | - if (method_exists($this, $methodName) && $systemDetails = $this->$methodName()) { |
|
42 | + $systemInfo = array_reduce( array_keys( $details ), function( $carry, $key ) use ($details) { |
|
43 | + $methodName = glsr( Helper::class )->buildMethodName( 'get-'.$key.'-details' ); |
|
44 | + if( method_exists( $this, $methodName ) && $systemDetails = $this->$methodName() ) { |
|
45 | 45 | return $carry.$this->implode( |
46 | - strtoupper($details[$key]), |
|
47 | - apply_filters('site-reviews/system/'.$key, $systemDetails) |
|
46 | + strtoupper( $details[$key] ), |
|
47 | + apply_filters( 'site-reviews/system/'.$key, $systemDetails ) |
|
48 | 48 | ); |
49 | 49 | } |
50 | 50 | return $carry; |
51 | 51 | }); |
52 | - return trim($systemInfo); |
|
52 | + return trim( $systemInfo ); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
@@ -58,9 +58,9 @@ discard block |
||
58 | 58 | public function getActivePluginDetails() |
59 | 59 | { |
60 | 60 | $plugins = get_plugins(); |
61 | - $activePlugins = (array) get_option('active_plugins', []); |
|
62 | - $inactive = array_diff_key($plugins, array_flip($activePlugins)); |
|
63 | - return $this->normalizePluginList(array_diff_key($plugins, $inactive)); |
|
61 | + $activePlugins = (array)get_option( 'active_plugins', [] ); |
|
62 | + $inactive = array_diff_key( $plugins, array_flip( $activePlugins ) ); |
|
63 | + return $this->normalizePluginList( array_diff_key( $plugins, $inactive ) ); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
@@ -68,8 +68,8 @@ discard block |
||
68 | 68 | */ |
69 | 69 | public function getAddonDetails() |
70 | 70 | { |
71 | - $details = apply_filters('site-reviews/addon/system-info', []); |
|
72 | - ksort($details); |
|
71 | + $details = apply_filters( 'site-reviews/addon/system-info', [] ); |
|
72 | + ksort( $details ); |
|
73 | 73 | return $details; |
74 | 74 | } |
75 | 75 | |
@@ -79,11 +79,11 @@ discard block |
||
79 | 79 | public function getBrowserDetails() |
80 | 80 | { |
81 | 81 | $browser = new Browser(); |
82 | - $name = esc_attr($browser->getName()); |
|
83 | - $userAgent = esc_attr($browser->getUserAgent()->getUserAgentString()); |
|
84 | - $version = esc_attr($browser->getVersion()); |
|
82 | + $name = esc_attr( $browser->getName() ); |
|
83 | + $userAgent = esc_attr( $browser->getUserAgent()->getUserAgentString() ); |
|
84 | + $version = esc_attr( $browser->getVersion() ); |
|
85 | 85 | return [ |
86 | - 'Browser Name' => sprintf('%s %s', $name, $version), |
|
86 | + 'Browser Name' => sprintf( '%s %s', $name, $version ), |
|
87 | 87 | 'Browser UA' => $userAgent, |
88 | 88 | ]; |
89 | 89 | } |
@@ -93,11 +93,11 @@ discard block |
||
93 | 93 | */ |
94 | 94 | public function getInactivePluginDetails() |
95 | 95 | { |
96 | - $activePlugins = (array) get_option('active_plugins', []); |
|
97 | - $inactivePlugins = $this->normalizePluginList(array_diff_key(get_plugins(), array_flip($activePlugins))); |
|
96 | + $activePlugins = (array)get_option( 'active_plugins', [] ); |
|
97 | + $inactivePlugins = $this->normalizePluginList( array_diff_key( get_plugins(), array_flip( $activePlugins ) ) ); |
|
98 | 98 | $multisitePlugins = $this->getMultisitePluginDetails(); |
99 | - return is_array($multisitePlugins) |
|
100 | - ? array_diff($inactivePlugins, $multisitePlugins) |
|
99 | + return is_array( $multisitePlugins ) |
|
100 | + ? array_diff( $inactivePlugins, $multisitePlugins ) |
|
101 | 101 | : $inactivePlugins; |
102 | 102 | } |
103 | 103 | |
@@ -106,10 +106,10 @@ discard block |
||
106 | 106 | */ |
107 | 107 | public function getMuPluginDetails() |
108 | 108 | { |
109 | - if (empty($plugins = get_mu_plugins())) { |
|
109 | + if( empty($plugins = get_mu_plugins()) ) { |
|
110 | 110 | return; |
111 | 111 | } |
112 | - return $this->normalizePluginList($plugins); |
|
112 | + return $this->normalizePluginList( $plugins ); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
@@ -117,11 +117,11 @@ discard block |
||
117 | 117 | */ |
118 | 118 | public function getMultisitePluginDetails() |
119 | 119 | { |
120 | - $activePlugins = (array) get_site_option('active_sitewide_plugins', []); |
|
121 | - if (!is_multisite() || empty($activePlugins)) { |
|
120 | + $activePlugins = (array)get_site_option( 'active_sitewide_plugins', [] ); |
|
121 | + if( !is_multisite() || empty($activePlugins) ) { |
|
122 | 122 | return; |
123 | 123 | } |
124 | - return $this->normalizePluginList(array_intersect_key(get_plugins(), $activePlugins)); |
|
124 | + return $this->normalizePluginList( array_intersect_key( get_plugins(), $activePlugins ) ); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -129,31 +129,31 @@ discard block |
||
129 | 129 | */ |
130 | 130 | public function getPhpDetails() |
131 | 131 | { |
132 | - $displayErrors = ini_get('display_errors') |
|
133 | - ? 'On ('.ini_get('display_errors').')' |
|
132 | + $displayErrors = ini_get( 'display_errors' ) |
|
133 | + ? 'On ('.ini_get( 'display_errors' ).')' |
|
134 | 134 | : 'N/A'; |
135 | - $intlSupport = extension_loaded('intl') |
|
136 | - ? phpversion('intl') |
|
135 | + $intlSupport = extension_loaded( 'intl' ) |
|
136 | + ? phpversion( 'intl' ) |
|
137 | 137 | : 'false'; |
138 | 138 | return [ |
139 | - 'cURL' => var_export(function_exists('curl_init'), true), |
|
140 | - 'Default Charset' => ini_get('default_charset'), |
|
139 | + 'cURL' => var_export( function_exists( 'curl_init' ), true ), |
|
140 | + 'Default Charset' => ini_get( 'default_charset' ), |
|
141 | 141 | 'Display Errors' => $displayErrors, |
142 | - 'fsockopen' => var_export(function_exists('fsockopen'), true), |
|
142 | + 'fsockopen' => var_export( function_exists( 'fsockopen' ), true ), |
|
143 | 143 | 'Intl' => $intlSupport, |
144 | - 'IPv6' => var_export(defined('AF_INET6'), true), |
|
145 | - 'Max Execution Time' => ini_get('max_execution_time'), |
|
146 | - 'Max Input Nesting Level' => ini_get('max_input_nesting_level'), |
|
147 | - 'Max Input Vars' => ini_get('max_input_vars'), |
|
148 | - 'Memory Limit' => ini_get('memory_limit'), |
|
149 | - 'Post Max Size' => ini_get('post_max_size'), |
|
150 | - 'Sendmail Path' => ini_get('sendmail_path'), |
|
151 | - 'Session Cookie Path' => esc_html(ini_get('session.cookie_path')), |
|
152 | - 'Session Name' => esc_html(ini_get('session.name')), |
|
153 | - 'Session Save Path' => esc_html(ini_get('session.save_path')), |
|
154 | - 'Session Use Cookies' => var_export(wp_validate_boolean(ini_get('session.use_cookies')), true), |
|
155 | - 'Session Use Only Cookies' => var_export(wp_validate_boolean(ini_get('session.use_only_cookies')), true), |
|
156 | - 'Upload Max Filesize' => ini_get('upload_max_filesize'), |
|
144 | + 'IPv6' => var_export( defined( 'AF_INET6' ), true ), |
|
145 | + 'Max Execution Time' => ini_get( 'max_execution_time' ), |
|
146 | + 'Max Input Nesting Level' => ini_get( 'max_input_nesting_level' ), |
|
147 | + 'Max Input Vars' => ini_get( 'max_input_vars' ), |
|
148 | + 'Memory Limit' => ini_get( 'memory_limit' ), |
|
149 | + 'Post Max Size' => ini_get( 'post_max_size' ), |
|
150 | + 'Sendmail Path' => ini_get( 'sendmail_path' ), |
|
151 | + 'Session Cookie Path' => esc_html( ini_get( 'session.cookie_path' ) ), |
|
152 | + 'Session Name' => esc_html( ini_get( 'session.name' ) ), |
|
153 | + 'Session Save Path' => esc_html( ini_get( 'session.save_path' ) ), |
|
154 | + 'Session Use Cookies' => var_export( wp_validate_boolean( ini_get( 'session.use_cookies' ) ), true ), |
|
155 | + 'Session Use Only Cookies' => var_export( wp_validate_boolean( ini_get( 'session.use_only_cookies' ) ), true ), |
|
156 | + 'Upload Max Filesize' => ini_get( 'upload_max_filesize' ), |
|
157 | 157 | ]; |
158 | 158 | } |
159 | 159 | |
@@ -162,19 +162,19 @@ discard block |
||
162 | 162 | */ |
163 | 163 | public function getReviewsDetails() |
164 | 164 | { |
165 | - $counts = glsr(CountsManager::class)->getCounts(); |
|
166 | - $counts = glsr(Helper::class)->flattenArray($counts); |
|
167 | - array_walk($counts, function (&$ratings) use ($counts) { |
|
168 | - if (!is_array($ratings)) { |
|
165 | + $counts = glsr( CountsManager::class )->getCounts(); |
|
166 | + $counts = glsr( Helper::class )->flattenArray( $counts ); |
|
167 | + array_walk( $counts, function( &$ratings ) use ($counts) { |
|
168 | + if( !is_array( $ratings ) ) { |
|
169 | 169 | glsr_log() |
170 | - ->error('$ratings is not an array, possibly due to incorrectly imported reviews.') |
|
171 | - ->debug($ratings) |
|
172 | - ->debug($counts); |
|
170 | + ->error( '$ratings is not an array, possibly due to incorrectly imported reviews.' ) |
|
171 | + ->debug( $ratings ) |
|
172 | + ->debug( $counts ); |
|
173 | 173 | return; |
174 | 174 | } |
175 | - $ratings = array_sum($ratings).' ('.implode(', ', $ratings).')'; |
|
175 | + $ratings = array_sum( $ratings ).' ('.implode( ', ', $ratings ).')'; |
|
176 | 176 | }); |
177 | - ksort($counts); |
|
177 | + ksort( $counts ); |
|
178 | 178 | return $counts; |
179 | 179 | } |
180 | 180 | |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | 'Host Name' => $this->getHostName(), |
189 | 189 | 'MySQL Version' => $wpdb->db_version(), |
190 | 190 | 'PHP Version' => PHP_VERSION, |
191 | - 'Server Software' => filter_input(INPUT_SERVER, 'SERVER_SOFTWARE'), |
|
191 | + 'Server Software' => filter_input( INPUT_SERVER, 'SERVER_SOFTWARE' ), |
|
192 | 192 | ]; |
193 | 193 | } |
194 | 194 | |
@@ -197,17 +197,17 @@ discard block |
||
197 | 197 | */ |
198 | 198 | public function getSettingDetails() |
199 | 199 | { |
200 | - $helper = glsr(Helper::class); |
|
201 | - $settings = glsr(OptionManager::class)->get('settings', []); |
|
202 | - $settings = $helper->flattenArray($settings, true); |
|
203 | - $settings = $this->purgeSensitiveData($settings); |
|
204 | - ksort($settings); |
|
200 | + $helper = glsr( Helper::class ); |
|
201 | + $settings = glsr( OptionManager::class )->get( 'settings', [] ); |
|
202 | + $settings = $helper->flattenArray( $settings, true ); |
|
203 | + $settings = $this->purgeSensitiveData( $settings ); |
|
204 | + ksort( $settings ); |
|
205 | 205 | $details = []; |
206 | - foreach ($settings as $key => $value) { |
|
207 | - if ($helper->startsWith('strings', $key) && $helper->endsWith('id', $key)) { |
|
206 | + foreach( $settings as $key => $value ) { |
|
207 | + if( $helper->startsWith( 'strings', $key ) && $helper->endsWith( 'id', $key ) ) { |
|
208 | 208 | continue; |
209 | 209 | } |
210 | - $value = htmlspecialchars(trim(preg_replace('/\s\s+/', '\\n', $value)), ENT_QUOTES, 'UTF-8'); |
|
210 | + $value = htmlspecialchars( trim( preg_replace( '/\s\s+/', '\\n', $value ) ), ENT_QUOTES, 'UTF-8' ); |
|
211 | 211 | $details[$key] = $value; |
212 | 212 | } |
213 | 213 | return $details; |
@@ -219,11 +219,11 @@ discard block |
||
219 | 219 | public function getPluginDetails() |
220 | 220 | { |
221 | 221 | return [ |
222 | - 'Console level' => glsr(Console::class)->humanLevel(), |
|
223 | - 'Console size' => glsr(Console::class)->humanSize('0'), |
|
224 | - 'Last Rating Count' => date_i18n('Y-m-d H:i', glsr(OptionManager::class)->get('last_review_count')), |
|
222 | + 'Console level' => glsr( Console::class )->humanLevel(), |
|
223 | + 'Console size' => glsr( Console::class )->humanSize( '0' ), |
|
224 | + 'Last Rating Count' => date_i18n( 'Y-m-d H:i', glsr( OptionManager::class )->get( 'last_review_count' ) ), |
|
225 | 225 | 'Version (current)' => glsr()->version, |
226 | - 'Version (previous)' => glsr(OptionManager::class)->get('version_upgraded_from'), |
|
226 | + 'Version (previous)' => glsr( OptionManager::class )->get( 'version_upgraded_from' ), |
|
227 | 227 | ]; |
228 | 228 | } |
229 | 229 | |
@@ -235,23 +235,23 @@ discard block |
||
235 | 235 | global $wpdb; |
236 | 236 | $theme = wp_get_theme(); |
237 | 237 | return [ |
238 | - 'Active Theme' => sprintf('%s v%s', (string) $theme->Name, (string) $theme->Version), |
|
239 | - 'Email Domain' => substr(strrchr(get_option('admin_email'), '@'), 1), |
|
238 | + 'Active Theme' => sprintf( '%s v%s', (string)$theme->Name, (string)$theme->Version ), |
|
239 | + 'Email Domain' => substr( strrchr( get_option( 'admin_email' ), '@' ), 1 ), |
|
240 | 240 | 'Home URL' => home_url(), |
241 | 241 | 'Language' => get_locale(), |
242 | 242 | 'Memory Limit' => WP_MEMORY_LIMIT, |
243 | - 'Multisite' => var_export(is_multisite(), true), |
|
244 | - 'Page For Posts ID' => get_option('page_for_posts'), |
|
245 | - 'Page On Front ID' => get_option('page_on_front'), |
|
246 | - 'Permalink Structure' => get_option('permalink_structure', 'default'), |
|
247 | - 'Post Stati' => implode(', ', get_post_stati()), |
|
248 | - 'Remote Post' => glsr(Cache::class)->getRemotePostTest(), |
|
249 | - 'Show On Front' => get_option('show_on_front'), |
|
243 | + 'Multisite' => var_export( is_multisite(), true ), |
|
244 | + 'Page For Posts ID' => get_option( 'page_for_posts' ), |
|
245 | + 'Page On Front ID' => get_option( 'page_on_front' ), |
|
246 | + 'Permalink Structure' => get_option( 'permalink_structure', 'default' ), |
|
247 | + 'Post Stati' => implode( ', ', get_post_stati() ), |
|
248 | + 'Remote Post' => glsr( Cache::class )->getRemotePostTest(), |
|
249 | + 'Show On Front' => get_option( 'show_on_front' ), |
|
250 | 250 | 'Site URL' => site_url(), |
251 | - 'Timezone' => glsr(OptionManager::class)->getWP('timezone_string', ini_get('date.timezone').' (PHP)'), |
|
252 | - 'Version' => get_bloginfo('version'), |
|
253 | - 'WP Debug' => var_export(defined('WP_DEBUG'), true), |
|
254 | - 'WP Max Upload Size' => size_format(wp_max_upload_size()), |
|
251 | + 'Timezone' => glsr( OptionManager::class )->getWP( 'timezone_string', ini_get( 'date.timezone' ).' (PHP)' ), |
|
252 | + 'Version' => get_bloginfo( 'version' ), |
|
253 | + 'WP Debug' => var_export( defined( 'WP_DEBUG' ), true ), |
|
254 | + 'WP Max Upload Size' => size_format( wp_max_upload_size() ), |
|
255 | 255 | 'WP Memory Limit' => WP_MEMORY_LIMIT, |
256 | 256 | ]; |
257 | 257 | } |
@@ -281,13 +281,13 @@ discard block |
||
281 | 281 | 'secureserver.net' => 'GoDaddy', |
282 | 282 | 'WPE_APIKEY' => 'WP Engine', |
283 | 283 | ]; |
284 | - foreach ($checks as $key => $value) { |
|
285 | - if (!$this->isWebhostCheckValid($key)) { |
|
284 | + foreach( $checks as $key => $value ) { |
|
285 | + if( !$this->isWebhostCheckValid( $key ) ) { |
|
286 | 286 | continue; |
287 | 287 | } |
288 | 288 | return $value; |
289 | 289 | } |
290 | - return implode(',', array_filter([DB_HOST, filter_input(INPUT_SERVER, 'SERVER_NAME')])); |
|
290 | + return implode( ',', array_filter( [DB_HOST, filter_input( INPUT_SERVER, 'SERVER_NAME' )] ) ); |
|
291 | 291 | } |
292 | 292 | |
293 | 293 | /** |
@@ -295,9 +295,9 @@ discard block |
||
295 | 295 | */ |
296 | 296 | protected function getHostName() |
297 | 297 | { |
298 | - return sprintf('%s (%s)', |
|
298 | + return sprintf( '%s (%s)', |
|
299 | 299 | $this->detectWebhostProvider(), |
300 | - glsr(Helper::class)->getIpAddress() |
|
300 | + glsr( Helper::class )->getIpAddress() |
|
301 | 301 | ); |
302 | 302 | } |
303 | 303 | |
@@ -307,9 +307,9 @@ discard block |
||
307 | 307 | protected function getWordpressPlugins() |
308 | 308 | { |
309 | 309 | $plugins = get_plugins(); |
310 | - $activePlugins = (array) get_option('active_plugins', []); |
|
311 | - $inactive = $this->normalizePluginList(array_diff_key($plugins, array_flip($activePlugins))); |
|
312 | - $active = $this->normalizePluginList(array_diff_key($plugins, $inactive)); |
|
310 | + $activePlugins = (array)get_option( 'active_plugins', [] ); |
|
311 | + $inactive = $this->normalizePluginList( array_diff_key( $plugins, array_flip( $activePlugins ) ) ); |
|
312 | + $active = $this->normalizePluginList( array_diff_key( $plugins, $inactive ) ); |
|
313 | 313 | return $active + $inactive; |
314 | 314 | } |
315 | 315 | |
@@ -317,58 +317,58 @@ discard block |
||
317 | 317 | * @param string $title |
318 | 318 | * @return string |
319 | 319 | */ |
320 | - protected function implode($title, array $details) |
|
320 | + protected function implode( $title, array $details ) |
|
321 | 321 | { |
322 | 322 | $strings = ['['.$title.']']; |
323 | - $padding = max(array_map('strlen', array_keys($details))); |
|
324 | - $padding = max([$padding, static::PAD]); |
|
325 | - foreach ($details as $key => $value) { |
|
326 | - $strings[] = is_string($key) |
|
327 | - ? sprintf('%s : %s', str_pad($key, $padding, '.'), $value) |
|
323 | + $padding = max( array_map( 'strlen', array_keys( $details ) ) ); |
|
324 | + $padding = max( [$padding, static::PAD] ); |
|
325 | + foreach( $details as $key => $value ) { |
|
326 | + $strings[] = is_string( $key ) |
|
327 | + ? sprintf( '%s : %s', str_pad( $key, $padding, '.' ), $value ) |
|
328 | 328 | : ' - '.$value; |
329 | 329 | } |
330 | - return implode(PHP_EOL, $strings).PHP_EOL.PHP_EOL; |
|
330 | + return implode( PHP_EOL, $strings ).PHP_EOL.PHP_EOL; |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | /** |
334 | 334 | * @param string $key |
335 | 335 | * @return bool |
336 | 336 | */ |
337 | - protected function isWebhostCheckValid($key) |
|
337 | + protected function isWebhostCheckValid( $key ) |
|
338 | 338 | { |
339 | - return defined($key) |
|
340 | - || filter_input(INPUT_SERVER, $key) |
|
341 | - || false !== strpos(filter_input(INPUT_SERVER, 'SERVER_NAME'), $key) |
|
342 | - || false !== strpos(DB_HOST, $key) |
|
343 | - || false !== strpos(php_uname(), $key); |
|
339 | + return defined( $key ) |
|
340 | + || filter_input( INPUT_SERVER, $key ) |
|
341 | + || false !== strpos( filter_input( INPUT_SERVER, 'SERVER_NAME' ), $key ) |
|
342 | + || false !== strpos( DB_HOST, $key ) |
|
343 | + || false !== strpos( php_uname(), $key ); |
|
344 | 344 | } |
345 | 345 | |
346 | 346 | /** |
347 | 347 | * @return array |
348 | 348 | */ |
349 | - protected function normalizePluginList(array $plugins) |
|
349 | + protected function normalizePluginList( array $plugins ) |
|
350 | 350 | { |
351 | - $plugins = array_map(function ($plugin) { |
|
352 | - return sprintf('%s v%s', glsr_get($plugin, 'Name'), glsr_get($plugin, 'Version')); |
|
353 | - }, $plugins); |
|
354 | - natcasesort($plugins); |
|
355 | - return array_flip($plugins); |
|
351 | + $plugins = array_map( function( $plugin ) { |
|
352 | + return sprintf( '%s v%s', glsr_get( $plugin, 'Name' ), glsr_get( $plugin, 'Version' ) ); |
|
353 | + }, $plugins ); |
|
354 | + natcasesort( $plugins ); |
|
355 | + return array_flip( $plugins ); |
|
356 | 356 | } |
357 | 357 | |
358 | 358 | /** |
359 | 359 | * @return array |
360 | 360 | */ |
361 | - protected function purgeSensitiveData(array $settings) |
|
361 | + protected function purgeSensitiveData( array $settings ) |
|
362 | 362 | { |
363 | 363 | $keys = [ |
364 | 364 | 'licenses.', 'submissions.recaptcha.key', 'submissions.recaptcha.secret', |
365 | 365 | ]; |
366 | - array_walk($settings, function (&$value, $setting) use ($keys) { |
|
367 | - foreach ($keys as $key) { |
|
368 | - if (!glsr(Helper::class)->startsWith($key, $setting) || empty($value)) { |
|
366 | + array_walk( $settings, function( &$value, $setting ) use ($keys) { |
|
367 | + foreach( $keys as $key ) { |
|
368 | + if( !glsr( Helper::class )->startsWith( $key, $setting ) || empty($value) ) { |
|
369 | 369 | continue; |
370 | 370 | } |
371 | - $value = str_repeat('•', 13); |
|
371 | + $value = str_repeat( '•', 13 ); |
|
372 | 372 | return; |
373 | 373 | } |
374 | 374 | }); |
@@ -6,8 +6,8 @@ |
||
6 | 6 | |
7 | 7 | class Upgrade_3_1_11 |
8 | 8 | { |
9 | - public function __construct() |
|
10 | - { |
|
11 | - delete_transient(Application::ID.'_cloudflare_ips'); |
|
12 | - } |
|
9 | + public function __construct() |
|
10 | + { |
|
11 | + delete_transient(Application::ID.'_cloudflare_ips'); |
|
12 | + } |
|
13 | 13 | } |
@@ -8,6 +8,6 @@ |
||
8 | 8 | { |
9 | 9 | public function __construct() |
10 | 10 | { |
11 | - delete_transient(Application::ID.'_cloudflare_ips'); |
|
11 | + delete_transient( Application::ID.'_cloudflare_ips' ); |
|
12 | 12 | } |
13 | 13 | } |
@@ -8,160 +8,160 @@ |
||
8 | 8 | |
9 | 9 | class Upgrade_3_0_0 |
10 | 10 | { |
11 | - const MAPPED_SETTINGS = [ |
|
12 | - 'settings.general.notification' => 'settings.general.notifications', // array |
|
13 | - 'settings.general.notification_email' => 'settings.general.notification_email', |
|
14 | - 'settings.general.notification_message' => 'settings.general.notification_message', |
|
15 | - 'settings.general.require.approval' => 'settings.general.require.approval', |
|
16 | - 'settings.general.require.login' => 'settings.general.require.login', |
|
17 | - 'settings.general.require.login_register' => 'settings.general.require.login_register', |
|
18 | - 'settings.general.webhook_url' => 'settings.general.notification_slack', |
|
19 | - 'settings.reviews-form.akismet' => 'settings.submissions.akismet', |
|
20 | - 'settings.reviews-form.blacklist.action' => 'settings.submissions.blacklist.action', |
|
21 | - 'settings.reviews-form.blacklist.entries' => 'settings.submissions.blacklist.entries', |
|
22 | - 'settings.reviews-form.recaptcha.integration' => 'settings.submissions.recaptcha.integration', |
|
23 | - 'settings.reviews-form.recaptcha.key' => 'settings.submissions.recaptcha.key', |
|
24 | - 'settings.reviews-form.recaptcha.position' => 'settings.submissions.recaptcha.position', |
|
25 | - 'settings.reviews-form.recaptcha.secret' => 'settings.submissions.recaptcha.secret', |
|
26 | - 'settings.reviews-form.required' => 'settings.submissions.required', // array |
|
27 | - 'settings.reviews.assigned_links.enabled' => 'settings.reviews.assigned_links', |
|
28 | - 'settings.reviews.avatars.enabled' => 'settings.reviews.avatars', |
|
29 | - 'settings.reviews.date.custom' => 'settings.reviews.date.custom', |
|
30 | - 'settings.reviews.date.format' => 'settings.reviews.date.format', |
|
31 | - 'settings.reviews.excerpt.enabled' => 'settings.reviews.excerpts', |
|
32 | - 'settings.reviews.excerpt.length' => 'settings.reviews.excerpts_length', |
|
33 | - 'settings.reviews.schema.address' => 'settings.schema.address', |
|
34 | - 'settings.reviews.schema.description.custom' => 'settings.schema.description.custom', |
|
35 | - 'settings.reviews.schema.description.default' => 'settings.schema.description.default', |
|
36 | - 'settings.reviews.schema.highprice' => 'settings.schema.highprice', |
|
37 | - 'settings.reviews.schema.image.custom' => 'settings.schema.image.custom', |
|
38 | - 'settings.reviews.schema.image.default' => 'settings.schema.image.default', |
|
39 | - 'settings.reviews.schema.lowprice' => 'settings.schema.lowprice', |
|
40 | - 'settings.reviews.schema.name.custom' => 'settings.schema.name.custom', |
|
41 | - 'settings.reviews.schema.name.default' => 'settings.schema.name.default', |
|
42 | - 'settings.reviews.schema.pricecurrency' => 'settings.schema.pricecurrency', |
|
43 | - 'settings.reviews.schema.pricerange' => 'settings.schema.pricerange', |
|
44 | - 'settings.reviews.schema.telephone' => 'settings.schema.telephone', |
|
45 | - 'settings.reviews.schema.type.custom' => 'settings.schema.type.custom', |
|
46 | - 'settings.reviews.schema.type.default' => 'settings.schema.type.default', |
|
47 | - 'settings.reviews.schema.url.custom' => 'settings.schema.url.custom', |
|
48 | - 'settings.reviews.schema.url.default' => 'settings.schema.url.default', |
|
49 | - 'version' => 'version_upgraded_from', |
|
50 | - ]; |
|
11 | + const MAPPED_SETTINGS = [ |
|
12 | + 'settings.general.notification' => 'settings.general.notifications', // array |
|
13 | + 'settings.general.notification_email' => 'settings.general.notification_email', |
|
14 | + 'settings.general.notification_message' => 'settings.general.notification_message', |
|
15 | + 'settings.general.require.approval' => 'settings.general.require.approval', |
|
16 | + 'settings.general.require.login' => 'settings.general.require.login', |
|
17 | + 'settings.general.require.login_register' => 'settings.general.require.login_register', |
|
18 | + 'settings.general.webhook_url' => 'settings.general.notification_slack', |
|
19 | + 'settings.reviews-form.akismet' => 'settings.submissions.akismet', |
|
20 | + 'settings.reviews-form.blacklist.action' => 'settings.submissions.blacklist.action', |
|
21 | + 'settings.reviews-form.blacklist.entries' => 'settings.submissions.blacklist.entries', |
|
22 | + 'settings.reviews-form.recaptcha.integration' => 'settings.submissions.recaptcha.integration', |
|
23 | + 'settings.reviews-form.recaptcha.key' => 'settings.submissions.recaptcha.key', |
|
24 | + 'settings.reviews-form.recaptcha.position' => 'settings.submissions.recaptcha.position', |
|
25 | + 'settings.reviews-form.recaptcha.secret' => 'settings.submissions.recaptcha.secret', |
|
26 | + 'settings.reviews-form.required' => 'settings.submissions.required', // array |
|
27 | + 'settings.reviews.assigned_links.enabled' => 'settings.reviews.assigned_links', |
|
28 | + 'settings.reviews.avatars.enabled' => 'settings.reviews.avatars', |
|
29 | + 'settings.reviews.date.custom' => 'settings.reviews.date.custom', |
|
30 | + 'settings.reviews.date.format' => 'settings.reviews.date.format', |
|
31 | + 'settings.reviews.excerpt.enabled' => 'settings.reviews.excerpts', |
|
32 | + 'settings.reviews.excerpt.length' => 'settings.reviews.excerpts_length', |
|
33 | + 'settings.reviews.schema.address' => 'settings.schema.address', |
|
34 | + 'settings.reviews.schema.description.custom' => 'settings.schema.description.custom', |
|
35 | + 'settings.reviews.schema.description.default' => 'settings.schema.description.default', |
|
36 | + 'settings.reviews.schema.highprice' => 'settings.schema.highprice', |
|
37 | + 'settings.reviews.schema.image.custom' => 'settings.schema.image.custom', |
|
38 | + 'settings.reviews.schema.image.default' => 'settings.schema.image.default', |
|
39 | + 'settings.reviews.schema.lowprice' => 'settings.schema.lowprice', |
|
40 | + 'settings.reviews.schema.name.custom' => 'settings.schema.name.custom', |
|
41 | + 'settings.reviews.schema.name.default' => 'settings.schema.name.default', |
|
42 | + 'settings.reviews.schema.pricecurrency' => 'settings.schema.pricecurrency', |
|
43 | + 'settings.reviews.schema.pricerange' => 'settings.schema.pricerange', |
|
44 | + 'settings.reviews.schema.telephone' => 'settings.schema.telephone', |
|
45 | + 'settings.reviews.schema.type.custom' => 'settings.schema.type.custom', |
|
46 | + 'settings.reviews.schema.type.default' => 'settings.schema.type.default', |
|
47 | + 'settings.reviews.schema.url.custom' => 'settings.schema.url.custom', |
|
48 | + 'settings.reviews.schema.url.default' => 'settings.schema.url.default', |
|
49 | + 'version' => 'version_upgraded_from', |
|
50 | + ]; |
|
51 | 51 | |
52 | - /** |
|
53 | - * @var array |
|
54 | - */ |
|
55 | - protected $newSettings; |
|
52 | + /** |
|
53 | + * @var array |
|
54 | + */ |
|
55 | + protected $newSettings; |
|
56 | 56 | |
57 | - /** |
|
58 | - * @var array |
|
59 | - */ |
|
60 | - protected $oldSettings; |
|
57 | + /** |
|
58 | + * @var array |
|
59 | + */ |
|
60 | + protected $oldSettings; |
|
61 | 61 | |
62 | - public function __construct() |
|
63 | - { |
|
64 | - $this->migrateSettings(); |
|
65 | - } |
|
62 | + public function __construct() |
|
63 | + { |
|
64 | + $this->migrateSettings(); |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * @return void |
|
69 | - */ |
|
70 | - public function migrateSettings() |
|
71 | - { |
|
72 | - $this->newSettings = $this->getNewSettings(); |
|
73 | - $this->oldSettings = $this->getOldSettings(); |
|
74 | - if (empty($this->oldSettings)) { |
|
75 | - return; |
|
76 | - } |
|
77 | - foreach (static::MAPPED_SETTINGS as $old => $new) { |
|
78 | - if (empty($this->oldSettings[$old])) { |
|
79 | - continue; |
|
80 | - } |
|
81 | - $this->newSettings[$new] = $this->oldSettings[$old]; |
|
82 | - } |
|
83 | - $this->migrateNotificationSettings(); |
|
84 | - $this->migrateRecaptchaSettings(); |
|
85 | - $this->migrateRequiredSettings(); |
|
86 | - $oldSettings = glsr(Helper::class)->convertDotNotationArray($this->oldSettings); |
|
87 | - $newSettings = glsr(Helper::class)->convertDotNotationArray($this->newSettings); |
|
88 | - if (isset($oldSettings['settings']['strings']) && is_array($oldSettings['settings']['strings'])) { |
|
89 | - $newSettings['settings']['strings'] = $oldSettings['settings']['strings']; |
|
90 | - } |
|
91 | - glsr(OptionManager::class)->set($newSettings); |
|
92 | - } |
|
67 | + /** |
|
68 | + * @return void |
|
69 | + */ |
|
70 | + public function migrateSettings() |
|
71 | + { |
|
72 | + $this->newSettings = $this->getNewSettings(); |
|
73 | + $this->oldSettings = $this->getOldSettings(); |
|
74 | + if (empty($this->oldSettings)) { |
|
75 | + return; |
|
76 | + } |
|
77 | + foreach (static::MAPPED_SETTINGS as $old => $new) { |
|
78 | + if (empty($this->oldSettings[$old])) { |
|
79 | + continue; |
|
80 | + } |
|
81 | + $this->newSettings[$new] = $this->oldSettings[$old]; |
|
82 | + } |
|
83 | + $this->migrateNotificationSettings(); |
|
84 | + $this->migrateRecaptchaSettings(); |
|
85 | + $this->migrateRequiredSettings(); |
|
86 | + $oldSettings = glsr(Helper::class)->convertDotNotationArray($this->oldSettings); |
|
87 | + $newSettings = glsr(Helper::class)->convertDotNotationArray($this->newSettings); |
|
88 | + if (isset($oldSettings['settings']['strings']) && is_array($oldSettings['settings']['strings'])) { |
|
89 | + $newSettings['settings']['strings'] = $oldSettings['settings']['strings']; |
|
90 | + } |
|
91 | + glsr(OptionManager::class)->set($newSettings); |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * @return array |
|
96 | - */ |
|
97 | - protected function getNewSettings() |
|
98 | - { |
|
99 | - return wp_parse_args( |
|
100 | - glsr(Helper::class)->flattenArray(glsr(OptionManager::class)->all()), |
|
101 | - glsr(DefaultsManager::class)->defaults() |
|
102 | - ); |
|
103 | - } |
|
94 | + /** |
|
95 | + * @return array |
|
96 | + */ |
|
97 | + protected function getNewSettings() |
|
98 | + { |
|
99 | + return wp_parse_args( |
|
100 | + glsr(Helper::class)->flattenArray(glsr(OptionManager::class)->all()), |
|
101 | + glsr(DefaultsManager::class)->defaults() |
|
102 | + ); |
|
103 | + } |
|
104 | 104 | |
105 | - /** |
|
106 | - * @return array |
|
107 | - */ |
|
108 | - protected function getOldSettings() |
|
109 | - { |
|
110 | - $defaults = array_fill_keys(array_keys(static::MAPPED_SETTINGS), ''); |
|
111 | - $settings = glsr(Helper::class)->flattenArray(get_option('geminilabs_site_reviews-v2', [])); |
|
112 | - if (!empty($settings)) { |
|
113 | - $settings = wp_parse_args($settings, $defaults); |
|
114 | - } |
|
115 | - return $settings; |
|
116 | - } |
|
105 | + /** |
|
106 | + * @return array |
|
107 | + */ |
|
108 | + protected function getOldSettings() |
|
109 | + { |
|
110 | + $defaults = array_fill_keys(array_keys(static::MAPPED_SETTINGS), ''); |
|
111 | + $settings = glsr(Helper::class)->flattenArray(get_option('geminilabs_site_reviews-v2', [])); |
|
112 | + if (!empty($settings)) { |
|
113 | + $settings = wp_parse_args($settings, $defaults); |
|
114 | + } |
|
115 | + return $settings; |
|
116 | + } |
|
117 | 117 | |
118 | - /** |
|
119 | - * @return void |
|
120 | - */ |
|
121 | - protected function migrateNotificationSettings() |
|
122 | - { |
|
123 | - $notifications = [ |
|
124 | - 'custom' => 'custom', |
|
125 | - 'default' => 'admin', |
|
126 | - 'webhook' => 'slack', |
|
127 | - ]; |
|
128 | - $this->newSettings['settings.general.notifications'] = []; |
|
129 | - foreach ($notifications as $old => $new) { |
|
130 | - if ($this->oldSettings['settings.general.notification'] != $old) { |
|
131 | - continue; |
|
132 | - } |
|
133 | - $this->newSettings['settings.general.notifications'][] = $new; |
|
134 | - } |
|
135 | - } |
|
118 | + /** |
|
119 | + * @return void |
|
120 | + */ |
|
121 | + protected function migrateNotificationSettings() |
|
122 | + { |
|
123 | + $notifications = [ |
|
124 | + 'custom' => 'custom', |
|
125 | + 'default' => 'admin', |
|
126 | + 'webhook' => 'slack', |
|
127 | + ]; |
|
128 | + $this->newSettings['settings.general.notifications'] = []; |
|
129 | + foreach ($notifications as $old => $new) { |
|
130 | + if ($this->oldSettings['settings.general.notification'] != $old) { |
|
131 | + continue; |
|
132 | + } |
|
133 | + $this->newSettings['settings.general.notifications'][] = $new; |
|
134 | + } |
|
135 | + } |
|
136 | 136 | |
137 | - /** |
|
138 | - * @return void |
|
139 | - */ |
|
140 | - protected function migrateRecaptchaSettings() |
|
141 | - { |
|
142 | - $recaptcha = [ |
|
143 | - 'BadgePosition' => $this->oldSettings['settings.reviews-form.recaptcha.position'], |
|
144 | - 'SecretKey' => $this->oldSettings['settings.reviews-form.recaptcha.secret'], |
|
145 | - 'SiteKey' => $this->oldSettings['settings.reviews-form.recaptcha.key'], |
|
146 | - ]; |
|
147 | - if (in_array($this->oldSettings['settings.reviews-form.recaptcha.integration'], ['custom', 'invisible-recaptcha'])) { |
|
148 | - $this->newSettings['settings.submissions.recaptcha.integration'] = 'all'; |
|
149 | - } |
|
150 | - if ('invisible-recaptcha' == $this->oldSettings['settings.reviews-form.recaptcha.integration']) { |
|
151 | - $recaptcha = wp_parse_args((array) get_site_option('ic-settings', [], false), $recaptcha); |
|
152 | - } |
|
153 | - $this->newSettings['settings.submissions.recaptcha.key'] = $recaptcha['SiteKey']; |
|
154 | - $this->newSettings['settings.submissions.recaptcha.secret'] = $recaptcha['SecretKey']; |
|
155 | - $this->newSettings['settings.submissions.recaptcha.position'] = $recaptcha['BadgePosition']; |
|
156 | - } |
|
137 | + /** |
|
138 | + * @return void |
|
139 | + */ |
|
140 | + protected function migrateRecaptchaSettings() |
|
141 | + { |
|
142 | + $recaptcha = [ |
|
143 | + 'BadgePosition' => $this->oldSettings['settings.reviews-form.recaptcha.position'], |
|
144 | + 'SecretKey' => $this->oldSettings['settings.reviews-form.recaptcha.secret'], |
|
145 | + 'SiteKey' => $this->oldSettings['settings.reviews-form.recaptcha.key'], |
|
146 | + ]; |
|
147 | + if (in_array($this->oldSettings['settings.reviews-form.recaptcha.integration'], ['custom', 'invisible-recaptcha'])) { |
|
148 | + $this->newSettings['settings.submissions.recaptcha.integration'] = 'all'; |
|
149 | + } |
|
150 | + if ('invisible-recaptcha' == $this->oldSettings['settings.reviews-form.recaptcha.integration']) { |
|
151 | + $recaptcha = wp_parse_args((array) get_site_option('ic-settings', [], false), $recaptcha); |
|
152 | + } |
|
153 | + $this->newSettings['settings.submissions.recaptcha.key'] = $recaptcha['SiteKey']; |
|
154 | + $this->newSettings['settings.submissions.recaptcha.secret'] = $recaptcha['SecretKey']; |
|
155 | + $this->newSettings['settings.submissions.recaptcha.position'] = $recaptcha['BadgePosition']; |
|
156 | + } |
|
157 | 157 | |
158 | - /** |
|
159 | - * @return void |
|
160 | - */ |
|
161 | - protected function migrateRequiredSettings() |
|
162 | - { |
|
163 | - $this->newSettings['settings.submissions.required'] = array_filter((array) $this->oldSettings['settings.reviews-form.required']); |
|
164 | - $this->newSettings['settings.submissions.required'][] = 'rating'; |
|
165 | - $this->newSettings['settings.submissions.required'][] = 'terms'; |
|
166 | - } |
|
158 | + /** |
|
159 | + * @return void |
|
160 | + */ |
|
161 | + protected function migrateRequiredSettings() |
|
162 | + { |
|
163 | + $this->newSettings['settings.submissions.required'] = array_filter((array) $this->oldSettings['settings.reviews-form.required']); |
|
164 | + $this->newSettings['settings.submissions.required'][] = 'rating'; |
|
165 | + $this->newSettings['settings.submissions.required'][] = 'terms'; |
|
166 | + } |
|
167 | 167 | } |
@@ -71,11 +71,11 @@ discard block |
||
71 | 71 | { |
72 | 72 | $this->newSettings = $this->getNewSettings(); |
73 | 73 | $this->oldSettings = $this->getOldSettings(); |
74 | - if (empty($this->oldSettings)) { |
|
74 | + if( empty($this->oldSettings) ) { |
|
75 | 75 | return; |
76 | 76 | } |
77 | - foreach (static::MAPPED_SETTINGS as $old => $new) { |
|
78 | - if (empty($this->oldSettings[$old])) { |
|
77 | + foreach( static::MAPPED_SETTINGS as $old => $new ) { |
|
78 | + if( empty($this->oldSettings[$old]) ) { |
|
79 | 79 | continue; |
80 | 80 | } |
81 | 81 | $this->newSettings[$new] = $this->oldSettings[$old]; |
@@ -83,12 +83,12 @@ discard block |
||
83 | 83 | $this->migrateNotificationSettings(); |
84 | 84 | $this->migrateRecaptchaSettings(); |
85 | 85 | $this->migrateRequiredSettings(); |
86 | - $oldSettings = glsr(Helper::class)->convertDotNotationArray($this->oldSettings); |
|
87 | - $newSettings = glsr(Helper::class)->convertDotNotationArray($this->newSettings); |
|
88 | - if (isset($oldSettings['settings']['strings']) && is_array($oldSettings['settings']['strings'])) { |
|
86 | + $oldSettings = glsr( Helper::class )->convertDotNotationArray( $this->oldSettings ); |
|
87 | + $newSettings = glsr( Helper::class )->convertDotNotationArray( $this->newSettings ); |
|
88 | + if( isset($oldSettings['settings']['strings']) && is_array( $oldSettings['settings']['strings'] ) ) { |
|
89 | 89 | $newSettings['settings']['strings'] = $oldSettings['settings']['strings']; |
90 | 90 | } |
91 | - glsr(OptionManager::class)->set($newSettings); |
|
91 | + glsr( OptionManager::class )->set( $newSettings ); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
@@ -97,8 +97,8 @@ discard block |
||
97 | 97 | protected function getNewSettings() |
98 | 98 | { |
99 | 99 | return wp_parse_args( |
100 | - glsr(Helper::class)->flattenArray(glsr(OptionManager::class)->all()), |
|
101 | - glsr(DefaultsManager::class)->defaults() |
|
100 | + glsr( Helper::class )->flattenArray( glsr( OptionManager::class )->all() ), |
|
101 | + glsr( DefaultsManager::class )->defaults() |
|
102 | 102 | ); |
103 | 103 | } |
104 | 104 | |
@@ -107,10 +107,10 @@ discard block |
||
107 | 107 | */ |
108 | 108 | protected function getOldSettings() |
109 | 109 | { |
110 | - $defaults = array_fill_keys(array_keys(static::MAPPED_SETTINGS), ''); |
|
111 | - $settings = glsr(Helper::class)->flattenArray(get_option('geminilabs_site_reviews-v2', [])); |
|
112 | - if (!empty($settings)) { |
|
113 | - $settings = wp_parse_args($settings, $defaults); |
|
110 | + $defaults = array_fill_keys( array_keys( static::MAPPED_SETTINGS ), '' ); |
|
111 | + $settings = glsr( Helper::class )->flattenArray( get_option( 'geminilabs_site_reviews-v2', [] ) ); |
|
112 | + if( !empty($settings) ) { |
|
113 | + $settings = wp_parse_args( $settings, $defaults ); |
|
114 | 114 | } |
115 | 115 | return $settings; |
116 | 116 | } |
@@ -126,8 +126,8 @@ discard block |
||
126 | 126 | 'webhook' => 'slack', |
127 | 127 | ]; |
128 | 128 | $this->newSettings['settings.general.notifications'] = []; |
129 | - foreach ($notifications as $old => $new) { |
|
130 | - if ($this->oldSettings['settings.general.notification'] != $old) { |
|
129 | + foreach( $notifications as $old => $new ) { |
|
130 | + if( $this->oldSettings['settings.general.notification'] != $old ) { |
|
131 | 131 | continue; |
132 | 132 | } |
133 | 133 | $this->newSettings['settings.general.notifications'][] = $new; |
@@ -144,11 +144,11 @@ discard block |
||
144 | 144 | 'SecretKey' => $this->oldSettings['settings.reviews-form.recaptcha.secret'], |
145 | 145 | 'SiteKey' => $this->oldSettings['settings.reviews-form.recaptcha.key'], |
146 | 146 | ]; |
147 | - if (in_array($this->oldSettings['settings.reviews-form.recaptcha.integration'], ['custom', 'invisible-recaptcha'])) { |
|
147 | + if( in_array( $this->oldSettings['settings.reviews-form.recaptcha.integration'], ['custom', 'invisible-recaptcha'] ) ) { |
|
148 | 148 | $this->newSettings['settings.submissions.recaptcha.integration'] = 'all'; |
149 | 149 | } |
150 | - if ('invisible-recaptcha' == $this->oldSettings['settings.reviews-form.recaptcha.integration']) { |
|
151 | - $recaptcha = wp_parse_args((array) get_site_option('ic-settings', [], false), $recaptcha); |
|
150 | + if( 'invisible-recaptcha' == $this->oldSettings['settings.reviews-form.recaptcha.integration'] ) { |
|
151 | + $recaptcha = wp_parse_args( (array)get_site_option( 'ic-settings', [], false ), $recaptcha ); |
|
152 | 152 | } |
153 | 153 | $this->newSettings['settings.submissions.recaptcha.key'] = $recaptcha['SiteKey']; |
154 | 154 | $this->newSettings['settings.submissions.recaptcha.secret'] = $recaptcha['SecretKey']; |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | */ |
161 | 161 | protected function migrateRequiredSettings() |
162 | 162 | { |
163 | - $this->newSettings['settings.submissions.required'] = array_filter((array) $this->oldSettings['settings.reviews-form.required']); |
|
163 | + $this->newSettings['settings.submissions.required'] = array_filter( (array)$this->oldSettings['settings.reviews-form.required'] ); |
|
164 | 164 | $this->newSettings['settings.submissions.required'][] = 'rating'; |
165 | 165 | $this->newSettings['settings.submissions.required'][] = 'terms'; |
166 | 166 | } |
@@ -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 | ); |
@@ -6,285 +6,285 @@ |
||
6 | 6 | |
7 | 7 | class Attributes |
8 | 8 | { |
9 | - const ATTRIBUTES_A = [ |
|
10 | - 'download', 'href', 'hreflang', 'ping', 'referrerpolicy', 'rel', 'target', 'type', |
|
11 | - ]; |
|
9 | + const ATTRIBUTES_A = [ |
|
10 | + 'download', 'href', 'hreflang', 'ping', 'referrerpolicy', 'rel', 'target', 'type', |
|
11 | + ]; |
|
12 | 12 | |
13 | - const ATTRIBUTES_BUTTON = [ |
|
14 | - 'autofocus', 'disabled', 'form', 'formaction', 'formenctype', 'formmethod', |
|
15 | - 'formnovalidate', 'formtarget', 'name', 'type', 'value', |
|
16 | - ]; |
|
13 | + const ATTRIBUTES_BUTTON = [ |
|
14 | + 'autofocus', 'disabled', 'form', 'formaction', 'formenctype', 'formmethod', |
|
15 | + 'formnovalidate', 'formtarget', 'name', 'type', 'value', |
|
16 | + ]; |
|
17 | 17 | |
18 | - const ATTRIBUTES_FORM = [ |
|
19 | - 'accept', 'accept-charset', 'action', 'autocapitalize', 'autocomplete', 'enctype', 'method', |
|
20 | - 'name', 'novalidate', 'target', |
|
21 | - ]; |
|
18 | + const ATTRIBUTES_FORM = [ |
|
19 | + 'accept', 'accept-charset', 'action', 'autocapitalize', 'autocomplete', 'enctype', 'method', |
|
20 | + 'name', 'novalidate', 'target', |
|
21 | + ]; |
|
22 | 22 | |
23 | - const ATTRIBUTES_IMG = [ |
|
24 | - 'alt', 'crossorigin', 'decoding', 'height', 'ismap', 'referrerpolicy', 'sizes', 'src', |
|
25 | - 'srcset', 'width', 'usemap', |
|
26 | - ]; |
|
23 | + const ATTRIBUTES_IMG = [ |
|
24 | + 'alt', 'crossorigin', 'decoding', 'height', 'ismap', 'referrerpolicy', 'sizes', 'src', |
|
25 | + 'srcset', 'width', 'usemap', |
|
26 | + ]; |
|
27 | 27 | |
28 | - const ATTRIBUTES_INPUT = [ |
|
29 | - 'accept', 'autocomplete', 'autocorrect', 'autofocus', 'capture', 'checked', 'disabled', |
|
30 | - 'form', 'formaction', 'formenctype', 'formmethod', 'formnovalidate', 'formtarget', 'height', |
|
31 | - 'incremental', 'inputmode', 'list', 'max', 'maxlength', 'min', 'minlength', 'multiple', |
|
32 | - 'name', 'pattern', 'placeholder', 'readonly', 'results', 'required', 'selectionDirection', |
|
33 | - 'selectionEnd', 'selectionStart', 'size', 'spellcheck', 'src', 'step', 'tabindex', 'type', |
|
34 | - 'value', 'webkitdirectory', 'width', |
|
35 | - ]; |
|
28 | + const ATTRIBUTES_INPUT = [ |
|
29 | + 'accept', 'autocomplete', 'autocorrect', 'autofocus', 'capture', 'checked', 'disabled', |
|
30 | + 'form', 'formaction', 'formenctype', 'formmethod', 'formnovalidate', 'formtarget', 'height', |
|
31 | + 'incremental', 'inputmode', 'list', 'max', 'maxlength', 'min', 'minlength', 'multiple', |
|
32 | + 'name', 'pattern', 'placeholder', 'readonly', 'results', 'required', 'selectionDirection', |
|
33 | + 'selectionEnd', 'selectionStart', 'size', 'spellcheck', 'src', 'step', 'tabindex', 'type', |
|
34 | + 'value', 'webkitdirectory', 'width', |
|
35 | + ]; |
|
36 | 36 | |
37 | - const ATTRIBUTES_LABEL = [ |
|
38 | - 'for', |
|
39 | - ]; |
|
37 | + const ATTRIBUTES_LABEL = [ |
|
38 | + 'for', |
|
39 | + ]; |
|
40 | 40 | |
41 | - const ATTRIBUTES_OPTION = [ |
|
42 | - 'disabled', 'label', 'selected', 'value', |
|
43 | - ]; |
|
41 | + const ATTRIBUTES_OPTION = [ |
|
42 | + 'disabled', 'label', 'selected', 'value', |
|
43 | + ]; |
|
44 | 44 | |
45 | - const ATTRIBUTES_SELECT = [ |
|
46 | - 'autofocus', 'disabled', 'form', 'multiple', 'name', 'required', 'size', |
|
47 | - ]; |
|
45 | + const ATTRIBUTES_SELECT = [ |
|
46 | + 'autofocus', 'disabled', 'form', 'multiple', 'name', 'required', 'size', |
|
47 | + ]; |
|
48 | 48 | |
49 | - const ATTRIBUTES_TEXTAREA = [ |
|
50 | - 'autocapitalize', 'autocomplete', 'autofocus', 'cols', 'disabled', 'form', 'maxlength', |
|
51 | - 'minlength', 'name', 'placeholder', 'readonly', 'required', 'rows', 'spellcheck', 'wrap', |
|
52 | - ]; |
|
49 | + const ATTRIBUTES_TEXTAREA = [ |
|
50 | + 'autocapitalize', 'autocomplete', 'autofocus', 'cols', 'disabled', 'form', 'maxlength', |
|
51 | + 'minlength', 'name', 'placeholder', 'readonly', 'required', 'rows', 'spellcheck', 'wrap', |
|
52 | + ]; |
|
53 | 53 | |
54 | - const BOOLEAN_ATTRIBUTES = [ |
|
55 | - 'autofocus', 'capture', 'checked', 'disabled', 'draggable', 'formnovalidate', 'hidden', |
|
56 | - 'multiple', 'novalidate', 'readonly', 'required', 'selected', 'spellcheck', |
|
57 | - 'webkitdirectory', |
|
58 | - ]; |
|
54 | + const BOOLEAN_ATTRIBUTES = [ |
|
55 | + 'autofocus', 'capture', 'checked', 'disabled', 'draggable', 'formnovalidate', 'hidden', |
|
56 | + 'multiple', 'novalidate', 'readonly', 'required', 'selected', 'spellcheck', |
|
57 | + 'webkitdirectory', |
|
58 | + ]; |
|
59 | 59 | |
60 | - const GLOBAL_ATTRIBUTES = [ |
|
61 | - 'accesskey', 'class', 'contenteditable', 'contextmenu', 'dir', 'draggable', 'dropzone', |
|
62 | - 'hidden', 'id', 'lang', 'spellcheck', 'style', 'tabindex', 'title', |
|
63 | - ]; |
|
60 | + const GLOBAL_ATTRIBUTES = [ |
|
61 | + 'accesskey', 'class', 'contenteditable', 'contextmenu', 'dir', 'draggable', 'dropzone', |
|
62 | + 'hidden', 'id', 'lang', 'spellcheck', 'style', 'tabindex', 'title', |
|
63 | + ]; |
|
64 | 64 | |
65 | - const GLOBAL_WILDCARD_ATTRIBUTES = [ |
|
66 | - 'aria-', 'data-', 'item', 'on', |
|
67 | - ]; |
|
65 | + const GLOBAL_WILDCARD_ATTRIBUTES = [ |
|
66 | + 'aria-', 'data-', 'item', 'on', |
|
67 | + ]; |
|
68 | 68 | |
69 | - const INPUT_TYPES = [ |
|
70 | - 'button', 'checkbox', 'color', 'date', 'datetime-local', 'email', 'file', 'hidden', 'image', |
|
71 | - 'month', 'number', 'password', 'radio', 'range', 'reset', 'search', 'submit', 'tel', 'text', |
|
72 | - 'time', 'url', 'week', |
|
73 | - ]; |
|
69 | + const INPUT_TYPES = [ |
|
70 | + 'button', 'checkbox', 'color', 'date', 'datetime-local', 'email', 'file', 'hidden', 'image', |
|
71 | + 'month', 'number', 'password', 'radio', 'range', 'reset', 'search', 'submit', 'tel', 'text', |
|
72 | + 'time', 'url', 'week', |
|
73 | + ]; |
|
74 | 74 | |
75 | - /** |
|
76 | - * @var array |
|
77 | - */ |
|
78 | - protected $attributes = []; |
|
75 | + /** |
|
76 | + * @var array |
|
77 | + */ |
|
78 | + protected $attributes = []; |
|
79 | 79 | |
80 | - /** |
|
81 | - * @param string $method |
|
82 | - * @param array $args |
|
83 | - * @return static |
|
84 | - */ |
|
85 | - public function __call($method, $args) |
|
86 | - { |
|
87 | - $args += [[], false]; |
|
88 | - $constant = 'static::ATTRIBUTES_'.strtoupper($method); |
|
89 | - $allowedAttributeKeys = defined($constant) |
|
90 | - ? constant($constant) |
|
91 | - : []; |
|
92 | - $this->normalize((array) $args[0], $allowedAttributeKeys); |
|
93 | - $this->normalizeInputType($method); |
|
94 | - return $this; |
|
95 | - } |
|
80 | + /** |
|
81 | + * @param string $method |
|
82 | + * @param array $args |
|
83 | + * @return static |
|
84 | + */ |
|
85 | + public function __call($method, $args) |
|
86 | + { |
|
87 | + $args += [[], false]; |
|
88 | + $constant = 'static::ATTRIBUTES_'.strtoupper($method); |
|
89 | + $allowedAttributeKeys = defined($constant) |
|
90 | + ? constant($constant) |
|
91 | + : []; |
|
92 | + $this->normalize((array) $args[0], $allowedAttributeKeys); |
|
93 | + $this->normalizeInputType($method); |
|
94 | + return $this; |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * @return array |
|
99 | - */ |
|
100 | - public function toArray() |
|
101 | - { |
|
102 | - return $this->attributes; |
|
103 | - } |
|
97 | + /** |
|
98 | + * @return array |
|
99 | + */ |
|
100 | + public function toArray() |
|
101 | + { |
|
102 | + return $this->attributes; |
|
103 | + } |
|
104 | 104 | |
105 | - /** |
|
106 | - * @return string |
|
107 | - */ |
|
108 | - public function toString() |
|
109 | - { |
|
110 | - $attributes = []; |
|
111 | - foreach ($this->attributes as $attribute => $value) { |
|
112 | - $quote = $this->getQuoteChar($attribute); |
|
113 | - $attributes[] = in_array($attribute, static::BOOLEAN_ATTRIBUTES) |
|
114 | - ? $attribute |
|
115 | - : $attribute.'='.$quote.implode(',', (array) $value).$quote; |
|
116 | - } |
|
117 | - return implode(' ', $attributes); |
|
118 | - } |
|
105 | + /** |
|
106 | + * @return string |
|
107 | + */ |
|
108 | + public function toString() |
|
109 | + { |
|
110 | + $attributes = []; |
|
111 | + foreach ($this->attributes as $attribute => $value) { |
|
112 | + $quote = $this->getQuoteChar($attribute); |
|
113 | + $attributes[] = in_array($attribute, static::BOOLEAN_ATTRIBUTES) |
|
114 | + ? $attribute |
|
115 | + : $attribute.'='.$quote.implode(',', (array) $value).$quote; |
|
116 | + } |
|
117 | + return implode(' ', $attributes); |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * @return array |
|
122 | - */ |
|
123 | - protected function filterAttributes(array $allowedAttributeKeys) |
|
124 | - { |
|
125 | - return array_intersect_key($this->attributes, array_flip($allowedAttributeKeys)); |
|
126 | - } |
|
120 | + /** |
|
121 | + * @return array |
|
122 | + */ |
|
123 | + protected function filterAttributes(array $allowedAttributeKeys) |
|
124 | + { |
|
125 | + return array_intersect_key($this->attributes, array_flip($allowedAttributeKeys)); |
|
126 | + } |
|
127 | 127 | |
128 | - /** |
|
129 | - * @return array |
|
130 | - */ |
|
131 | - protected function filterGlobalAttributes() |
|
132 | - { |
|
133 | - $globalAttributes = $this->filterAttributes(static::GLOBAL_ATTRIBUTES); |
|
134 | - $wildcards = []; |
|
135 | - foreach (static::GLOBAL_WILDCARD_ATTRIBUTES as $wildcard) { |
|
136 | - $newWildcards = array_filter($this->attributes, function ($key) use ($wildcard) { |
|
137 | - return glsr(Helper::class)->startsWith($wildcard, $key); |
|
138 | - }, ARRAY_FILTER_USE_KEY); |
|
139 | - $wildcards = array_merge($wildcards, $newWildcards); |
|
140 | - } |
|
141 | - return array_merge($globalAttributes, $wildcards); |
|
142 | - } |
|
128 | + /** |
|
129 | + * @return array |
|
130 | + */ |
|
131 | + protected function filterGlobalAttributes() |
|
132 | + { |
|
133 | + $globalAttributes = $this->filterAttributes(static::GLOBAL_ATTRIBUTES); |
|
134 | + $wildcards = []; |
|
135 | + foreach (static::GLOBAL_WILDCARD_ATTRIBUTES as $wildcard) { |
|
136 | + $newWildcards = array_filter($this->attributes, function ($key) use ($wildcard) { |
|
137 | + return glsr(Helper::class)->startsWith($wildcard, $key); |
|
138 | + }, ARRAY_FILTER_USE_KEY); |
|
139 | + $wildcards = array_merge($wildcards, $newWildcards); |
|
140 | + } |
|
141 | + return array_merge($globalAttributes, $wildcards); |
|
142 | + } |
|
143 | 143 | |
144 | - /** |
|
145 | - * @return array |
|
146 | - */ |
|
147 | - protected function getPermanentAttributes() |
|
148 | - { |
|
149 | - $permanentAttributes = []; |
|
150 | - if (array_key_exists('value', $this->attributes)) { |
|
151 | - $permanentAttributes['value'] = $this->attributes['value']; |
|
152 | - } |
|
153 | - return $permanentAttributes; |
|
154 | - } |
|
144 | + /** |
|
145 | + * @return array |
|
146 | + */ |
|
147 | + protected function getPermanentAttributes() |
|
148 | + { |
|
149 | + $permanentAttributes = []; |
|
150 | + if (array_key_exists('value', $this->attributes)) { |
|
151 | + $permanentAttributes['value'] = $this->attributes['value']; |
|
152 | + } |
|
153 | + return $permanentAttributes; |
|
154 | + } |
|
155 | 155 | |
156 | - /** |
|
157 | - * @param string $attribute |
|
158 | - * @return string |
|
159 | - */ |
|
160 | - protected function getQuoteChar($attribute) |
|
161 | - { |
|
162 | - return glsr(Helper::class)->startsWith('data-', $attribute) |
|
163 | - ? '\'' |
|
164 | - : '"'; |
|
165 | - } |
|
156 | + /** |
|
157 | + * @param string $attribute |
|
158 | + * @return string |
|
159 | + */ |
|
160 | + protected function getQuoteChar($attribute) |
|
161 | + { |
|
162 | + return glsr(Helper::class)->startsWith('data-', $attribute) |
|
163 | + ? '\'' |
|
164 | + : '"'; |
|
165 | + } |
|
166 | 166 | |
167 | - /** |
|
168 | - * @param string $key |
|
169 | - * @param mixed $value |
|
170 | - * @return bool |
|
171 | - */ |
|
172 | - protected function isAttributeKeyNumeric($key, $value) |
|
173 | - { |
|
174 | - return is_string($value) |
|
175 | - && is_numeric($key) |
|
176 | - && !array_key_exists($value, $this->attributes); |
|
177 | - } |
|
167 | + /** |
|
168 | + * @param string $key |
|
169 | + * @param mixed $value |
|
170 | + * @return bool |
|
171 | + */ |
|
172 | + protected function isAttributeKeyNumeric($key, $value) |
|
173 | + { |
|
174 | + return is_string($value) |
|
175 | + && is_numeric($key) |
|
176 | + && !array_key_exists($value, $this->attributes); |
|
177 | + } |
|
178 | 178 | |
179 | - /** |
|
180 | - * @return void |
|
181 | - */ |
|
182 | - protected function normalize(array $args, array $allowedAttributeKeys) |
|
183 | - { |
|
184 | - $this->attributes = array_change_key_case($args, CASE_LOWER); |
|
185 | - $this->normalizeBooleanAttributes(); |
|
186 | - $this->normalizeDataAttributes(); |
|
187 | - $this->normalizeStringAttributes(); |
|
188 | - $this->removeEmptyAttributes(); |
|
189 | - $this->removeIndexedAttributes(); |
|
190 | - $this->attributes = array_merge( |
|
191 | - $this->filterGlobalAttributes(), |
|
192 | - $this->filterAttributes($allowedAttributeKeys) |
|
193 | - ); |
|
194 | - } |
|
179 | + /** |
|
180 | + * @return void |
|
181 | + */ |
|
182 | + protected function normalize(array $args, array $allowedAttributeKeys) |
|
183 | + { |
|
184 | + $this->attributes = array_change_key_case($args, CASE_LOWER); |
|
185 | + $this->normalizeBooleanAttributes(); |
|
186 | + $this->normalizeDataAttributes(); |
|
187 | + $this->normalizeStringAttributes(); |
|
188 | + $this->removeEmptyAttributes(); |
|
189 | + $this->removeIndexedAttributes(); |
|
190 | + $this->attributes = array_merge( |
|
191 | + $this->filterGlobalAttributes(), |
|
192 | + $this->filterAttributes($allowedAttributeKeys) |
|
193 | + ); |
|
194 | + } |
|
195 | 195 | |
196 | - /** |
|
197 | - * @return void |
|
198 | - */ |
|
199 | - protected function normalizeBooleanAttributes() |
|
200 | - { |
|
201 | - foreach ($this->attributes as $key => $value) { |
|
202 | - if ($this->isAttributeKeyNumeric($key, $value)) { |
|
203 | - $key = $value; |
|
204 | - $value = true; |
|
205 | - } |
|
206 | - if (!in_array($key, static::BOOLEAN_ATTRIBUTES)) { |
|
207 | - continue; |
|
208 | - } |
|
209 | - $this->attributes[$key] = wp_validate_boolean($value); |
|
210 | - } |
|
211 | - } |
|
196 | + /** |
|
197 | + * @return void |
|
198 | + */ |
|
199 | + protected function normalizeBooleanAttributes() |
|
200 | + { |
|
201 | + foreach ($this->attributes as $key => $value) { |
|
202 | + if ($this->isAttributeKeyNumeric($key, $value)) { |
|
203 | + $key = $value; |
|
204 | + $value = true; |
|
205 | + } |
|
206 | + if (!in_array($key, static::BOOLEAN_ATTRIBUTES)) { |
|
207 | + continue; |
|
208 | + } |
|
209 | + $this->attributes[$key] = wp_validate_boolean($value); |
|
210 | + } |
|
211 | + } |
|
212 | 212 | |
213 | - /** |
|
214 | - * @return void |
|
215 | - */ |
|
216 | - protected function normalizeDataAttributes() |
|
217 | - { |
|
218 | - foreach ($this->attributes as $key => $value) { |
|
219 | - if ($this->isAttributeKeyNumeric($key, $value)) { |
|
220 | - $key = $value; |
|
221 | - $value = ''; |
|
222 | - } |
|
223 | - if (!glsr(Helper::class)->startsWith('data-', $key)) { |
|
224 | - continue; |
|
225 | - } |
|
226 | - if (is_array($value)) { |
|
227 | - $value = json_encode($value, JSON_HEX_APOS | JSON_NUMERIC_CHECK | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); |
|
228 | - } |
|
229 | - $this->attributes[$key] = $value; |
|
230 | - } |
|
231 | - } |
|
213 | + /** |
|
214 | + * @return void |
|
215 | + */ |
|
216 | + protected function normalizeDataAttributes() |
|
217 | + { |
|
218 | + foreach ($this->attributes as $key => $value) { |
|
219 | + if ($this->isAttributeKeyNumeric($key, $value)) { |
|
220 | + $key = $value; |
|
221 | + $value = ''; |
|
222 | + } |
|
223 | + if (!glsr(Helper::class)->startsWith('data-', $key)) { |
|
224 | + continue; |
|
225 | + } |
|
226 | + if (is_array($value)) { |
|
227 | + $value = json_encode($value, JSON_HEX_APOS | JSON_NUMERIC_CHECK | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); |
|
228 | + } |
|
229 | + $this->attributes[$key] = $value; |
|
230 | + } |
|
231 | + } |
|
232 | 232 | |
233 | - /** |
|
234 | - * @return void |
|
235 | - */ |
|
236 | - protected function normalizeStringAttributes() |
|
237 | - { |
|
238 | - foreach ($this->attributes as $key => $value) { |
|
239 | - if (!is_string($value)) { |
|
240 | - continue; |
|
241 | - } |
|
242 | - $this->attributes[$key] = trim($value); |
|
243 | - } |
|
244 | - } |
|
233 | + /** |
|
234 | + * @return void |
|
235 | + */ |
|
236 | + protected function normalizeStringAttributes() |
|
237 | + { |
|
238 | + foreach ($this->attributes as $key => $value) { |
|
239 | + if (!is_string($value)) { |
|
240 | + continue; |
|
241 | + } |
|
242 | + $this->attributes[$key] = trim($value); |
|
243 | + } |
|
244 | + } |
|
245 | 245 | |
246 | - /** |
|
247 | - * @param string $method |
|
248 | - * @return void |
|
249 | - */ |
|
250 | - protected function normalizeInputType($method) |
|
251 | - { |
|
252 | - if ('input' != $method) { |
|
253 | - return; |
|
254 | - } |
|
255 | - $attributes = wp_parse_args($this->attributes, ['type' => '']); |
|
256 | - if (!in_array($attributes['type'], static::INPUT_TYPES)) { |
|
257 | - $this->attributes['type'] = 'text'; |
|
258 | - } |
|
259 | - } |
|
246 | + /** |
|
247 | + * @param string $method |
|
248 | + * @return void |
|
249 | + */ |
|
250 | + protected function normalizeInputType($method) |
|
251 | + { |
|
252 | + if ('input' != $method) { |
|
253 | + return; |
|
254 | + } |
|
255 | + $attributes = wp_parse_args($this->attributes, ['type' => '']); |
|
256 | + if (!in_array($attributes['type'], static::INPUT_TYPES)) { |
|
257 | + $this->attributes['type'] = 'text'; |
|
258 | + } |
|
259 | + } |
|
260 | 260 | |
261 | - /** |
|
262 | - * @return void |
|
263 | - */ |
|
264 | - protected function removeEmptyAttributes() |
|
265 | - { |
|
266 | - $attributes = $this->attributes; |
|
267 | - $permanentAttributes = $this->getPermanentAttributes(); |
|
268 | - foreach ($this->attributes as $key => $value) { |
|
269 | - if (in_array($key, static::BOOLEAN_ATTRIBUTES) && !$value) { |
|
270 | - unset($attributes[$key]); |
|
271 | - } |
|
272 | - if (glsr(Helper::class)->startsWith('data-', $key)) { |
|
273 | - $permanentAttributes[$key] = $value; |
|
274 | - unset($attributes[$key]); |
|
275 | - } |
|
276 | - } |
|
277 | - $this->attributes = array_merge(array_filter($attributes), $permanentAttributes); |
|
278 | - } |
|
261 | + /** |
|
262 | + * @return void |
|
263 | + */ |
|
264 | + protected function removeEmptyAttributes() |
|
265 | + { |
|
266 | + $attributes = $this->attributes; |
|
267 | + $permanentAttributes = $this->getPermanentAttributes(); |
|
268 | + foreach ($this->attributes as $key => $value) { |
|
269 | + if (in_array($key, static::BOOLEAN_ATTRIBUTES) && !$value) { |
|
270 | + unset($attributes[$key]); |
|
271 | + } |
|
272 | + if (glsr(Helper::class)->startsWith('data-', $key)) { |
|
273 | + $permanentAttributes[$key] = $value; |
|
274 | + unset($attributes[$key]); |
|
275 | + } |
|
276 | + } |
|
277 | + $this->attributes = array_merge(array_filter($attributes), $permanentAttributes); |
|
278 | + } |
|
279 | 279 | |
280 | - /** |
|
281 | - * @return void |
|
282 | - */ |
|
283 | - protected function removeIndexedAttributes() |
|
284 | - { |
|
285 | - $this->attributes = array_diff_key( |
|
286 | - $this->attributes, |
|
287 | - array_filter($this->attributes, 'is_numeric', ARRAY_FILTER_USE_KEY) |
|
288 | - ); |
|
289 | - } |
|
280 | + /** |
|
281 | + * @return void |
|
282 | + */ |
|
283 | + protected function removeIndexedAttributes() |
|
284 | + { |
|
285 | + $this->attributes = array_diff_key( |
|
286 | + $this->attributes, |
|
287 | + array_filter($this->attributes, 'is_numeric', ARRAY_FILTER_USE_KEY) |
|
288 | + ); |
|
289 | + } |
|
290 | 290 | } |
@@ -82,15 +82,15 @@ discard block |
||
82 | 82 | * @param array $args |
83 | 83 | * @return static |
84 | 84 | */ |
85 | - public function __call($method, $args) |
|
85 | + public function __call( $method, $args ) |
|
86 | 86 | { |
87 | 87 | $args += [[], false]; |
88 | - $constant = 'static::ATTRIBUTES_'.strtoupper($method); |
|
89 | - $allowedAttributeKeys = defined($constant) |
|
90 | - ? constant($constant) |
|
88 | + $constant = 'static::ATTRIBUTES_'.strtoupper( $method ); |
|
89 | + $allowedAttributeKeys = defined( $constant ) |
|
90 | + ? constant( $constant ) |
|
91 | 91 | : []; |
92 | - $this->normalize((array) $args[0], $allowedAttributeKeys); |
|
93 | - $this->normalizeInputType($method); |
|
92 | + $this->normalize( (array)$args[0], $allowedAttributeKeys ); |
|
93 | + $this->normalizeInputType( $method ); |
|
94 | 94 | return $this; |
95 | 95 | } |
96 | 96 | |
@@ -108,21 +108,21 @@ discard block |
||
108 | 108 | public function toString() |
109 | 109 | { |
110 | 110 | $attributes = []; |
111 | - foreach ($this->attributes as $attribute => $value) { |
|
112 | - $quote = $this->getQuoteChar($attribute); |
|
113 | - $attributes[] = in_array($attribute, static::BOOLEAN_ATTRIBUTES) |
|
111 | + foreach( $this->attributes as $attribute => $value ) { |
|
112 | + $quote = $this->getQuoteChar( $attribute ); |
|
113 | + $attributes[] = in_array( $attribute, static::BOOLEAN_ATTRIBUTES ) |
|
114 | 114 | ? $attribute |
115 | - : $attribute.'='.$quote.implode(',', (array) $value).$quote; |
|
115 | + : $attribute.'='.$quote.implode( ',', (array)$value ).$quote; |
|
116 | 116 | } |
117 | - return implode(' ', $attributes); |
|
117 | + return implode( ' ', $attributes ); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
121 | 121 | * @return array |
122 | 122 | */ |
123 | - protected function filterAttributes(array $allowedAttributeKeys) |
|
123 | + protected function filterAttributes( array $allowedAttributeKeys ) |
|
124 | 124 | { |
125 | - return array_intersect_key($this->attributes, array_flip($allowedAttributeKeys)); |
|
125 | + return array_intersect_key( $this->attributes, array_flip( $allowedAttributeKeys ) ); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
@@ -130,15 +130,15 @@ discard block |
||
130 | 130 | */ |
131 | 131 | protected function filterGlobalAttributes() |
132 | 132 | { |
133 | - $globalAttributes = $this->filterAttributes(static::GLOBAL_ATTRIBUTES); |
|
133 | + $globalAttributes = $this->filterAttributes( static::GLOBAL_ATTRIBUTES ); |
|
134 | 134 | $wildcards = []; |
135 | - foreach (static::GLOBAL_WILDCARD_ATTRIBUTES as $wildcard) { |
|
136 | - $newWildcards = array_filter($this->attributes, function ($key) use ($wildcard) { |
|
137 | - return glsr(Helper::class)->startsWith($wildcard, $key); |
|
138 | - }, ARRAY_FILTER_USE_KEY); |
|
139 | - $wildcards = array_merge($wildcards, $newWildcards); |
|
135 | + foreach( static::GLOBAL_WILDCARD_ATTRIBUTES as $wildcard ) { |
|
136 | + $newWildcards = array_filter( $this->attributes, function( $key ) use ($wildcard) { |
|
137 | + return glsr( Helper::class )->startsWith( $wildcard, $key ); |
|
138 | + }, ARRAY_FILTER_USE_KEY ); |
|
139 | + $wildcards = array_merge( $wildcards, $newWildcards ); |
|
140 | 140 | } |
141 | - return array_merge($globalAttributes, $wildcards); |
|
141 | + return array_merge( $globalAttributes, $wildcards ); |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | /** |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | protected function getPermanentAttributes() |
148 | 148 | { |
149 | 149 | $permanentAttributes = []; |
150 | - if (array_key_exists('value', $this->attributes)) { |
|
150 | + if( array_key_exists( 'value', $this->attributes ) ) { |
|
151 | 151 | $permanentAttributes['value'] = $this->attributes['value']; |
152 | 152 | } |
153 | 153 | return $permanentAttributes; |
@@ -157,9 +157,9 @@ discard block |
||
157 | 157 | * @param string $attribute |
158 | 158 | * @return string |
159 | 159 | */ |
160 | - protected function getQuoteChar($attribute) |
|
160 | + protected function getQuoteChar( $attribute ) |
|
161 | 161 | { |
162 | - return glsr(Helper::class)->startsWith('data-', $attribute) |
|
162 | + return glsr( Helper::class )->startsWith( 'data-', $attribute ) |
|
163 | 163 | ? '\'' |
164 | 164 | : '"'; |
165 | 165 | } |
@@ -169,19 +169,19 @@ discard block |
||
169 | 169 | * @param mixed $value |
170 | 170 | * @return bool |
171 | 171 | */ |
172 | - protected function isAttributeKeyNumeric($key, $value) |
|
172 | + protected function isAttributeKeyNumeric( $key, $value ) |
|
173 | 173 | { |
174 | - return is_string($value) |
|
175 | - && is_numeric($key) |
|
176 | - && !array_key_exists($value, $this->attributes); |
|
174 | + return is_string( $value ) |
|
175 | + && is_numeric( $key ) |
|
176 | + && !array_key_exists( $value, $this->attributes ); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | /** |
180 | 180 | * @return void |
181 | 181 | */ |
182 | - protected function normalize(array $args, array $allowedAttributeKeys) |
|
182 | + protected function normalize( array $args, array $allowedAttributeKeys ) |
|
183 | 183 | { |
184 | - $this->attributes = array_change_key_case($args, CASE_LOWER); |
|
184 | + $this->attributes = array_change_key_case( $args, CASE_LOWER ); |
|
185 | 185 | $this->normalizeBooleanAttributes(); |
186 | 186 | $this->normalizeDataAttributes(); |
187 | 187 | $this->normalizeStringAttributes(); |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | $this->removeIndexedAttributes(); |
190 | 190 | $this->attributes = array_merge( |
191 | 191 | $this->filterGlobalAttributes(), |
192 | - $this->filterAttributes($allowedAttributeKeys) |
|
192 | + $this->filterAttributes( $allowedAttributeKeys ) |
|
193 | 193 | ); |
194 | 194 | } |
195 | 195 | |
@@ -198,15 +198,15 @@ discard block |
||
198 | 198 | */ |
199 | 199 | protected function normalizeBooleanAttributes() |
200 | 200 | { |
201 | - foreach ($this->attributes as $key => $value) { |
|
202 | - if ($this->isAttributeKeyNumeric($key, $value)) { |
|
201 | + foreach( $this->attributes as $key => $value ) { |
|
202 | + if( $this->isAttributeKeyNumeric( $key, $value ) ) { |
|
203 | 203 | $key = $value; |
204 | 204 | $value = true; |
205 | 205 | } |
206 | - if (!in_array($key, static::BOOLEAN_ATTRIBUTES)) { |
|
206 | + if( !in_array( $key, static::BOOLEAN_ATTRIBUTES ) ) { |
|
207 | 207 | continue; |
208 | 208 | } |
209 | - $this->attributes[$key] = wp_validate_boolean($value); |
|
209 | + $this->attributes[$key] = wp_validate_boolean( $value ); |
|
210 | 210 | } |
211 | 211 | } |
212 | 212 | |
@@ -215,16 +215,16 @@ discard block |
||
215 | 215 | */ |
216 | 216 | protected function normalizeDataAttributes() |
217 | 217 | { |
218 | - foreach ($this->attributes as $key => $value) { |
|
219 | - if ($this->isAttributeKeyNumeric($key, $value)) { |
|
218 | + foreach( $this->attributes as $key => $value ) { |
|
219 | + if( $this->isAttributeKeyNumeric( $key, $value ) ) { |
|
220 | 220 | $key = $value; |
221 | 221 | $value = ''; |
222 | 222 | } |
223 | - if (!glsr(Helper::class)->startsWith('data-', $key)) { |
|
223 | + if( !glsr( Helper::class )->startsWith( 'data-', $key ) ) { |
|
224 | 224 | continue; |
225 | 225 | } |
226 | - if (is_array($value)) { |
|
227 | - $value = json_encode($value, JSON_HEX_APOS | JSON_NUMERIC_CHECK | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); |
|
226 | + if( is_array( $value ) ) { |
|
227 | + $value = json_encode( $value, JSON_HEX_APOS | JSON_NUMERIC_CHECK | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ); |
|
228 | 228 | } |
229 | 229 | $this->attributes[$key] = $value; |
230 | 230 | } |
@@ -235,11 +235,11 @@ discard block |
||
235 | 235 | */ |
236 | 236 | protected function normalizeStringAttributes() |
237 | 237 | { |
238 | - foreach ($this->attributes as $key => $value) { |
|
239 | - if (!is_string($value)) { |
|
238 | + foreach( $this->attributes as $key => $value ) { |
|
239 | + if( !is_string( $value ) ) { |
|
240 | 240 | continue; |
241 | 241 | } |
242 | - $this->attributes[$key] = trim($value); |
|
242 | + $this->attributes[$key] = trim( $value ); |
|
243 | 243 | } |
244 | 244 | } |
245 | 245 | |
@@ -247,13 +247,13 @@ discard block |
||
247 | 247 | * @param string $method |
248 | 248 | * @return void |
249 | 249 | */ |
250 | - protected function normalizeInputType($method) |
|
250 | + protected function normalizeInputType( $method ) |
|
251 | 251 | { |
252 | - if ('input' != $method) { |
|
252 | + if( 'input' != $method ) { |
|
253 | 253 | return; |
254 | 254 | } |
255 | - $attributes = wp_parse_args($this->attributes, ['type' => '']); |
|
256 | - if (!in_array($attributes['type'], static::INPUT_TYPES)) { |
|
255 | + $attributes = wp_parse_args( $this->attributes, ['type' => ''] ); |
|
256 | + if( !in_array( $attributes['type'], static::INPUT_TYPES ) ) { |
|
257 | 257 | $this->attributes['type'] = 'text'; |
258 | 258 | } |
259 | 259 | } |
@@ -265,16 +265,16 @@ discard block |
||
265 | 265 | { |
266 | 266 | $attributes = $this->attributes; |
267 | 267 | $permanentAttributes = $this->getPermanentAttributes(); |
268 | - foreach ($this->attributes as $key => $value) { |
|
269 | - if (in_array($key, static::BOOLEAN_ATTRIBUTES) && !$value) { |
|
268 | + foreach( $this->attributes as $key => $value ) { |
|
269 | + if( in_array( $key, static::BOOLEAN_ATTRIBUTES ) && !$value ) { |
|
270 | 270 | unset($attributes[$key]); |
271 | 271 | } |
272 | - if (glsr(Helper::class)->startsWith('data-', $key)) { |
|
272 | + if( glsr( Helper::class )->startsWith( 'data-', $key ) ) { |
|
273 | 273 | $permanentAttributes[$key] = $value; |
274 | 274 | unset($attributes[$key]); |
275 | 275 | } |
276 | 276 | } |
277 | - $this->attributes = array_merge(array_filter($attributes), $permanentAttributes); |
|
277 | + $this->attributes = array_merge( array_filter( $attributes ), $permanentAttributes ); |
|
278 | 278 | } |
279 | 279 | |
280 | 280 | /** |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | { |
285 | 285 | $this->attributes = array_diff_key( |
286 | 286 | $this->attributes, |
287 | - array_filter($this->attributes, 'is_numeric', ARRAY_FILTER_USE_KEY) |
|
287 | + array_filter( $this->attributes, 'is_numeric', ARRAY_FILTER_USE_KEY ) |
|
288 | 288 | ); |
289 | 289 | } |
290 | 290 | } |