@@ -11,272 +11,272 @@ |
||
11 | 11 | |
12 | 12 | class Translation |
13 | 13 | { |
14 | - const SEARCH_THRESHOLD = 3; |
|
14 | + const SEARCH_THRESHOLD = 3; |
|
15 | 15 | |
16 | - /** |
|
17 | - * @var array |
|
18 | - */ |
|
19 | - protected $entries; |
|
16 | + /** |
|
17 | + * @var array |
|
18 | + */ |
|
19 | + protected $entries; |
|
20 | 20 | |
21 | - /** |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $results; |
|
21 | + /** |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + protected $results; |
|
25 | 25 | |
26 | - /** |
|
27 | - * Returns all saved custom translations with translation context. |
|
28 | - * @return array |
|
29 | - */ |
|
30 | - public function all() |
|
31 | - { |
|
32 | - $translations = $this->translations(); |
|
33 | - $entries = $this->filter($translations, $this->entries())->results(); |
|
34 | - array_walk($translations, function (&$entry) use ($entries) { |
|
35 | - $entry['desc'] = array_key_exists($entry['id'], $entries) |
|
36 | - ? $this->getEntryString($entries[$entry['id']], 'msgctxt') |
|
37 | - : ''; |
|
38 | - }); |
|
39 | - return $translations; |
|
40 | - } |
|
26 | + /** |
|
27 | + * Returns all saved custom translations with translation context. |
|
28 | + * @return array |
|
29 | + */ |
|
30 | + public function all() |
|
31 | + { |
|
32 | + $translations = $this->translations(); |
|
33 | + $entries = $this->filter($translations, $this->entries())->results(); |
|
34 | + array_walk($translations, function (&$entry) use ($entries) { |
|
35 | + $entry['desc'] = array_key_exists($entry['id'], $entries) |
|
36 | + ? $this->getEntryString($entries[$entry['id']], 'msgctxt') |
|
37 | + : ''; |
|
38 | + }); |
|
39 | + return $translations; |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * @return array |
|
44 | - */ |
|
45 | - public function entries() |
|
46 | - { |
|
47 | - if (!isset($this->entries)) { |
|
48 | - $potFile = glsr()->path(glsr()->languages.'/'.Application::ID.'.pot'); |
|
49 | - $entries = $this->extractEntriesFromPotFile($potFile); |
|
50 | - $entries = apply_filters('site-reviews/translation/entries', $entries); |
|
51 | - $this->entries = $entries; |
|
52 | - } |
|
53 | - return $this->entries; |
|
54 | - } |
|
42 | + /** |
|
43 | + * @return array |
|
44 | + */ |
|
45 | + public function entries() |
|
46 | + { |
|
47 | + if (!isset($this->entries)) { |
|
48 | + $potFile = glsr()->path(glsr()->languages.'/'.Application::ID.'.pot'); |
|
49 | + $entries = $this->extractEntriesFromPotFile($potFile); |
|
50 | + $entries = apply_filters('site-reviews/translation/entries', $entries); |
|
51 | + $this->entries = $entries; |
|
52 | + } |
|
53 | + return $this->entries; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * @param array|null $entriesToExclude |
|
58 | - * @param array|null $entries |
|
59 | - * @return static |
|
60 | - */ |
|
61 | - public function exclude($entriesToExclude = null, $entries = null) |
|
62 | - { |
|
63 | - return $this->filter($entriesToExclude, $entries, false); |
|
64 | - } |
|
56 | + /** |
|
57 | + * @param array|null $entriesToExclude |
|
58 | + * @param array|null $entries |
|
59 | + * @return static |
|
60 | + */ |
|
61 | + public function exclude($entriesToExclude = null, $entries = null) |
|
62 | + { |
|
63 | + return $this->filter($entriesToExclude, $entries, false); |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @param string $potFile |
|
68 | - * @return array |
|
69 | - */ |
|
70 | - public function extractEntriesFromPotFile($potFile, array $entries = []) |
|
71 | - { |
|
72 | - try { |
|
73 | - $potEntries = $this->normalize(Parser::parseFile($potFile)->getEntries()); |
|
74 | - foreach ($potEntries as $key => $entry) { |
|
75 | - $entries[html_entity_decode($key, ENT_COMPAT, 'UTF-8')] = $entry; |
|
76 | - } |
|
77 | - } catch (Exception $e) { |
|
78 | - glsr_log()->error($e->getMessage()); |
|
79 | - } |
|
80 | - return $entries; |
|
81 | - } |
|
66 | + /** |
|
67 | + * @param string $potFile |
|
68 | + * @return array |
|
69 | + */ |
|
70 | + public function extractEntriesFromPotFile($potFile, array $entries = []) |
|
71 | + { |
|
72 | + try { |
|
73 | + $potEntries = $this->normalize(Parser::parseFile($potFile)->getEntries()); |
|
74 | + foreach ($potEntries as $key => $entry) { |
|
75 | + $entries[html_entity_decode($key, ENT_COMPAT, 'UTF-8')] = $entry; |
|
76 | + } |
|
77 | + } catch (Exception $e) { |
|
78 | + glsr_log()->error($e->getMessage()); |
|
79 | + } |
|
80 | + return $entries; |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * @param array|null $filterWith |
|
85 | - * @param array|null $entries |
|
86 | - * @param bool $intersect |
|
87 | - * @return static |
|
88 | - */ |
|
89 | - public function filter($filterWith = null, $entries = null, $intersect = true) |
|
90 | - { |
|
91 | - if (!is_array($entries)) { |
|
92 | - $entries = $this->results; |
|
93 | - } |
|
94 | - if (!is_array($filterWith)) { |
|
95 | - $filterWith = $this->translations(); |
|
96 | - } |
|
97 | - $keys = array_flip(glsr_array_column($filterWith, 'id')); |
|
98 | - $this->results = $intersect |
|
99 | - ? array_intersect_key($entries, $keys) |
|
100 | - : array_diff_key($entries, $keys); |
|
101 | - return $this; |
|
102 | - } |
|
83 | + /** |
|
84 | + * @param array|null $filterWith |
|
85 | + * @param array|null $entries |
|
86 | + * @param bool $intersect |
|
87 | + * @return static |
|
88 | + */ |
|
89 | + public function filter($filterWith = null, $entries = null, $intersect = true) |
|
90 | + { |
|
91 | + if (!is_array($entries)) { |
|
92 | + $entries = $this->results; |
|
93 | + } |
|
94 | + if (!is_array($filterWith)) { |
|
95 | + $filterWith = $this->translations(); |
|
96 | + } |
|
97 | + $keys = array_flip(glsr_array_column($filterWith, 'id')); |
|
98 | + $this->results = $intersect |
|
99 | + ? array_intersect_key($entries, $keys) |
|
100 | + : array_diff_key($entries, $keys); |
|
101 | + return $this; |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
105 | - * @param string $template |
|
106 | - * @return string |
|
107 | - */ |
|
108 | - public function render($template, array $entry) |
|
109 | - { |
|
110 | - $data = array_combine( |
|
111 | - array_map(function ($key) { return 'data.'.$key; }, array_keys($entry)), |
|
112 | - $entry |
|
113 | - ); |
|
114 | - $data['data.class'] = $data['data.error'] = ''; |
|
115 | - if (false === array_search($entry['s1'], glsr_array_column($this->entries(), 'msgid'))) { |
|
116 | - $data['data.class'] = 'is-invalid'; |
|
117 | - $data['data.error'] = __('This custom translation is no longer valid as the original text has been changed or removed.', 'site-reviews'); |
|
118 | - } |
|
119 | - return glsr(Template::class)->build('partials/translations/'.$template, [ |
|
120 | - 'context' => array_map('esc_html', $data), |
|
121 | - ]); |
|
122 | - } |
|
104 | + /** |
|
105 | + * @param string $template |
|
106 | + * @return string |
|
107 | + */ |
|
108 | + public function render($template, array $entry) |
|
109 | + { |
|
110 | + $data = array_combine( |
|
111 | + array_map(function ($key) { return 'data.'.$key; }, array_keys($entry)), |
|
112 | + $entry |
|
113 | + ); |
|
114 | + $data['data.class'] = $data['data.error'] = ''; |
|
115 | + if (false === array_search($entry['s1'], glsr_array_column($this->entries(), 'msgid'))) { |
|
116 | + $data['data.class'] = 'is-invalid'; |
|
117 | + $data['data.error'] = __('This custom translation is no longer valid as the original text has been changed or removed.', 'site-reviews'); |
|
118 | + } |
|
119 | + return glsr(Template::class)->build('partials/translations/'.$template, [ |
|
120 | + 'context' => array_map('esc_html', $data), |
|
121 | + ]); |
|
122 | + } |
|
123 | 123 | |
124 | - /** |
|
125 | - * Returns a rendered string of all saved custom translations with translation context. |
|
126 | - * @return string |
|
127 | - */ |
|
128 | - public function renderAll() |
|
129 | - { |
|
130 | - $rendered = ''; |
|
131 | - foreach ($this->all() as $index => $entry) { |
|
132 | - $entry['index'] = $index; |
|
133 | - $entry['prefix'] = OptionManager::databaseKey(); |
|
134 | - $rendered.= $this->render($entry['type'], $entry); |
|
135 | - } |
|
136 | - return $rendered; |
|
137 | - } |
|
124 | + /** |
|
125 | + * Returns a rendered string of all saved custom translations with translation context. |
|
126 | + * @return string |
|
127 | + */ |
|
128 | + public function renderAll() |
|
129 | + { |
|
130 | + $rendered = ''; |
|
131 | + foreach ($this->all() as $index => $entry) { |
|
132 | + $entry['index'] = $index; |
|
133 | + $entry['prefix'] = OptionManager::databaseKey(); |
|
134 | + $rendered.= $this->render($entry['type'], $entry); |
|
135 | + } |
|
136 | + return $rendered; |
|
137 | + } |
|
138 | 138 | |
139 | - /** |
|
140 | - * @param bool $resetAfterRender |
|
141 | - * @return string |
|
142 | - */ |
|
143 | - public function renderResults($resetAfterRender = true) |
|
144 | - { |
|
145 | - $rendered = ''; |
|
146 | - foreach ($this->results as $id => $entry) { |
|
147 | - $data = [ |
|
148 | - 'desc' => $this->getEntryString($entry, 'msgctxt'), |
|
149 | - 'id' => $id, |
|
150 | - 'p1' => $this->getEntryString($entry, 'msgid_plural'), |
|
151 | - 's1' => $this->getEntryString($entry, 'msgid'), |
|
152 | - ]; |
|
153 | - $text = !empty($data['p1']) |
|
154 | - ? sprintf('%s | %s', $data['s1'], $data['p1']) |
|
155 | - : $data['s1']; |
|
156 | - $rendered.= $this->render('result', [ |
|
157 | - 'entry' => json_encode($data, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), |
|
158 | - 'text' => wp_strip_all_tags($text), |
|
159 | - ]); |
|
160 | - } |
|
161 | - if ($resetAfterRender) { |
|
162 | - $this->reset(); |
|
163 | - } |
|
164 | - return $rendered; |
|
165 | - } |
|
139 | + /** |
|
140 | + * @param bool $resetAfterRender |
|
141 | + * @return string |
|
142 | + */ |
|
143 | + public function renderResults($resetAfterRender = true) |
|
144 | + { |
|
145 | + $rendered = ''; |
|
146 | + foreach ($this->results as $id => $entry) { |
|
147 | + $data = [ |
|
148 | + 'desc' => $this->getEntryString($entry, 'msgctxt'), |
|
149 | + 'id' => $id, |
|
150 | + 'p1' => $this->getEntryString($entry, 'msgid_plural'), |
|
151 | + 's1' => $this->getEntryString($entry, 'msgid'), |
|
152 | + ]; |
|
153 | + $text = !empty($data['p1']) |
|
154 | + ? sprintf('%s | %s', $data['s1'], $data['p1']) |
|
155 | + : $data['s1']; |
|
156 | + $rendered.= $this->render('result', [ |
|
157 | + 'entry' => json_encode($data, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), |
|
158 | + 'text' => wp_strip_all_tags($text), |
|
159 | + ]); |
|
160 | + } |
|
161 | + if ($resetAfterRender) { |
|
162 | + $this->reset(); |
|
163 | + } |
|
164 | + return $rendered; |
|
165 | + } |
|
166 | 166 | |
167 | - /** |
|
168 | - * @return void |
|
169 | - */ |
|
170 | - public function reset() |
|
171 | - { |
|
172 | - $this->results = []; |
|
173 | - } |
|
167 | + /** |
|
168 | + * @return void |
|
169 | + */ |
|
170 | + public function reset() |
|
171 | + { |
|
172 | + $this->results = []; |
|
173 | + } |
|
174 | 174 | |
175 | - /** |
|
176 | - * @return array |
|
177 | - */ |
|
178 | - public function results() |
|
179 | - { |
|
180 | - $results = $this->results; |
|
181 | - $this->reset(); |
|
182 | - return $results; |
|
183 | - } |
|
175 | + /** |
|
176 | + * @return array |
|
177 | + */ |
|
178 | + public function results() |
|
179 | + { |
|
180 | + $results = $this->results; |
|
181 | + $this->reset(); |
|
182 | + return $results; |
|
183 | + } |
|
184 | 184 | |
185 | - /** |
|
186 | - * @param string $needle |
|
187 | - * @return static |
|
188 | - */ |
|
189 | - public function search($needle = '') |
|
190 | - { |
|
191 | - $this->reset(); |
|
192 | - $needle = trim(strtolower($needle)); |
|
193 | - foreach ($this->entries() as $key => $entry) { |
|
194 | - $single = strtolower($this->getEntryString($entry, 'msgid')); |
|
195 | - $plural = strtolower($this->getEntryString($entry, 'msgid_plural')); |
|
196 | - if (strlen($needle) < static::SEARCH_THRESHOLD) { |
|
197 | - if (in_array($needle, [$single, $plural])) { |
|
198 | - $this->results[$key] = $entry; |
|
199 | - } |
|
200 | - } elseif (Str::contains(sprintf('%s %s', $single, $plural), $needle)) { |
|
201 | - $this->results[$key] = $entry; |
|
202 | - } |
|
203 | - } |
|
204 | - return $this; |
|
205 | - } |
|
185 | + /** |
|
186 | + * @param string $needle |
|
187 | + * @return static |
|
188 | + */ |
|
189 | + public function search($needle = '') |
|
190 | + { |
|
191 | + $this->reset(); |
|
192 | + $needle = trim(strtolower($needle)); |
|
193 | + foreach ($this->entries() as $key => $entry) { |
|
194 | + $single = strtolower($this->getEntryString($entry, 'msgid')); |
|
195 | + $plural = strtolower($this->getEntryString($entry, 'msgid_plural')); |
|
196 | + if (strlen($needle) < static::SEARCH_THRESHOLD) { |
|
197 | + if (in_array($needle, [$single, $plural])) { |
|
198 | + $this->results[$key] = $entry; |
|
199 | + } |
|
200 | + } elseif (Str::contains(sprintf('%s %s', $single, $plural), $needle)) { |
|
201 | + $this->results[$key] = $entry; |
|
202 | + } |
|
203 | + } |
|
204 | + return $this; |
|
205 | + } |
|
206 | 206 | |
207 | - /** |
|
208 | - * Store the translations to avoid unnecessary loops. |
|
209 | - * @return array |
|
210 | - */ |
|
211 | - public function translations() |
|
212 | - { |
|
213 | - static $translations; |
|
214 | - if (empty($translations)) { |
|
215 | - $settings = glsr(OptionManager::class)->get('settings'); |
|
216 | - $translations = isset($settings['strings']) |
|
217 | - ? $this->normalizeSettings((array) $settings['strings']) |
|
218 | - : []; |
|
219 | - } |
|
220 | - return $translations; |
|
221 | - } |
|
207 | + /** |
|
208 | + * Store the translations to avoid unnecessary loops. |
|
209 | + * @return array |
|
210 | + */ |
|
211 | + public function translations() |
|
212 | + { |
|
213 | + static $translations; |
|
214 | + if (empty($translations)) { |
|
215 | + $settings = glsr(OptionManager::class)->get('settings'); |
|
216 | + $translations = isset($settings['strings']) |
|
217 | + ? $this->normalizeSettings((array) $settings['strings']) |
|
218 | + : []; |
|
219 | + } |
|
220 | + return $translations; |
|
221 | + } |
|
222 | 222 | |
223 | - /** |
|
224 | - * @param string $key |
|
225 | - * @return string |
|
226 | - */ |
|
227 | - protected function getEntryString(array $entry, $key) |
|
228 | - { |
|
229 | - return isset($entry[$key]) |
|
230 | - ? implode('', (array) $entry[$key]) |
|
231 | - : ''; |
|
232 | - } |
|
223 | + /** |
|
224 | + * @param string $key |
|
225 | + * @return string |
|
226 | + */ |
|
227 | + protected function getEntryString(array $entry, $key) |
|
228 | + { |
|
229 | + return isset($entry[$key]) |
|
230 | + ? implode('', (array) $entry[$key]) |
|
231 | + : ''; |
|
232 | + } |
|
233 | 233 | |
234 | - /** |
|
235 | - * @return array |
|
236 | - */ |
|
237 | - protected function normalize(array $entries) |
|
238 | - { |
|
239 | - $keys = [ |
|
240 | - 'msgctxt', 'msgid', 'msgid_plural', 'msgstr', 'msgstr[0]', 'msgstr[1]', |
|
241 | - ]; |
|
242 | - array_walk($entries, function (&$entry) use ($keys) { |
|
243 | - foreach ($keys as $key) { |
|
244 | - try { |
|
245 | - $entry = $this->normalizeEntryString($entry, $key); |
|
246 | - } catch (\TypeError $error) { |
|
247 | - glsr_log()->once('error', 'Translation/normalize', $error); |
|
248 | - glsr_log()->once('debug', 'Translation/normalize', $entry); |
|
249 | - } |
|
250 | - } |
|
251 | - }); |
|
252 | - return $entries; |
|
253 | - } |
|
234 | + /** |
|
235 | + * @return array |
|
236 | + */ |
|
237 | + protected function normalize(array $entries) |
|
238 | + { |
|
239 | + $keys = [ |
|
240 | + 'msgctxt', 'msgid', 'msgid_plural', 'msgstr', 'msgstr[0]', 'msgstr[1]', |
|
241 | + ]; |
|
242 | + array_walk($entries, function (&$entry) use ($keys) { |
|
243 | + foreach ($keys as $key) { |
|
244 | + try { |
|
245 | + $entry = $this->normalizeEntryString($entry, $key); |
|
246 | + } catch (\TypeError $error) { |
|
247 | + glsr_log()->once('error', 'Translation/normalize', $error); |
|
248 | + glsr_log()->once('debug', 'Translation/normalize', $entry); |
|
249 | + } |
|
250 | + } |
|
251 | + }); |
|
252 | + return $entries; |
|
253 | + } |
|
254 | 254 | |
255 | - /** |
|
256 | - * @param string $key |
|
257 | - * @return array |
|
258 | - */ |
|
259 | - protected function normalizeEntryString(array $entry, $key) |
|
260 | - { |
|
261 | - if (isset($entry[$key])) { |
|
262 | - $entry[$key] = $this->getEntryString($entry, $key); |
|
263 | - } |
|
264 | - return $entry; |
|
265 | - } |
|
255 | + /** |
|
256 | + * @param string $key |
|
257 | + * @return array |
|
258 | + */ |
|
259 | + protected function normalizeEntryString(array $entry, $key) |
|
260 | + { |
|
261 | + if (isset($entry[$key])) { |
|
262 | + $entry[$key] = $this->getEntryString($entry, $key); |
|
263 | + } |
|
264 | + return $entry; |
|
265 | + } |
|
266 | 266 | |
267 | - /** |
|
268 | - * @return array |
|
269 | - */ |
|
270 | - protected function normalizeSettings(array $strings) |
|
271 | - { |
|
272 | - $defaultString = array_fill_keys(['id', 's1', 's2', 'p1', 'p2'], ''); |
|
273 | - $strings = array_filter($strings, 'is_array'); |
|
274 | - foreach ($strings as &$string) { |
|
275 | - $string['type'] = isset($string['p1']) ? 'plural' : 'single'; |
|
276 | - $string = wp_parse_args($string, $defaultString); |
|
277 | - } |
|
278 | - return array_filter($strings, function ($string) { |
|
279 | - return !empty($string['id']); |
|
280 | - }); |
|
281 | - } |
|
267 | + /** |
|
268 | + * @return array |
|
269 | + */ |
|
270 | + protected function normalizeSettings(array $strings) |
|
271 | + { |
|
272 | + $defaultString = array_fill_keys(['id', 's1', 's2', 'p1', 'p2'], ''); |
|
273 | + $strings = array_filter($strings, 'is_array'); |
|
274 | + foreach ($strings as &$string) { |
|
275 | + $string['type'] = isset($string['p1']) ? 'plural' : 'single'; |
|
276 | + $string = wp_parse_args($string, $defaultString); |
|
277 | + } |
|
278 | + return array_filter($strings, function ($string) { |
|
279 | + return !empty($string['id']); |
|
280 | + }); |
|
281 | + } |
|
282 | 282 | } |
@@ -30,10 +30,10 @@ discard block |
||
30 | 30 | public function all() |
31 | 31 | { |
32 | 32 | $translations = $this->translations(); |
33 | - $entries = $this->filter($translations, $this->entries())->results(); |
|
34 | - array_walk($translations, function (&$entry) use ($entries) { |
|
35 | - $entry['desc'] = array_key_exists($entry['id'], $entries) |
|
36 | - ? $this->getEntryString($entries[$entry['id']], 'msgctxt') |
|
33 | + $entries = $this->filter( $translations, $this->entries() )->results(); |
|
34 | + array_walk( $translations, function( &$entry ) use ($entries) { |
|
35 | + $entry['desc'] = array_key_exists( $entry['id'], $entries ) |
|
36 | + ? $this->getEntryString( $entries[$entry['id']], 'msgctxt' ) |
|
37 | 37 | : ''; |
38 | 38 | }); |
39 | 39 | return $translations; |
@@ -44,10 +44,10 @@ discard block |
||
44 | 44 | */ |
45 | 45 | public function entries() |
46 | 46 | { |
47 | - if (!isset($this->entries)) { |
|
48 | - $potFile = glsr()->path(glsr()->languages.'/'.Application::ID.'.pot'); |
|
49 | - $entries = $this->extractEntriesFromPotFile($potFile); |
|
50 | - $entries = apply_filters('site-reviews/translation/entries', $entries); |
|
47 | + if( !isset($this->entries) ) { |
|
48 | + $potFile = glsr()->path( glsr()->languages.'/'.Application::ID.'.pot' ); |
|
49 | + $entries = $this->extractEntriesFromPotFile( $potFile ); |
|
50 | + $entries = apply_filters( 'site-reviews/translation/entries', $entries ); |
|
51 | 51 | $this->entries = $entries; |
52 | 52 | } |
53 | 53 | return $this->entries; |
@@ -58,24 +58,24 @@ discard block |
||
58 | 58 | * @param array|null $entries |
59 | 59 | * @return static |
60 | 60 | */ |
61 | - public function exclude($entriesToExclude = null, $entries = null) |
|
61 | + public function exclude( $entriesToExclude = null, $entries = null ) |
|
62 | 62 | { |
63 | - return $this->filter($entriesToExclude, $entries, false); |
|
63 | + return $this->filter( $entriesToExclude, $entries, false ); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
67 | 67 | * @param string $potFile |
68 | 68 | * @return array |
69 | 69 | */ |
70 | - public function extractEntriesFromPotFile($potFile, array $entries = []) |
|
70 | + public function extractEntriesFromPotFile( $potFile, array $entries = [] ) |
|
71 | 71 | { |
72 | 72 | try { |
73 | - $potEntries = $this->normalize(Parser::parseFile($potFile)->getEntries()); |
|
74 | - foreach ($potEntries as $key => $entry) { |
|
75 | - $entries[html_entity_decode($key, ENT_COMPAT, 'UTF-8')] = $entry; |
|
73 | + $potEntries = $this->normalize( Parser::parseFile( $potFile )->getEntries() ); |
|
74 | + foreach( $potEntries as $key => $entry ) { |
|
75 | + $entries[html_entity_decode( $key, ENT_COMPAT, 'UTF-8' )] = $entry; |
|
76 | 76 | } |
77 | - } catch (Exception $e) { |
|
78 | - glsr_log()->error($e->getMessage()); |
|
77 | + } catch( Exception $e ) { |
|
78 | + glsr_log()->error( $e->getMessage() ); |
|
79 | 79 | } |
80 | 80 | return $entries; |
81 | 81 | } |
@@ -86,18 +86,18 @@ discard block |
||
86 | 86 | * @param bool $intersect |
87 | 87 | * @return static |
88 | 88 | */ |
89 | - public function filter($filterWith = null, $entries = null, $intersect = true) |
|
89 | + public function filter( $filterWith = null, $entries = null, $intersect = true ) |
|
90 | 90 | { |
91 | - if (!is_array($entries)) { |
|
91 | + if( !is_array( $entries ) ) { |
|
92 | 92 | $entries = $this->results; |
93 | 93 | } |
94 | - if (!is_array($filterWith)) { |
|
94 | + if( !is_array( $filterWith ) ) { |
|
95 | 95 | $filterWith = $this->translations(); |
96 | 96 | } |
97 | - $keys = array_flip(glsr_array_column($filterWith, 'id')); |
|
97 | + $keys = array_flip( glsr_array_column( $filterWith, 'id' ) ); |
|
98 | 98 | $this->results = $intersect |
99 | - ? array_intersect_key($entries, $keys) |
|
100 | - : array_diff_key($entries, $keys); |
|
99 | + ? array_intersect_key( $entries, $keys ) |
|
100 | + : array_diff_key( $entries, $keys ); |
|
101 | 101 | return $this; |
102 | 102 | } |
103 | 103 | |
@@ -105,20 +105,20 @@ discard block |
||
105 | 105 | * @param string $template |
106 | 106 | * @return string |
107 | 107 | */ |
108 | - public function render($template, array $entry) |
|
108 | + public function render( $template, array $entry ) |
|
109 | 109 | { |
110 | 110 | $data = array_combine( |
111 | - array_map(function ($key) { return 'data.'.$key; }, array_keys($entry)), |
|
111 | + array_map( function( $key ) { return 'data.'.$key; }, array_keys( $entry ) ), |
|
112 | 112 | $entry |
113 | 113 | ); |
114 | 114 | $data['data.class'] = $data['data.error'] = ''; |
115 | - if (false === array_search($entry['s1'], glsr_array_column($this->entries(), 'msgid'))) { |
|
115 | + if( false === array_search( $entry['s1'], glsr_array_column( $this->entries(), 'msgid' ) ) ) { |
|
116 | 116 | $data['data.class'] = 'is-invalid'; |
117 | - $data['data.error'] = __('This custom translation is no longer valid as the original text has been changed or removed.', 'site-reviews'); |
|
117 | + $data['data.error'] = __( 'This custom translation is no longer valid as the original text has been changed or removed.', 'site-reviews' ); |
|
118 | 118 | } |
119 | - return glsr(Template::class)->build('partials/translations/'.$template, [ |
|
120 | - 'context' => array_map('esc_html', $data), |
|
121 | - ]); |
|
119 | + return glsr( Template::class )->build( 'partials/translations/'.$template, [ |
|
120 | + 'context' => array_map( 'esc_html', $data ), |
|
121 | + ] ); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
@@ -128,10 +128,10 @@ discard block |
||
128 | 128 | public function renderAll() |
129 | 129 | { |
130 | 130 | $rendered = ''; |
131 | - foreach ($this->all() as $index => $entry) { |
|
131 | + foreach( $this->all() as $index => $entry ) { |
|
132 | 132 | $entry['index'] = $index; |
133 | 133 | $entry['prefix'] = OptionManager::databaseKey(); |
134 | - $rendered.= $this->render($entry['type'], $entry); |
|
134 | + $rendered .= $this->render( $entry['type'], $entry ); |
|
135 | 135 | } |
136 | 136 | return $rendered; |
137 | 137 | } |
@@ -140,25 +140,25 @@ discard block |
||
140 | 140 | * @param bool $resetAfterRender |
141 | 141 | * @return string |
142 | 142 | */ |
143 | - public function renderResults($resetAfterRender = true) |
|
143 | + public function renderResults( $resetAfterRender = true ) |
|
144 | 144 | { |
145 | 145 | $rendered = ''; |
146 | - foreach ($this->results as $id => $entry) { |
|
146 | + foreach( $this->results as $id => $entry ) { |
|
147 | 147 | $data = [ |
148 | - 'desc' => $this->getEntryString($entry, 'msgctxt'), |
|
148 | + 'desc' => $this->getEntryString( $entry, 'msgctxt' ), |
|
149 | 149 | 'id' => $id, |
150 | - 'p1' => $this->getEntryString($entry, 'msgid_plural'), |
|
151 | - 's1' => $this->getEntryString($entry, 'msgid'), |
|
150 | + 'p1' => $this->getEntryString( $entry, 'msgid_plural' ), |
|
151 | + 's1' => $this->getEntryString( $entry, 'msgid' ), |
|
152 | 152 | ]; |
153 | 153 | $text = !empty($data['p1']) |
154 | - ? sprintf('%s | %s', $data['s1'], $data['p1']) |
|
154 | + ? sprintf( '%s | %s', $data['s1'], $data['p1'] ) |
|
155 | 155 | : $data['s1']; |
156 | - $rendered.= $this->render('result', [ |
|
157 | - 'entry' => json_encode($data, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), |
|
158 | - 'text' => wp_strip_all_tags($text), |
|
159 | - ]); |
|
156 | + $rendered .= $this->render( 'result', [ |
|
157 | + 'entry' => json_encode( $data, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ), |
|
158 | + 'text' => wp_strip_all_tags( $text ), |
|
159 | + ] ); |
|
160 | 160 | } |
161 | - if ($resetAfterRender) { |
|
161 | + if( $resetAfterRender ) { |
|
162 | 162 | $this->reset(); |
163 | 163 | } |
164 | 164 | return $rendered; |
@@ -186,18 +186,18 @@ discard block |
||
186 | 186 | * @param string $needle |
187 | 187 | * @return static |
188 | 188 | */ |
189 | - public function search($needle = '') |
|
189 | + public function search( $needle = '' ) |
|
190 | 190 | { |
191 | 191 | $this->reset(); |
192 | - $needle = trim(strtolower($needle)); |
|
193 | - foreach ($this->entries() as $key => $entry) { |
|
194 | - $single = strtolower($this->getEntryString($entry, 'msgid')); |
|
195 | - $plural = strtolower($this->getEntryString($entry, 'msgid_plural')); |
|
196 | - if (strlen($needle) < static::SEARCH_THRESHOLD) { |
|
197 | - if (in_array($needle, [$single, $plural])) { |
|
192 | + $needle = trim( strtolower( $needle ) ); |
|
193 | + foreach( $this->entries() as $key => $entry ) { |
|
194 | + $single = strtolower( $this->getEntryString( $entry, 'msgid' ) ); |
|
195 | + $plural = strtolower( $this->getEntryString( $entry, 'msgid_plural' ) ); |
|
196 | + if( strlen( $needle ) < static::SEARCH_THRESHOLD ) { |
|
197 | + if( in_array( $needle, [$single, $plural] ) ) { |
|
198 | 198 | $this->results[$key] = $entry; |
199 | 199 | } |
200 | - } elseif (Str::contains(sprintf('%s %s', $single, $plural), $needle)) { |
|
200 | + } elseif( Str::contains( sprintf( '%s %s', $single, $plural ), $needle ) ) { |
|
201 | 201 | $this->results[$key] = $entry; |
202 | 202 | } |
203 | 203 | } |
@@ -211,10 +211,10 @@ discard block |
||
211 | 211 | public function translations() |
212 | 212 | { |
213 | 213 | static $translations; |
214 | - if (empty($translations)) { |
|
215 | - $settings = glsr(OptionManager::class)->get('settings'); |
|
214 | + if( empty($translations) ) { |
|
215 | + $settings = glsr( OptionManager::class )->get( 'settings' ); |
|
216 | 216 | $translations = isset($settings['strings']) |
217 | - ? $this->normalizeSettings((array) $settings['strings']) |
|
217 | + ? $this->normalizeSettings( (array)$settings['strings'] ) |
|
218 | 218 | : []; |
219 | 219 | } |
220 | 220 | return $translations; |
@@ -224,28 +224,28 @@ discard block |
||
224 | 224 | * @param string $key |
225 | 225 | * @return string |
226 | 226 | */ |
227 | - protected function getEntryString(array $entry, $key) |
|
227 | + protected function getEntryString( array $entry, $key ) |
|
228 | 228 | { |
229 | 229 | return isset($entry[$key]) |
230 | - ? implode('', (array) $entry[$key]) |
|
230 | + ? implode( '', (array)$entry[$key] ) |
|
231 | 231 | : ''; |
232 | 232 | } |
233 | 233 | |
234 | 234 | /** |
235 | 235 | * @return array |
236 | 236 | */ |
237 | - protected function normalize(array $entries) |
|
237 | + protected function normalize( array $entries ) |
|
238 | 238 | { |
239 | 239 | $keys = [ |
240 | 240 | 'msgctxt', 'msgid', 'msgid_plural', 'msgstr', 'msgstr[0]', 'msgstr[1]', |
241 | 241 | ]; |
242 | - array_walk($entries, function (&$entry) use ($keys) { |
|
243 | - foreach ($keys as $key) { |
|
242 | + array_walk( $entries, function( &$entry ) use ($keys) { |
|
243 | + foreach( $keys as $key ) { |
|
244 | 244 | try { |
245 | - $entry = $this->normalizeEntryString($entry, $key); |
|
246 | - } catch (\TypeError $error) { |
|
247 | - glsr_log()->once('error', 'Translation/normalize', $error); |
|
248 | - glsr_log()->once('debug', 'Translation/normalize', $entry); |
|
245 | + $entry = $this->normalizeEntryString( $entry, $key ); |
|
246 | + } catch( \TypeError $error ) { |
|
247 | + glsr_log()->once( 'error', 'Translation/normalize', $error ); |
|
248 | + glsr_log()->once( 'debug', 'Translation/normalize', $entry ); |
|
249 | 249 | } |
250 | 250 | } |
251 | 251 | }); |
@@ -256,10 +256,10 @@ discard block |
||
256 | 256 | * @param string $key |
257 | 257 | * @return array |
258 | 258 | */ |
259 | - protected function normalizeEntryString(array $entry, $key) |
|
259 | + protected function normalizeEntryString( array $entry, $key ) |
|
260 | 260 | { |
261 | - if (isset($entry[$key])) { |
|
262 | - $entry[$key] = $this->getEntryString($entry, $key); |
|
261 | + if( isset($entry[$key]) ) { |
|
262 | + $entry[$key] = $this->getEntryString( $entry, $key ); |
|
263 | 263 | } |
264 | 264 | return $entry; |
265 | 265 | } |
@@ -267,15 +267,15 @@ discard block |
||
267 | 267 | /** |
268 | 268 | * @return array |
269 | 269 | */ |
270 | - protected function normalizeSettings(array $strings) |
|
270 | + protected function normalizeSettings( array $strings ) |
|
271 | 271 | { |
272 | - $defaultString = array_fill_keys(['id', 's1', 's2', 'p1', 'p2'], ''); |
|
273 | - $strings = array_filter($strings, 'is_array'); |
|
274 | - foreach ($strings as &$string) { |
|
272 | + $defaultString = array_fill_keys( ['id', 's1', 's2', 'p1', 'p2'], '' ); |
|
273 | + $strings = array_filter( $strings, 'is_array' ); |
|
274 | + foreach( $strings as &$string ) { |
|
275 | 275 | $string['type'] = isset($string['p1']) ? 'plural' : 'single'; |
276 | - $string = wp_parse_args($string, $defaultString); |
|
276 | + $string = wp_parse_args( $string, $defaultString ); |
|
277 | 277 | } |
278 | - return array_filter($strings, function ($string) { |
|
278 | + return array_filter( $strings, function( $string ) { |
|
279 | 279 | return !empty($string['id']); |
280 | 280 | }); |
281 | 281 | } |
@@ -74,7 +74,8 @@ discard block |
||
74 | 74 | foreach ($potEntries as $key => $entry) { |
75 | 75 | $entries[html_entity_decode($key, ENT_COMPAT, 'UTF-8')] = $entry; |
76 | 76 | } |
77 | - } catch (Exception $e) { |
|
77 | + } |
|
78 | + catch (Exception $e) { |
|
78 | 79 | glsr_log()->error($e->getMessage()); |
79 | 80 | } |
80 | 81 | return $entries; |
@@ -197,7 +198,8 @@ discard block |
||
197 | 198 | if (in_array($needle, [$single, $plural])) { |
198 | 199 | $this->results[$key] = $entry; |
199 | 200 | } |
200 | - } elseif (Str::contains(sprintf('%s %s', $single, $plural), $needle)) { |
|
201 | + } |
|
202 | + elseif (Str::contains(sprintf('%s %s', $single, $plural), $needle)) { |
|
201 | 203 | $this->results[$key] = $entry; |
202 | 204 | } |
203 | 205 | } |
@@ -243,7 +245,8 @@ discard block |
||
243 | 245 | foreach ($keys as $key) { |
244 | 246 | try { |
245 | 247 | $entry = $this->normalizeEntryString($entry, $key); |
246 | - } catch (\TypeError $error) { |
|
248 | + } |
|
249 | + catch (\TypeError $error) { |
|
247 | 250 | glsr_log()->once('error', 'Translation/normalize', $error); |
248 | 251 | glsr_log()->once('debug', 'Translation/normalize', $entry); |
249 | 252 | } |
@@ -6,97 +6,97 @@ |
||
6 | 6 | |
7 | 7 | class Translator |
8 | 8 | { |
9 | - /** |
|
10 | - * @param string $original |
|
11 | - * @param string $domain |
|
12 | - * @return string |
|
13 | - */ |
|
14 | - public function translate($original, $domain, array $args) |
|
15 | - { |
|
16 | - $domains = apply_filters('site-reviews/translator/domains', [Application::ID]); |
|
17 | - if (!in_array($domain, $domains)) { |
|
18 | - return $original; |
|
19 | - } |
|
20 | - $args = $this->normalizeTranslationArgs($args); |
|
21 | - $strings = $this->getTranslationStrings($args['single'], $args['plural']); |
|
22 | - if (empty($strings)) { |
|
23 | - return $original; |
|
24 | - } |
|
25 | - $string = current($strings); |
|
26 | - return 'plural' == $string['type'] |
|
27 | - ? $this->translatePlural($domain, $string, $args) |
|
28 | - : $this->translateSingle($domain, $string, $args); |
|
29 | - } |
|
9 | + /** |
|
10 | + * @param string $original |
|
11 | + * @param string $domain |
|
12 | + * @return string |
|
13 | + */ |
|
14 | + public function translate($original, $domain, array $args) |
|
15 | + { |
|
16 | + $domains = apply_filters('site-reviews/translator/domains', [Application::ID]); |
|
17 | + if (!in_array($domain, $domains)) { |
|
18 | + return $original; |
|
19 | + } |
|
20 | + $args = $this->normalizeTranslationArgs($args); |
|
21 | + $strings = $this->getTranslationStrings($args['single'], $args['plural']); |
|
22 | + if (empty($strings)) { |
|
23 | + return $original; |
|
24 | + } |
|
25 | + $string = current($strings); |
|
26 | + return 'plural' == $string['type'] |
|
27 | + ? $this->translatePlural($domain, $string, $args) |
|
28 | + : $this->translateSingle($domain, $string, $args); |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * Used when search/replacing a default text-domain translation |
|
33 | - * @return string |
|
34 | - */ |
|
35 | - public function getTranslation(array $args) |
|
36 | - { |
|
37 | - $args = $this->normalizeTranslationArgs($args); |
|
38 | - return get_translations_for_domain(Application::ID)->translate_plural($args['single'], $args['plural'], $args['number']); |
|
39 | - } |
|
31 | + /** |
|
32 | + * Used when search/replacing a default text-domain translation |
|
33 | + * @return string |
|
34 | + */ |
|
35 | + public function getTranslation(array $args) |
|
36 | + { |
|
37 | + $args = $this->normalizeTranslationArgs($args); |
|
38 | + return get_translations_for_domain(Application::ID)->translate_plural($args['single'], $args['plural'], $args['number']); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * @param string $single |
|
43 | - * @param string $plural |
|
44 | - * @return array |
|
45 | - */ |
|
46 | - protected function getTranslationStrings($single, $plural) |
|
47 | - { |
|
48 | - return array_filter(glsr(Translation::class)->translations(), function ($string) use ($single, $plural) { |
|
49 | - return $string['s1'] == html_entity_decode($single, ENT_COMPAT, 'UTF-8') |
|
50 | - && $string['p1'] == html_entity_decode($plural, ENT_COMPAT, 'UTF-8'); |
|
51 | - }); |
|
52 | - } |
|
41 | + /** |
|
42 | + * @param string $single |
|
43 | + * @param string $plural |
|
44 | + * @return array |
|
45 | + */ |
|
46 | + protected function getTranslationStrings($single, $plural) |
|
47 | + { |
|
48 | + return array_filter(glsr(Translation::class)->translations(), function ($string) use ($single, $plural) { |
|
49 | + return $string['s1'] == html_entity_decode($single, ENT_COMPAT, 'UTF-8') |
|
50 | + && $string['p1'] == html_entity_decode($plural, ENT_COMPAT, 'UTF-8'); |
|
51 | + }); |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * @return array |
|
56 | - */ |
|
57 | - protected function normalizeTranslationArgs(array $args) |
|
58 | - { |
|
59 | - $defaults = [ |
|
60 | - 'context' => '', |
|
61 | - 'number' => 1, |
|
62 | - 'plural' => '', |
|
63 | - 'single' => '', |
|
64 | - ]; |
|
65 | - return shortcode_atts($defaults, $args); |
|
66 | - } |
|
54 | + /** |
|
55 | + * @return array |
|
56 | + */ |
|
57 | + protected function normalizeTranslationArgs(array $args) |
|
58 | + { |
|
59 | + $defaults = [ |
|
60 | + 'context' => '', |
|
61 | + 'number' => 1, |
|
62 | + 'plural' => '', |
|
63 | + 'single' => '', |
|
64 | + ]; |
|
65 | + return shortcode_atts($defaults, $args); |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @param string $domain |
|
70 | - * @return string |
|
71 | - */ |
|
72 | - protected function translatePlural($domain, array $string, array $args) |
|
73 | - { |
|
74 | - if (!empty($string['s2'])) { |
|
75 | - $args['single'] = $string['s2']; |
|
76 | - } |
|
77 | - if (!empty($string['p2'])) { |
|
78 | - $args['plural'] = $string['p2']; |
|
79 | - } |
|
80 | - return get_translations_for_domain($domain)->translate_plural( |
|
81 | - $args['single'], |
|
82 | - $args['plural'], |
|
83 | - $args['number'], |
|
84 | - $args['context'] |
|
85 | - ); |
|
86 | - } |
|
68 | + /** |
|
69 | + * @param string $domain |
|
70 | + * @return string |
|
71 | + */ |
|
72 | + protected function translatePlural($domain, array $string, array $args) |
|
73 | + { |
|
74 | + if (!empty($string['s2'])) { |
|
75 | + $args['single'] = $string['s2']; |
|
76 | + } |
|
77 | + if (!empty($string['p2'])) { |
|
78 | + $args['plural'] = $string['p2']; |
|
79 | + } |
|
80 | + return get_translations_for_domain($domain)->translate_plural( |
|
81 | + $args['single'], |
|
82 | + $args['plural'], |
|
83 | + $args['number'], |
|
84 | + $args['context'] |
|
85 | + ); |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * @param string $domain |
|
90 | - * @return string |
|
91 | - */ |
|
92 | - protected function translateSingle($domain, array $string, array $args) |
|
93 | - { |
|
94 | - if (!empty($string['s2'])) { |
|
95 | - $args['single'] = $string['s2']; |
|
96 | - } |
|
97 | - return get_translations_for_domain($domain)->translate( |
|
98 | - $args['single'], |
|
99 | - $args['context'] |
|
100 | - ); |
|
101 | - } |
|
88 | + /** |
|
89 | + * @param string $domain |
|
90 | + * @return string |
|
91 | + */ |
|
92 | + protected function translateSingle($domain, array $string, array $args) |
|
93 | + { |
|
94 | + if (!empty($string['s2'])) { |
|
95 | + $args['single'] = $string['s2']; |
|
96 | + } |
|
97 | + return get_translations_for_domain($domain)->translate( |
|
98 | + $args['single'], |
|
99 | + $args['context'] |
|
100 | + ); |
|
101 | + } |
|
102 | 102 | } |
@@ -11,31 +11,31 @@ discard block |
||
11 | 11 | * @param string $domain |
12 | 12 | * @return string |
13 | 13 | */ |
14 | - public function translate($original, $domain, array $args) |
|
14 | + public function translate( $original, $domain, array $args ) |
|
15 | 15 | { |
16 | - $domains = apply_filters('site-reviews/translator/domains', [Application::ID]); |
|
17 | - if (!in_array($domain, $domains)) { |
|
16 | + $domains = apply_filters( 'site-reviews/translator/domains', [Application::ID] ); |
|
17 | + if( !in_array( $domain, $domains ) ) { |
|
18 | 18 | return $original; |
19 | 19 | } |
20 | - $args = $this->normalizeTranslationArgs($args); |
|
21 | - $strings = $this->getTranslationStrings($args['single'], $args['plural']); |
|
22 | - if (empty($strings)) { |
|
20 | + $args = $this->normalizeTranslationArgs( $args ); |
|
21 | + $strings = $this->getTranslationStrings( $args['single'], $args['plural'] ); |
|
22 | + if( empty($strings) ) { |
|
23 | 23 | return $original; |
24 | 24 | } |
25 | - $string = current($strings); |
|
25 | + $string = current( $strings ); |
|
26 | 26 | return 'plural' == $string['type'] |
27 | - ? $this->translatePlural($domain, $string, $args) |
|
28 | - : $this->translateSingle($domain, $string, $args); |
|
27 | + ? $this->translatePlural( $domain, $string, $args ) |
|
28 | + : $this->translateSingle( $domain, $string, $args ); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
32 | 32 | * Used when search/replacing a default text-domain translation |
33 | 33 | * @return string |
34 | 34 | */ |
35 | - public function getTranslation(array $args) |
|
35 | + public function getTranslation( array $args ) |
|
36 | 36 | { |
37 | - $args = $this->normalizeTranslationArgs($args); |
|
38 | - return get_translations_for_domain(Application::ID)->translate_plural($args['single'], $args['plural'], $args['number']); |
|
37 | + $args = $this->normalizeTranslationArgs( $args ); |
|
38 | + return get_translations_for_domain( Application::ID )->translate_plural( $args['single'], $args['plural'], $args['number'] ); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
@@ -43,18 +43,18 @@ discard block |
||
43 | 43 | * @param string $plural |
44 | 44 | * @return array |
45 | 45 | */ |
46 | - protected function getTranslationStrings($single, $plural) |
|
46 | + protected function getTranslationStrings( $single, $plural ) |
|
47 | 47 | { |
48 | - return array_filter(glsr(Translation::class)->translations(), function ($string) use ($single, $plural) { |
|
49 | - return $string['s1'] == html_entity_decode($single, ENT_COMPAT, 'UTF-8') |
|
50 | - && $string['p1'] == html_entity_decode($plural, ENT_COMPAT, 'UTF-8'); |
|
48 | + return array_filter( glsr( Translation::class )->translations(), function( $string ) use ($single, $plural) { |
|
49 | + return $string['s1'] == html_entity_decode( $single, ENT_COMPAT, 'UTF-8' ) |
|
50 | + && $string['p1'] == html_entity_decode( $plural, ENT_COMPAT, 'UTF-8' ); |
|
51 | 51 | }); |
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
55 | 55 | * @return array |
56 | 56 | */ |
57 | - protected function normalizeTranslationArgs(array $args) |
|
57 | + protected function normalizeTranslationArgs( array $args ) |
|
58 | 58 | { |
59 | 59 | $defaults = [ |
60 | 60 | 'context' => '', |
@@ -62,22 +62,22 @@ discard block |
||
62 | 62 | 'plural' => '', |
63 | 63 | 'single' => '', |
64 | 64 | ]; |
65 | - return shortcode_atts($defaults, $args); |
|
65 | + return shortcode_atts( $defaults, $args ); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
69 | 69 | * @param string $domain |
70 | 70 | * @return string |
71 | 71 | */ |
72 | - protected function translatePlural($domain, array $string, array $args) |
|
72 | + protected function translatePlural( $domain, array $string, array $args ) |
|
73 | 73 | { |
74 | - if (!empty($string['s2'])) { |
|
74 | + if( !empty($string['s2']) ) { |
|
75 | 75 | $args['single'] = $string['s2']; |
76 | 76 | } |
77 | - if (!empty($string['p2'])) { |
|
77 | + if( !empty($string['p2']) ) { |
|
78 | 78 | $args['plural'] = $string['p2']; |
79 | 79 | } |
80 | - return get_translations_for_domain($domain)->translate_plural( |
|
80 | + return get_translations_for_domain( $domain )->translate_plural( |
|
81 | 81 | $args['single'], |
82 | 82 | $args['plural'], |
83 | 83 | $args['number'], |
@@ -89,12 +89,12 @@ discard block |
||
89 | 89 | * @param string $domain |
90 | 90 | * @return string |
91 | 91 | */ |
92 | - protected function translateSingle($domain, array $string, array $args) |
|
92 | + protected function translateSingle( $domain, array $string, array $args ) |
|
93 | 93 | { |
94 | - if (!empty($string['s2'])) { |
|
94 | + if( !empty($string['s2']) ) { |
|
95 | 95 | $args['single'] = $string['s2']; |
96 | 96 | } |
97 | - return get_translations_for_domain($domain)->translate( |
|
97 | + return get_translations_for_domain( $domain )->translate( |
|
98 | 98 | $args['single'], |
99 | 99 | $args['context'] |
100 | 100 | ); |
@@ -13,81 +13,81 @@ |
||
13 | 13 | |
14 | 14 | class PublicController extends Controller |
15 | 15 | { |
16 | - /** |
|
17 | - * @return void |
|
18 | - * @action wp_enqueue_scripts |
|
19 | - */ |
|
20 | - public function enqueueAssets() |
|
21 | - { |
|
22 | - (new EnqueuePublicAssets())->handle(); |
|
23 | - } |
|
16 | + /** |
|
17 | + * @return void |
|
18 | + * @action wp_enqueue_scripts |
|
19 | + */ |
|
20 | + public function enqueueAssets() |
|
21 | + { |
|
22 | + (new EnqueuePublicAssets())->handle(); |
|
23 | + } |
|
24 | 24 | |
25 | - /** |
|
26 | - * @param string $tag |
|
27 | - * @param string $handle |
|
28 | - * @return string |
|
29 | - * @filter script_loader_tag |
|
30 | - */ |
|
31 | - public function filterEnqueuedScripts($tag, $handle) |
|
32 | - { |
|
33 | - $scripts = [Application::ID.'/google-recaptcha']; |
|
34 | - if (in_array($handle, apply_filters('site-reviews/async-scripts', $scripts))) { |
|
35 | - $tag = str_replace(' src=', ' async src=', $tag); |
|
36 | - } |
|
37 | - if (in_array($handle, apply_filters('site-reviews/defer-scripts', $scripts))) { |
|
38 | - $tag = str_replace(' src=', ' defer src=', $tag); |
|
39 | - } |
|
40 | - return $tag; |
|
41 | - } |
|
25 | + /** |
|
26 | + * @param string $tag |
|
27 | + * @param string $handle |
|
28 | + * @return string |
|
29 | + * @filter script_loader_tag |
|
30 | + */ |
|
31 | + public function filterEnqueuedScripts($tag, $handle) |
|
32 | + { |
|
33 | + $scripts = [Application::ID.'/google-recaptcha']; |
|
34 | + if (in_array($handle, apply_filters('site-reviews/async-scripts', $scripts))) { |
|
35 | + $tag = str_replace(' src=', ' async src=', $tag); |
|
36 | + } |
|
37 | + if (in_array($handle, apply_filters('site-reviews/defer-scripts', $scripts))) { |
|
38 | + $tag = str_replace(' src=', ' defer src=', $tag); |
|
39 | + } |
|
40 | + return $tag; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @return array |
|
45 | - * @filter site-reviews/config/forms/submission-form |
|
46 | - */ |
|
47 | - public function filterFieldOrder(array $config) |
|
48 | - { |
|
49 | - $order = (array) apply_filters('site-reviews/submission-form/order', array_keys($config)); |
|
50 | - return array_intersect_key(array_merge(array_flip($order), $config), $config); |
|
51 | - } |
|
43 | + /** |
|
44 | + * @return array |
|
45 | + * @filter site-reviews/config/forms/submission-form |
|
46 | + */ |
|
47 | + public function filterFieldOrder(array $config) |
|
48 | + { |
|
49 | + $order = (array) apply_filters('site-reviews/submission-form/order', array_keys($config)); |
|
50 | + return array_intersect_key(array_merge(array_flip($order), $config), $config); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @param string $view |
|
55 | - * @return string |
|
56 | - * @filter site-reviews/render/view |
|
57 | - */ |
|
58 | - public function filterRenderView($view) |
|
59 | - { |
|
60 | - return glsr(Style::class)->filterView($view); |
|
61 | - } |
|
53 | + /** |
|
54 | + * @param string $view |
|
55 | + * @return string |
|
56 | + * @filter site-reviews/render/view |
|
57 | + */ |
|
58 | + public function filterRenderView($view) |
|
59 | + { |
|
60 | + return glsr(Style::class)->filterView($view); |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * @return void |
|
65 | - * @action site-reviews/builder |
|
66 | - */ |
|
67 | - public function modifyBuilder(Builder $instance) |
|
68 | - { |
|
69 | - call_user_func_array([glsr(Style::class), 'modifyField'], [$instance]); |
|
70 | - } |
|
63 | + /** |
|
64 | + * @return void |
|
65 | + * @action site-reviews/builder |
|
66 | + */ |
|
67 | + public function modifyBuilder(Builder $instance) |
|
68 | + { |
|
69 | + call_user_func_array([glsr(Style::class), 'modifyField'], [$instance]); |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * @return void |
|
74 | - * @action wp_footer |
|
75 | - */ |
|
76 | - public function renderSchema() |
|
77 | - { |
|
78 | - glsr(Schema::class)->render(); |
|
79 | - } |
|
72 | + /** |
|
73 | + * @return void |
|
74 | + * @action wp_footer |
|
75 | + */ |
|
76 | + public function renderSchema() |
|
77 | + { |
|
78 | + glsr(Schema::class)->render(); |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * @return CreateReview |
|
83 | - */ |
|
84 | - public function routerSubmitReview(array $request) |
|
85 | - { |
|
86 | - $validated = glsr(ValidateReview::class)->validate($request); |
|
87 | - $command = new CreateReview($validated->request); |
|
88 | - if (empty($validated->error) && !$validated->recaptchaIsUnset) { |
|
89 | - $this->execute($command); |
|
90 | - } |
|
91 | - return $command; |
|
92 | - } |
|
81 | + /** |
|
82 | + * @return CreateReview |
|
83 | + */ |
|
84 | + public function routerSubmitReview(array $request) |
|
85 | + { |
|
86 | + $validated = glsr(ValidateReview::class)->validate($request); |
|
87 | + $command = new CreateReview($validated->request); |
|
88 | + if (empty($validated->error) && !$validated->recaptchaIsUnset) { |
|
89 | + $this->execute($command); |
|
90 | + } |
|
91 | + return $command; |
|
92 | + } |
|
93 | 93 | } |
@@ -28,14 +28,14 @@ discard block |
||
28 | 28 | * @return string |
29 | 29 | * @filter script_loader_tag |
30 | 30 | */ |
31 | - public function filterEnqueuedScripts($tag, $handle) |
|
31 | + public function filterEnqueuedScripts( $tag, $handle ) |
|
32 | 32 | { |
33 | 33 | $scripts = [Application::ID.'/google-recaptcha']; |
34 | - if (in_array($handle, apply_filters('site-reviews/async-scripts', $scripts))) { |
|
35 | - $tag = str_replace(' src=', ' async src=', $tag); |
|
34 | + if( in_array( $handle, apply_filters( 'site-reviews/async-scripts', $scripts ) ) ) { |
|
35 | + $tag = str_replace( ' src=', ' async src=', $tag ); |
|
36 | 36 | } |
37 | - if (in_array($handle, apply_filters('site-reviews/defer-scripts', $scripts))) { |
|
38 | - $tag = str_replace(' src=', ' defer src=', $tag); |
|
37 | + if( in_array( $handle, apply_filters( 'site-reviews/defer-scripts', $scripts ) ) ) { |
|
38 | + $tag = str_replace( ' src=', ' defer src=', $tag ); |
|
39 | 39 | } |
40 | 40 | return $tag; |
41 | 41 | } |
@@ -44,10 +44,10 @@ discard block |
||
44 | 44 | * @return array |
45 | 45 | * @filter site-reviews/config/forms/submission-form |
46 | 46 | */ |
47 | - public function filterFieldOrder(array $config) |
|
47 | + public function filterFieldOrder( array $config ) |
|
48 | 48 | { |
49 | - $order = (array) apply_filters('site-reviews/submission-form/order', array_keys($config)); |
|
50 | - return array_intersect_key(array_merge(array_flip($order), $config), $config); |
|
49 | + $order = (array)apply_filters( 'site-reviews/submission-form/order', array_keys( $config ) ); |
|
50 | + return array_intersect_key( array_merge( array_flip( $order ), $config ), $config ); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
@@ -55,18 +55,18 @@ discard block |
||
55 | 55 | * @return string |
56 | 56 | * @filter site-reviews/render/view |
57 | 57 | */ |
58 | - public function filterRenderView($view) |
|
58 | + public function filterRenderView( $view ) |
|
59 | 59 | { |
60 | - return glsr(Style::class)->filterView($view); |
|
60 | + return glsr( Style::class )->filterView( $view ); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
64 | 64 | * @return void |
65 | 65 | * @action site-reviews/builder |
66 | 66 | */ |
67 | - public function modifyBuilder(Builder $instance) |
|
67 | + public function modifyBuilder( Builder $instance ) |
|
68 | 68 | { |
69 | - call_user_func_array([glsr(Style::class), 'modifyField'], [$instance]); |
|
69 | + call_user_func_array( [glsr( Style::class ), 'modifyField'], [$instance] ); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
@@ -75,18 +75,18 @@ discard block |
||
75 | 75 | */ |
76 | 76 | public function renderSchema() |
77 | 77 | { |
78 | - glsr(Schema::class)->render(); |
|
78 | + glsr( Schema::class )->render(); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
82 | 82 | * @return CreateReview |
83 | 83 | */ |
84 | - public function routerSubmitReview(array $request) |
|
84 | + public function routerSubmitReview( array $request ) |
|
85 | 85 | { |
86 | - $validated = glsr(ValidateReview::class)->validate($request); |
|
87 | - $command = new CreateReview($validated->request); |
|
88 | - if (empty($validated->error) && !$validated->recaptchaIsUnset) { |
|
89 | - $this->execute($command); |
|
86 | + $validated = glsr( ValidateReview::class )->validate( $request ); |
|
87 | + $command = new CreateReview( $validated->request ); |
|
88 | + if( empty($validated->error) && !$validated->recaptchaIsUnset ) { |
|
89 | + $this->execute( $command ); |
|
90 | 90 | } |
91 | 91 | return $command; |
92 | 92 | } |
@@ -6,63 +6,63 @@ |
||
6 | 6 | |
7 | 7 | class Cache |
8 | 8 | { |
9 | - /** |
|
10 | - * @return array |
|
11 | - */ |
|
12 | - public function getCloudflareIps() |
|
13 | - { |
|
14 | - if (false === ($ipAddresses = get_transient(Application::ID.'_cloudflare_ips'))) { |
|
15 | - $ipAddresses = array_fill_keys(['v4', 'v6'], []); |
|
16 | - foreach (array_keys($ipAddresses) as $version) { |
|
17 | - $url = 'https://www.cloudflare.com/ips-'.$version; |
|
18 | - $response = wp_remote_get($url, ['sslverify' => false]); |
|
19 | - if (is_wp_error($response)) { |
|
20 | - glsr_log()->error($response->get_error_message()); |
|
21 | - continue; |
|
22 | - } |
|
23 | - if ('200' != ($statusCode = wp_remote_retrieve_response_code($response))) { |
|
24 | - glsr_log()->error('Unable to connect to '.$url.' ['.$statusCode.']'); |
|
25 | - continue; |
|
26 | - } |
|
27 | - $ipAddresses[$version] = array_filter( |
|
28 | - (array) preg_split('/\R/', wp_remote_retrieve_body($response)) |
|
29 | - ); |
|
30 | - } |
|
31 | - set_transient(Application::ID.'_cloudflare_ips', $ipAddresses, WEEK_IN_SECONDS); |
|
32 | - } |
|
33 | - return $ipAddresses; |
|
34 | - } |
|
9 | + /** |
|
10 | + * @return array |
|
11 | + */ |
|
12 | + public function getCloudflareIps() |
|
13 | + { |
|
14 | + if (false === ($ipAddresses = get_transient(Application::ID.'_cloudflare_ips'))) { |
|
15 | + $ipAddresses = array_fill_keys(['v4', 'v6'], []); |
|
16 | + foreach (array_keys($ipAddresses) as $version) { |
|
17 | + $url = 'https://www.cloudflare.com/ips-'.$version; |
|
18 | + $response = wp_remote_get($url, ['sslverify' => false]); |
|
19 | + if (is_wp_error($response)) { |
|
20 | + glsr_log()->error($response->get_error_message()); |
|
21 | + continue; |
|
22 | + } |
|
23 | + if ('200' != ($statusCode = wp_remote_retrieve_response_code($response))) { |
|
24 | + glsr_log()->error('Unable to connect to '.$url.' ['.$statusCode.']'); |
|
25 | + continue; |
|
26 | + } |
|
27 | + $ipAddresses[$version] = array_filter( |
|
28 | + (array) preg_split('/\R/', wp_remote_retrieve_body($response)) |
|
29 | + ); |
|
30 | + } |
|
31 | + set_transient(Application::ID.'_cloudflare_ips', $ipAddresses, WEEK_IN_SECONDS); |
|
32 | + } |
|
33 | + return $ipAddresses; |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * @param string $metaKey |
|
38 | - * @return array |
|
39 | - */ |
|
40 | - public function getReviewCountsFor($metaKey) |
|
41 | - { |
|
42 | - $counts = wp_cache_get(Application::ID, $metaKey.'_count'); |
|
43 | - if (false === $counts) { |
|
44 | - $counts = []; |
|
45 | - $results = glsr(SqlQueries::class)->getReviewCountsFor($metaKey); |
|
46 | - foreach ($results as $result) { |
|
47 | - $counts[$result->name] = $result->num_posts; |
|
48 | - } |
|
49 | - wp_cache_set(Application::ID, $counts, $metaKey.'_count'); |
|
50 | - } |
|
51 | - return $counts; |
|
52 | - } |
|
36 | + /** |
|
37 | + * @param string $metaKey |
|
38 | + * @return array |
|
39 | + */ |
|
40 | + public function getReviewCountsFor($metaKey) |
|
41 | + { |
|
42 | + $counts = wp_cache_get(Application::ID, $metaKey.'_count'); |
|
43 | + if (false === $counts) { |
|
44 | + $counts = []; |
|
45 | + $results = glsr(SqlQueries::class)->getReviewCountsFor($metaKey); |
|
46 | + foreach ($results as $result) { |
|
47 | + $counts[$result->name] = $result->num_posts; |
|
48 | + } |
|
49 | + wp_cache_set(Application::ID, $counts, $metaKey.'_count'); |
|
50 | + } |
|
51 | + return $counts; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * @return string |
|
56 | - */ |
|
57 | - public function getRemotePostTest() |
|
58 | - { |
|
59 | - if (false === ($test = get_transient(Application::ID.'_remote_post_test'))) { |
|
60 | - $response = wp_remote_post('https://api.wordpress.org/stats/php/1.0/'); |
|
61 | - $test = !is_wp_error($response) && in_array($response['response']['code'], range(200, 299)) |
|
62 | - ? 'Works' |
|
63 | - : 'Does not work'; |
|
64 | - set_transient(Application::ID.'_remote_post_test', $test, WEEK_IN_SECONDS); |
|
65 | - } |
|
66 | - return $test; |
|
67 | - } |
|
54 | + /** |
|
55 | + * @return string |
|
56 | + */ |
|
57 | + public function getRemotePostTest() |
|
58 | + { |
|
59 | + if (false === ($test = get_transient(Application::ID.'_remote_post_test'))) { |
|
60 | + $response = wp_remote_post('https://api.wordpress.org/stats/php/1.0/'); |
|
61 | + $test = !is_wp_error($response) && in_array($response['response']['code'], range(200, 299)) |
|
62 | + ? 'Works' |
|
63 | + : 'Does not work'; |
|
64 | + set_transient(Application::ID.'_remote_post_test', $test, WEEK_IN_SECONDS); |
|
65 | + } |
|
66 | + return $test; |
|
67 | + } |
|
68 | 68 | } |
@@ -11,24 +11,24 @@ discard block |
||
11 | 11 | */ |
12 | 12 | public function getCloudflareIps() |
13 | 13 | { |
14 | - if (false === ($ipAddresses = get_transient(Application::ID.'_cloudflare_ips'))) { |
|
15 | - $ipAddresses = array_fill_keys(['v4', 'v6'], []); |
|
16 | - foreach (array_keys($ipAddresses) as $version) { |
|
14 | + if( false === ($ipAddresses = get_transient( Application::ID.'_cloudflare_ips' )) ) { |
|
15 | + $ipAddresses = array_fill_keys( ['v4', 'v6'], [] ); |
|
16 | + foreach( array_keys( $ipAddresses ) as $version ) { |
|
17 | 17 | $url = 'https://www.cloudflare.com/ips-'.$version; |
18 | - $response = wp_remote_get($url, ['sslverify' => false]); |
|
19 | - if (is_wp_error($response)) { |
|
20 | - glsr_log()->error($response->get_error_message()); |
|
18 | + $response = wp_remote_get( $url, ['sslverify' => false] ); |
|
19 | + if( is_wp_error( $response ) ) { |
|
20 | + glsr_log()->error( $response->get_error_message() ); |
|
21 | 21 | continue; |
22 | 22 | } |
23 | - if ('200' != ($statusCode = wp_remote_retrieve_response_code($response))) { |
|
24 | - glsr_log()->error('Unable to connect to '.$url.' ['.$statusCode.']'); |
|
23 | + if( '200' != ($statusCode = wp_remote_retrieve_response_code( $response )) ) { |
|
24 | + glsr_log()->error( 'Unable to connect to '.$url.' ['.$statusCode.']' ); |
|
25 | 25 | continue; |
26 | 26 | } |
27 | 27 | $ipAddresses[$version] = array_filter( |
28 | - (array) preg_split('/\R/', wp_remote_retrieve_body($response)) |
|
28 | + (array)preg_split( '/\R/', wp_remote_retrieve_body( $response ) ) |
|
29 | 29 | ); |
30 | 30 | } |
31 | - set_transient(Application::ID.'_cloudflare_ips', $ipAddresses, WEEK_IN_SECONDS); |
|
31 | + set_transient( Application::ID.'_cloudflare_ips', $ipAddresses, WEEK_IN_SECONDS ); |
|
32 | 32 | } |
33 | 33 | return $ipAddresses; |
34 | 34 | } |
@@ -37,16 +37,16 @@ discard block |
||
37 | 37 | * @param string $metaKey |
38 | 38 | * @return array |
39 | 39 | */ |
40 | - public function getReviewCountsFor($metaKey) |
|
40 | + public function getReviewCountsFor( $metaKey ) |
|
41 | 41 | { |
42 | - $counts = wp_cache_get(Application::ID, $metaKey.'_count'); |
|
43 | - if (false === $counts) { |
|
42 | + $counts = wp_cache_get( Application::ID, $metaKey.'_count' ); |
|
43 | + if( false === $counts ) { |
|
44 | 44 | $counts = []; |
45 | - $results = glsr(SqlQueries::class)->getReviewCountsFor($metaKey); |
|
46 | - foreach ($results as $result) { |
|
45 | + $results = glsr( SqlQueries::class )->getReviewCountsFor( $metaKey ); |
|
46 | + foreach( $results as $result ) { |
|
47 | 47 | $counts[$result->name] = $result->num_posts; |
48 | 48 | } |
49 | - wp_cache_set(Application::ID, $counts, $metaKey.'_count'); |
|
49 | + wp_cache_set( Application::ID, $counts, $metaKey.'_count' ); |
|
50 | 50 | } |
51 | 51 | return $counts; |
52 | 52 | } |
@@ -56,12 +56,12 @@ discard block |
||
56 | 56 | */ |
57 | 57 | public function getRemotePostTest() |
58 | 58 | { |
59 | - if (false === ($test = get_transient(Application::ID.'_remote_post_test'))) { |
|
60 | - $response = wp_remote_post('https://api.wordpress.org/stats/php/1.0/'); |
|
61 | - $test = !is_wp_error($response) && in_array($response['response']['code'], range(200, 299)) |
|
59 | + if( false === ($test = get_transient( Application::ID.'_remote_post_test' )) ) { |
|
60 | + $response = wp_remote_post( 'https://api.wordpress.org/stats/php/1.0/' ); |
|
61 | + $test = !is_wp_error( $response ) && in_array( $response['response']['code'], range( 200, 299 ) ) |
|
62 | 62 | ? 'Works' |
63 | 63 | : 'Does not work'; |
64 | - set_transient(Application::ID.'_remote_post_test', $test, WEEK_IN_SECONDS); |
|
64 | + set_transient( Application::ID.'_remote_post_test', $test, WEEK_IN_SECONDS ); |
|
65 | 65 | } |
66 | 66 | return $test; |
67 | 67 | } |
@@ -6,41 +6,41 @@ |
||
6 | 6 | |
7 | 7 | class CreateReviewDefaults extends Defaults |
8 | 8 | { |
9 | - /** |
|
10 | - * @var array |
|
11 | - */ |
|
12 | - protected $guarded = [ |
|
13 | - 'assigned_to', |
|
14 | - 'content', |
|
15 | - 'date', |
|
16 | - 'pinned', |
|
17 | - 'response', |
|
18 | - 'review_id', |
|
19 | - 'review_type', |
|
20 | - 'title', |
|
21 | - ]; |
|
9 | + /** |
|
10 | + * @var array |
|
11 | + */ |
|
12 | + protected $guarded = [ |
|
13 | + 'assigned_to', |
|
14 | + 'content', |
|
15 | + 'date', |
|
16 | + 'pinned', |
|
17 | + 'response', |
|
18 | + 'review_id', |
|
19 | + 'review_type', |
|
20 | + 'title', |
|
21 | + ]; |
|
22 | 22 | |
23 | - /** |
|
24 | - * @return array |
|
25 | - */ |
|
26 | - protected function defaults() |
|
27 | - { |
|
28 | - return [ |
|
29 | - 'assigned_to' => '', |
|
30 | - 'author' => '', |
|
31 | - 'avatar' => '', |
|
32 | - 'content' => '', |
|
33 | - 'custom' => '', |
|
34 | - 'date' => '', |
|
35 | - 'email' => '', |
|
36 | - 'ip_address' => '', |
|
37 | - 'pinned' => false, |
|
38 | - 'rating' => '', |
|
39 | - 'response' => '', |
|
40 | - 'review_id' => md5(time().mt_rand()), |
|
41 | - 'review_type' => 'local', |
|
42 | - 'title' => '', |
|
43 | - 'url' => '', |
|
44 | - ]; |
|
45 | - } |
|
23 | + /** |
|
24 | + * @return array |
|
25 | + */ |
|
26 | + protected function defaults() |
|
27 | + { |
|
28 | + return [ |
|
29 | + 'assigned_to' => '', |
|
30 | + 'author' => '', |
|
31 | + 'avatar' => '', |
|
32 | + 'content' => '', |
|
33 | + 'custom' => '', |
|
34 | + 'date' => '', |
|
35 | + 'email' => '', |
|
36 | + 'ip_address' => '', |
|
37 | + 'pinned' => false, |
|
38 | + 'rating' => '', |
|
39 | + 'response' => '', |
|
40 | + 'review_id' => md5(time().mt_rand()), |
|
41 | + 'review_type' => 'local', |
|
42 | + 'title' => '', |
|
43 | + 'url' => '', |
|
44 | + ]; |
|
45 | + } |
|
46 | 46 | } |
@@ -37,7 +37,7 @@ |
||
37 | 37 | 'pinned' => false, |
38 | 38 | 'rating' => '', |
39 | 39 | 'response' => '', |
40 | - 'review_id' => md5(time().mt_rand()), |
|
40 | + 'review_id' => md5( time().mt_rand() ), |
|
41 | 41 | 'review_type' => 'local', |
42 | 42 | 'title' => '', |
43 | 43 | 'url' => '', |
@@ -6,22 +6,22 @@ |
||
6 | 6 | |
7 | 7 | class ValidateReviewDefaults extends Defaults |
8 | 8 | { |
9 | - /** |
|
10 | - * @return array |
|
11 | - */ |
|
12 | - protected function defaults() |
|
13 | - { |
|
14 | - return [ |
|
15 | - 'assign_to' => '', |
|
16 | - 'category' => '', |
|
17 | - 'content' => '', |
|
18 | - 'email' => '', |
|
19 | - 'form_id' => '', |
|
20 | - 'ip_address' => '', |
|
21 | - 'name' => '', |
|
22 | - 'rating' => '0', |
|
23 | - 'terms' => '', |
|
24 | - 'title' => '', |
|
25 | - ]; |
|
26 | - } |
|
9 | + /** |
|
10 | + * @return array |
|
11 | + */ |
|
12 | + protected function defaults() |
|
13 | + { |
|
14 | + return [ |
|
15 | + 'assign_to' => '', |
|
16 | + 'category' => '', |
|
17 | + 'content' => '', |
|
18 | + 'email' => '', |
|
19 | + 'form_id' => '', |
|
20 | + 'ip_address' => '', |
|
21 | + 'name' => '', |
|
22 | + 'rating' => '0', |
|
23 | + 'terms' => '', |
|
24 | + 'title' => '', |
|
25 | + ]; |
|
26 | + } |
|
27 | 27 | } |
@@ -9,148 +9,148 @@ |
||
9 | 9 | |
10 | 10 | class EnqueuePublicAssets |
11 | 11 | { |
12 | - /** |
|
13 | - * @return void |
|
14 | - */ |
|
15 | - public function handle() |
|
16 | - { |
|
17 | - $this->enqueueAssets(); |
|
18 | - $this->enqueuePolyfillService(); |
|
19 | - $this->enqueueRecaptchaScript(); |
|
20 | - $this->inlineScript(); |
|
21 | - $this->inlineStyles(); |
|
22 | - } |
|
12 | + /** |
|
13 | + * @return void |
|
14 | + */ |
|
15 | + public function handle() |
|
16 | + { |
|
17 | + $this->enqueueAssets(); |
|
18 | + $this->enqueuePolyfillService(); |
|
19 | + $this->enqueueRecaptchaScript(); |
|
20 | + $this->inlineScript(); |
|
21 | + $this->inlineStyles(); |
|
22 | + } |
|
23 | 23 | |
24 | - /** |
|
25 | - * @return void |
|
26 | - */ |
|
27 | - public function enqueueAssets() |
|
28 | - { |
|
29 | - if (apply_filters('site-reviews/assets/css', true)) { |
|
30 | - wp_enqueue_style( |
|
31 | - Application::ID, |
|
32 | - $this->getStylesheet(), |
|
33 | - [], |
|
34 | - glsr()->version |
|
35 | - ); |
|
36 | - } |
|
37 | - if (apply_filters('site-reviews/assets/js', true)) { |
|
38 | - $dependencies = apply_filters('site-reviews/assets/polyfill', true) |
|
39 | - ? [Application::ID.'/polyfill'] |
|
40 | - : []; |
|
41 | - $dependencies = apply_filters('site-reviews/enqueue/public/dependencies', $dependencies); |
|
42 | - wp_enqueue_script( |
|
43 | - Application::ID, |
|
44 | - glsr()->url('assets/scripts/'.Application::ID.'.js'), |
|
45 | - $dependencies, |
|
46 | - glsr()->version, |
|
47 | - true |
|
48 | - ); |
|
49 | - } |
|
50 | - } |
|
24 | + /** |
|
25 | + * @return void |
|
26 | + */ |
|
27 | + public function enqueueAssets() |
|
28 | + { |
|
29 | + if (apply_filters('site-reviews/assets/css', true)) { |
|
30 | + wp_enqueue_style( |
|
31 | + Application::ID, |
|
32 | + $this->getStylesheet(), |
|
33 | + [], |
|
34 | + glsr()->version |
|
35 | + ); |
|
36 | + } |
|
37 | + if (apply_filters('site-reviews/assets/js', true)) { |
|
38 | + $dependencies = apply_filters('site-reviews/assets/polyfill', true) |
|
39 | + ? [Application::ID.'/polyfill'] |
|
40 | + : []; |
|
41 | + $dependencies = apply_filters('site-reviews/enqueue/public/dependencies', $dependencies); |
|
42 | + wp_enqueue_script( |
|
43 | + Application::ID, |
|
44 | + glsr()->url('assets/scripts/'.Application::ID.'.js'), |
|
45 | + $dependencies, |
|
46 | + glsr()->version, |
|
47 | + true |
|
48 | + ); |
|
49 | + } |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * @return void |
|
54 | - */ |
|
55 | - public function enqueuePolyfillService() |
|
56 | - { |
|
57 | - if (!apply_filters('site-reviews/assets/polyfill', true)) { |
|
58 | - return; |
|
59 | - } |
|
60 | - wp_enqueue_script(Application::ID.'/polyfill', add_query_arg([ |
|
61 | - 'features' => 'Array.prototype.findIndex,CustomEvent,Element.prototype.closest,Element.prototype.dataset,Event,XMLHttpRequest,MutationObserver', |
|
62 | - 'flags' => 'gated', |
|
63 | - ], 'https://polyfill.io/v3/polyfill.min.js')); |
|
64 | - } |
|
52 | + /** |
|
53 | + * @return void |
|
54 | + */ |
|
55 | + public function enqueuePolyfillService() |
|
56 | + { |
|
57 | + if (!apply_filters('site-reviews/assets/polyfill', true)) { |
|
58 | + return; |
|
59 | + } |
|
60 | + wp_enqueue_script(Application::ID.'/polyfill', add_query_arg([ |
|
61 | + 'features' => 'Array.prototype.findIndex,CustomEvent,Element.prototype.closest,Element.prototype.dataset,Event,XMLHttpRequest,MutationObserver', |
|
62 | + 'flags' => 'gated', |
|
63 | + ], 'https://polyfill.io/v3/polyfill.min.js')); |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @return void |
|
68 | - */ |
|
69 | - public function enqueueRecaptchaScript() |
|
70 | - { |
|
71 | - // wpforms-recaptcha |
|
72 | - // google-recaptcha |
|
73 | - // nf-google-recaptcha |
|
74 | - if (!glsr(OptionManager::class)->isRecaptchaEnabled()) { |
|
75 | - return; |
|
76 | - } |
|
77 | - $language = apply_filters('site-reviews/recaptcha/language', get_locale()); |
|
78 | - wp_enqueue_script(Application::ID.'/google-recaptcha', add_query_arg([ |
|
79 | - 'hl' => $language, |
|
80 | - 'render' => 'explicit', |
|
81 | - ], 'https://www.google.com/recaptcha/api.js')); |
|
82 | - } |
|
66 | + /** |
|
67 | + * @return void |
|
68 | + */ |
|
69 | + public function enqueueRecaptchaScript() |
|
70 | + { |
|
71 | + // wpforms-recaptcha |
|
72 | + // google-recaptcha |
|
73 | + // nf-google-recaptcha |
|
74 | + if (!glsr(OptionManager::class)->isRecaptchaEnabled()) { |
|
75 | + return; |
|
76 | + } |
|
77 | + $language = apply_filters('site-reviews/recaptcha/language', get_locale()); |
|
78 | + wp_enqueue_script(Application::ID.'/google-recaptcha', add_query_arg([ |
|
79 | + 'hl' => $language, |
|
80 | + 'render' => 'explicit', |
|
81 | + ], 'https://www.google.com/recaptcha/api.js')); |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * @return void |
|
86 | - */ |
|
87 | - public function inlineScript() |
|
88 | - { |
|
89 | - $variables = [ |
|
90 | - 'action' => Application::PREFIX.'action', |
|
91 | - 'ajaxpagination' => $this->getFixedSelectorsForPagination(), |
|
92 | - 'ajaxurl' => admin_url('admin-ajax.php'), |
|
93 | - 'nameprefix' => Application::ID, |
|
94 | - 'validationconfig' => glsr(Style::class)->validation, |
|
95 | - 'validationstrings' => glsr(ValidationStringsDefaults::class)->defaults(), |
|
96 | - ]; |
|
97 | - $variables = apply_filters('site-reviews/enqueue/public/localize', $variables); |
|
98 | - wp_add_inline_script(Application::ID, $this->buildInlineScript($variables), 'before'); |
|
99 | - } |
|
84 | + /** |
|
85 | + * @return void |
|
86 | + */ |
|
87 | + public function inlineScript() |
|
88 | + { |
|
89 | + $variables = [ |
|
90 | + 'action' => Application::PREFIX.'action', |
|
91 | + 'ajaxpagination' => $this->getFixedSelectorsForPagination(), |
|
92 | + 'ajaxurl' => admin_url('admin-ajax.php'), |
|
93 | + 'nameprefix' => Application::ID, |
|
94 | + 'validationconfig' => glsr(Style::class)->validation, |
|
95 | + 'validationstrings' => glsr(ValidationStringsDefaults::class)->defaults(), |
|
96 | + ]; |
|
97 | + $variables = apply_filters('site-reviews/enqueue/public/localize', $variables); |
|
98 | + wp_add_inline_script(Application::ID, $this->buildInlineScript($variables), 'before'); |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * @return void |
|
103 | - */ |
|
104 | - public function inlineStyles() |
|
105 | - { |
|
106 | - $inlineStylesheetPath = glsr()->path('assets/styles/inline-styles.css'); |
|
107 | - if (!apply_filters('site-reviews/assets/css', true)) { |
|
108 | - return; |
|
109 | - } |
|
110 | - if (!file_exists($inlineStylesheetPath)) { |
|
111 | - glsr_log()->error('Inline stylesheet is missing: '.$inlineStylesheetPath); |
|
112 | - return; |
|
113 | - } |
|
114 | - $inlineStylesheetValues = glsr()->config('inline-styles'); |
|
115 | - $stylesheet = str_replace( |
|
116 | - array_keys($inlineStylesheetValues), |
|
117 | - array_values($inlineStylesheetValues), |
|
118 | - file_get_contents($inlineStylesheetPath) |
|
119 | - ); |
|
120 | - wp_add_inline_style(Application::ID, $stylesheet); |
|
121 | - } |
|
101 | + /** |
|
102 | + * @return void |
|
103 | + */ |
|
104 | + public function inlineStyles() |
|
105 | + { |
|
106 | + $inlineStylesheetPath = glsr()->path('assets/styles/inline-styles.css'); |
|
107 | + if (!apply_filters('site-reviews/assets/css', true)) { |
|
108 | + return; |
|
109 | + } |
|
110 | + if (!file_exists($inlineStylesheetPath)) { |
|
111 | + glsr_log()->error('Inline stylesheet is missing: '.$inlineStylesheetPath); |
|
112 | + return; |
|
113 | + } |
|
114 | + $inlineStylesheetValues = glsr()->config('inline-styles'); |
|
115 | + $stylesheet = str_replace( |
|
116 | + array_keys($inlineStylesheetValues), |
|
117 | + array_values($inlineStylesheetValues), |
|
118 | + file_get_contents($inlineStylesheetPath) |
|
119 | + ); |
|
120 | + wp_add_inline_style(Application::ID, $stylesheet); |
|
121 | + } |
|
122 | 122 | |
123 | - /** |
|
124 | - * @return string |
|
125 | - */ |
|
126 | - protected function buildInlineScript(array $variables) |
|
127 | - { |
|
128 | - $script = 'window.hasOwnProperty("GLSR")||(window.GLSR={});'; |
|
129 | - foreach ($variables as $key => $value) { |
|
130 | - $script.= sprintf('GLSR.%s=%s;', $key, json_encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); |
|
131 | - } |
|
132 | - $pattern = '/\"([^ \-\"]+)\"(:[{\[\"])/'; // removes unnecessary quotes surrounding object keys |
|
133 | - $optimizedScript = preg_replace($pattern, '$1$2', $script); |
|
134 | - return apply_filters('site-reviews/enqueue/public/inline-script', $optimizedScript, $script, $variables); |
|
135 | - } |
|
123 | + /** |
|
124 | + * @return string |
|
125 | + */ |
|
126 | + protected function buildInlineScript(array $variables) |
|
127 | + { |
|
128 | + $script = 'window.hasOwnProperty("GLSR")||(window.GLSR={});'; |
|
129 | + foreach ($variables as $key => $value) { |
|
130 | + $script.= sprintf('GLSR.%s=%s;', $key, json_encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); |
|
131 | + } |
|
132 | + $pattern = '/\"([^ \-\"]+)\"(:[{\[\"])/'; // removes unnecessary quotes surrounding object keys |
|
133 | + $optimizedScript = preg_replace($pattern, '$1$2', $script); |
|
134 | + return apply_filters('site-reviews/enqueue/public/inline-script', $optimizedScript, $script, $variables); |
|
135 | + } |
|
136 | 136 | |
137 | - /** |
|
138 | - * @return array |
|
139 | - */ |
|
140 | - protected function getFixedSelectorsForPagination() |
|
141 | - { |
|
142 | - $selectors = ['#wpadminbar', '.site-navigation-fixed']; |
|
143 | - return apply_filters('site-reviews/enqueue/public/localize/ajax-pagination', $selectors); |
|
144 | - } |
|
137 | + /** |
|
138 | + * @return array |
|
139 | + */ |
|
140 | + protected function getFixedSelectorsForPagination() |
|
141 | + { |
|
142 | + $selectors = ['#wpadminbar', '.site-navigation-fixed']; |
|
143 | + return apply_filters('site-reviews/enqueue/public/localize/ajax-pagination', $selectors); |
|
144 | + } |
|
145 | 145 | |
146 | - /** |
|
147 | - * @return string |
|
148 | - */ |
|
149 | - protected function getStylesheet() |
|
150 | - { |
|
151 | - $currentStyle = glsr(Style::class)->style; |
|
152 | - return file_exists(glsr()->path('assets/styles/custom/'.$currentStyle.'.css')) |
|
153 | - ? glsr()->url('assets/styles/custom/'.$currentStyle.'.css') |
|
154 | - : glsr()->url('assets/styles/'.Application::ID.'.css'); |
|
155 | - } |
|
146 | + /** |
|
147 | + * @return string |
|
148 | + */ |
|
149 | + protected function getStylesheet() |
|
150 | + { |
|
151 | + $currentStyle = glsr(Style::class)->style; |
|
152 | + return file_exists(glsr()->path('assets/styles/custom/'.$currentStyle.'.css')) |
|
153 | + ? glsr()->url('assets/styles/custom/'.$currentStyle.'.css') |
|
154 | + : glsr()->url('assets/styles/'.Application::ID.'.css'); |
|
155 | + } |
|
156 | 156 | } |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | */ |
27 | 27 | public function enqueueAssets() |
28 | 28 | { |
29 | - if (apply_filters('site-reviews/assets/css', true)) { |
|
29 | + if( apply_filters( 'site-reviews/assets/css', true ) ) { |
|
30 | 30 | wp_enqueue_style( |
31 | 31 | Application::ID, |
32 | 32 | $this->getStylesheet(), |
@@ -34,14 +34,14 @@ discard block |
||
34 | 34 | glsr()->version |
35 | 35 | ); |
36 | 36 | } |
37 | - if (apply_filters('site-reviews/assets/js', true)) { |
|
38 | - $dependencies = apply_filters('site-reviews/assets/polyfill', true) |
|
37 | + if( apply_filters( 'site-reviews/assets/js', true ) ) { |
|
38 | + $dependencies = apply_filters( 'site-reviews/assets/polyfill', true ) |
|
39 | 39 | ? [Application::ID.'/polyfill'] |
40 | 40 | : []; |
41 | - $dependencies = apply_filters('site-reviews/enqueue/public/dependencies', $dependencies); |
|
41 | + $dependencies = apply_filters( 'site-reviews/enqueue/public/dependencies', $dependencies ); |
|
42 | 42 | wp_enqueue_script( |
43 | 43 | Application::ID, |
44 | - glsr()->url('assets/scripts/'.Application::ID.'.js'), |
|
44 | + glsr()->url( 'assets/scripts/'.Application::ID.'.js' ), |
|
45 | 45 | $dependencies, |
46 | 46 | glsr()->version, |
47 | 47 | true |
@@ -54,13 +54,13 @@ discard block |
||
54 | 54 | */ |
55 | 55 | public function enqueuePolyfillService() |
56 | 56 | { |
57 | - if (!apply_filters('site-reviews/assets/polyfill', true)) { |
|
57 | + if( !apply_filters( 'site-reviews/assets/polyfill', true ) ) { |
|
58 | 58 | return; |
59 | 59 | } |
60 | - wp_enqueue_script(Application::ID.'/polyfill', add_query_arg([ |
|
60 | + wp_enqueue_script( Application::ID.'/polyfill', add_query_arg( [ |
|
61 | 61 | 'features' => 'Array.prototype.findIndex,CustomEvent,Element.prototype.closest,Element.prototype.dataset,Event,XMLHttpRequest,MutationObserver', |
62 | 62 | 'flags' => 'gated', |
63 | - ], 'https://polyfill.io/v3/polyfill.min.js')); |
|
63 | + ], 'https://polyfill.io/v3/polyfill.min.js' ) ); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
@@ -71,14 +71,14 @@ discard block |
||
71 | 71 | // wpforms-recaptcha |
72 | 72 | // google-recaptcha |
73 | 73 | // nf-google-recaptcha |
74 | - if (!glsr(OptionManager::class)->isRecaptchaEnabled()) { |
|
74 | + if( !glsr( OptionManager::class )->isRecaptchaEnabled() ) { |
|
75 | 75 | return; |
76 | 76 | } |
77 | - $language = apply_filters('site-reviews/recaptcha/language', get_locale()); |
|
78 | - wp_enqueue_script(Application::ID.'/google-recaptcha', add_query_arg([ |
|
77 | + $language = apply_filters( 'site-reviews/recaptcha/language', get_locale() ); |
|
78 | + wp_enqueue_script( Application::ID.'/google-recaptcha', add_query_arg( [ |
|
79 | 79 | 'hl' => $language, |
80 | 80 | 'render' => 'explicit', |
81 | - ], 'https://www.google.com/recaptcha/api.js')); |
|
81 | + ], 'https://www.google.com/recaptcha/api.js' ) ); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
@@ -89,13 +89,13 @@ discard block |
||
89 | 89 | $variables = [ |
90 | 90 | 'action' => Application::PREFIX.'action', |
91 | 91 | 'ajaxpagination' => $this->getFixedSelectorsForPagination(), |
92 | - 'ajaxurl' => admin_url('admin-ajax.php'), |
|
92 | + 'ajaxurl' => admin_url( 'admin-ajax.php' ), |
|
93 | 93 | 'nameprefix' => Application::ID, |
94 | - 'validationconfig' => glsr(Style::class)->validation, |
|
95 | - 'validationstrings' => glsr(ValidationStringsDefaults::class)->defaults(), |
|
94 | + 'validationconfig' => glsr( Style::class )->validation, |
|
95 | + 'validationstrings' => glsr( ValidationStringsDefaults::class )->defaults(), |
|
96 | 96 | ]; |
97 | - $variables = apply_filters('site-reviews/enqueue/public/localize', $variables); |
|
98 | - wp_add_inline_script(Application::ID, $this->buildInlineScript($variables), 'before'); |
|
97 | + $variables = apply_filters( 'site-reviews/enqueue/public/localize', $variables ); |
|
98 | + wp_add_inline_script( Application::ID, $this->buildInlineScript( $variables ), 'before' ); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -103,35 +103,35 @@ discard block |
||
103 | 103 | */ |
104 | 104 | public function inlineStyles() |
105 | 105 | { |
106 | - $inlineStylesheetPath = glsr()->path('assets/styles/inline-styles.css'); |
|
107 | - if (!apply_filters('site-reviews/assets/css', true)) { |
|
106 | + $inlineStylesheetPath = glsr()->path( 'assets/styles/inline-styles.css' ); |
|
107 | + if( !apply_filters( 'site-reviews/assets/css', true ) ) { |
|
108 | 108 | return; |
109 | 109 | } |
110 | - if (!file_exists($inlineStylesheetPath)) { |
|
111 | - glsr_log()->error('Inline stylesheet is missing: '.$inlineStylesheetPath); |
|
110 | + if( !file_exists( $inlineStylesheetPath ) ) { |
|
111 | + glsr_log()->error( 'Inline stylesheet is missing: '.$inlineStylesheetPath ); |
|
112 | 112 | return; |
113 | 113 | } |
114 | - $inlineStylesheetValues = glsr()->config('inline-styles'); |
|
114 | + $inlineStylesheetValues = glsr()->config( 'inline-styles' ); |
|
115 | 115 | $stylesheet = str_replace( |
116 | - array_keys($inlineStylesheetValues), |
|
117 | - array_values($inlineStylesheetValues), |
|
118 | - file_get_contents($inlineStylesheetPath) |
|
116 | + array_keys( $inlineStylesheetValues ), |
|
117 | + array_values( $inlineStylesheetValues ), |
|
118 | + file_get_contents( $inlineStylesheetPath ) |
|
119 | 119 | ); |
120 | - wp_add_inline_style(Application::ID, $stylesheet); |
|
120 | + wp_add_inline_style( Application::ID, $stylesheet ); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
124 | 124 | * @return string |
125 | 125 | */ |
126 | - protected function buildInlineScript(array $variables) |
|
126 | + protected function buildInlineScript( array $variables ) |
|
127 | 127 | { |
128 | 128 | $script = 'window.hasOwnProperty("GLSR")||(window.GLSR={});'; |
129 | - foreach ($variables as $key => $value) { |
|
130 | - $script.= sprintf('GLSR.%s=%s;', $key, json_encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); |
|
129 | + foreach( $variables as $key => $value ) { |
|
130 | + $script .= sprintf( 'GLSR.%s=%s;', $key, json_encode( $value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ) ); |
|
131 | 131 | } |
132 | 132 | $pattern = '/\"([^ \-\"]+)\"(:[{\[\"])/'; // removes unnecessary quotes surrounding object keys |
133 | - $optimizedScript = preg_replace($pattern, '$1$2', $script); |
|
134 | - return apply_filters('site-reviews/enqueue/public/inline-script', $optimizedScript, $script, $variables); |
|
133 | + $optimizedScript = preg_replace( $pattern, '$1$2', $script ); |
|
134 | + return apply_filters( 'site-reviews/enqueue/public/inline-script', $optimizedScript, $script, $variables ); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | /** |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | protected function getFixedSelectorsForPagination() |
141 | 141 | { |
142 | 142 | $selectors = ['#wpadminbar', '.site-navigation-fixed']; |
143 | - return apply_filters('site-reviews/enqueue/public/localize/ajax-pagination', $selectors); |
|
143 | + return apply_filters( 'site-reviews/enqueue/public/localize/ajax-pagination', $selectors ); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -148,9 +148,9 @@ discard block |
||
148 | 148 | */ |
149 | 149 | protected function getStylesheet() |
150 | 150 | { |
151 | - $currentStyle = glsr(Style::class)->style; |
|
152 | - return file_exists(glsr()->path('assets/styles/custom/'.$currentStyle.'.css')) |
|
153 | - ? glsr()->url('assets/styles/custom/'.$currentStyle.'.css') |
|
154 | - : glsr()->url('assets/styles/'.Application::ID.'.css'); |
|
151 | + $currentStyle = glsr( Style::class )->style; |
|
152 | + return file_exists( glsr()->path( 'assets/styles/custom/'.$currentStyle.'.css' ) ) |
|
153 | + ? glsr()->url( 'assets/styles/custom/'.$currentStyle.'.css' ) |
|
154 | + : glsr()->url( 'assets/styles/'.Application::ID.'.css' ); |
|
155 | 155 | } |
156 | 156 | } |
@@ -6,23 +6,23 @@ |
||
6 | 6 | |
7 | 7 | class StyleValidationDefaults extends Defaults |
8 | 8 | { |
9 | - /** |
|
10 | - * @return array |
|
11 | - */ |
|
12 | - protected function defaults() |
|
13 | - { |
|
14 | - return [ |
|
15 | - 'error_tag' => 'div', |
|
16 | - 'error_tag_class' => 'glsr-field-error', |
|
17 | - 'field_class' => 'glsr-field', |
|
18 | - 'field_error_class' => 'glsr-has-error', |
|
19 | - 'input_error_class' => 'glsr-is-invalid', |
|
20 | - 'input_valid_class' => 'glsr-is-valid', |
|
21 | - 'message_error_class' => 'glsr-has-errors', |
|
22 | - 'message_initial_class' => 'glsr-is-visible', |
|
23 | - 'message_success_class' => 'glsr-has-success', |
|
24 | - 'message_tag' => 'div', |
|
25 | - 'message_tag_class' => 'glsr-form-message', |
|
26 | - ]; |
|
27 | - } |
|
9 | + /** |
|
10 | + * @return array |
|
11 | + */ |
|
12 | + protected function defaults() |
|
13 | + { |
|
14 | + return [ |
|
15 | + 'error_tag' => 'div', |
|
16 | + 'error_tag_class' => 'glsr-field-error', |
|
17 | + 'field_class' => 'glsr-field', |
|
18 | + 'field_error_class' => 'glsr-has-error', |
|
19 | + 'input_error_class' => 'glsr-is-invalid', |
|
20 | + 'input_valid_class' => 'glsr-is-valid', |
|
21 | + 'message_error_class' => 'glsr-has-errors', |
|
22 | + 'message_initial_class' => 'glsr-is-visible', |
|
23 | + 'message_success_class' => 'glsr-has-success', |
|
24 | + 'message_tag' => 'div', |
|
25 | + 'message_tag_class' => 'glsr-form-message', |
|
26 | + ]; |
|
27 | + } |
|
28 | 28 | } |
@@ -1,22 +1,22 @@ |
||
1 | -<?php defined('WPINC') || die; ?> |
|
1 | +<?php defined( 'WPINC' ) || die; ?> |
|
2 | 2 | |
3 | 3 | <textarea id="log-file" class="large-text code glsr-code glsr-code-large" rows="20" readonly>{{ console }}</textarea> |
4 | 4 | <form method="post" class="glsr-float-left"> |
5 | 5 | <input type="hidden" name="{{ id }}[_action]" value="download-console"> |
6 | - <?php wp_nonce_field('download-console'); ?> |
|
7 | - <?php submit_button(__('Download Console', 'site-reviews'), 'primary', '', false); ?> |
|
6 | + <?php wp_nonce_field( 'download-console' ); ?> |
|
7 | + <?php submit_button( __( 'Download Console', 'site-reviews' ), 'primary', '', false ); ?> |
|
8 | 8 | </form> |
9 | 9 | <form method="post" class="glsr-float-left"> |
10 | 10 | <input type="hidden" name="{{ id }}[_action]" value="fetch-console"> |
11 | - <?php wp_nonce_field('fetch-console'); ?> |
|
11 | + <?php wp_nonce_field( 'fetch-console' ); ?> |
|
12 | 12 | <button type="submit" class="glsr-button button" id="fetch-console"> |
13 | - <span data-loading="<?= __('Reloading...', 'site-reviews'); ?>"><?= __('Reload', 'site-reviews'); ?></span> |
|
13 | + <span data-loading="<?= __( 'Reloading...', 'site-reviews' ); ?>"><?= __( 'Reload', 'site-reviews' ); ?></span> |
|
14 | 14 | </button> |
15 | 15 | </form> |
16 | 16 | <form method="post"> |
17 | 17 | <input type="hidden" name="{{ id }}[_action]" value="clear-console"> |
18 | - <?php wp_nonce_field('clear-console'); ?> |
|
18 | + <?php wp_nonce_field( 'clear-console' ); ?> |
|
19 | 19 | <button type="submit" class="glsr-button button" id="clear-console"> |
20 | - <span data-loading="<?= __('Clearing...', 'site-reviews'); ?>"><?= __('Clear', 'site-reviews'); ?></span> |
|
20 | + <span data-loading="<?= __( 'Clearing...', 'site-reviews' ); ?>"><?= __( 'Clear', 'site-reviews' ); ?></span> |
|
21 | 21 | </button> |
22 | 22 | </form> |