@@ -8,114 +8,114 @@ |
||
8 | 8 | |
9 | 9 | class Notice |
10 | 10 | { |
11 | - /** |
|
12 | - * @param string $type |
|
13 | - * @param string|array|WP_Error $message |
|
14 | - * @return void |
|
15 | - */ |
|
16 | - public function add($type, $message, array $args = []) |
|
17 | - { |
|
18 | - if (empty(array_filter([$message, $type]))) { |
|
19 | - return; |
|
20 | - } |
|
21 | - $args['message'] = $message; |
|
22 | - $args['type'] = $type; |
|
23 | - add_settings_error(Application::ID, '', json_encode($this->normalize($args))); |
|
24 | - } |
|
11 | + /** |
|
12 | + * @param string $type |
|
13 | + * @param string|array|WP_Error $message |
|
14 | + * @return void |
|
15 | + */ |
|
16 | + public function add($type, $message, array $args = []) |
|
17 | + { |
|
18 | + if (empty(array_filter([$message, $type]))) { |
|
19 | + return; |
|
20 | + } |
|
21 | + $args['message'] = $message; |
|
22 | + $args['type'] = $type; |
|
23 | + add_settings_error(Application::ID, '', json_encode($this->normalize($args))); |
|
24 | + } |
|
25 | 25 | |
26 | - /** |
|
27 | - * @param string|array|WP_Error $message |
|
28 | - * @return void |
|
29 | - */ |
|
30 | - public function addError($message, array $args = []) |
|
31 | - { |
|
32 | - $this->add('error', $message, $args); |
|
33 | - } |
|
26 | + /** |
|
27 | + * @param string|array|WP_Error $message |
|
28 | + * @return void |
|
29 | + */ |
|
30 | + public function addError($message, array $args = []) |
|
31 | + { |
|
32 | + $this->add('error', $message, $args); |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * @param string|array|WP_Error $message |
|
37 | - * @return void |
|
38 | - */ |
|
39 | - public function addSuccess($message, array $args = []) |
|
40 | - { |
|
41 | - $this->add('success', $message, $args); |
|
42 | - } |
|
35 | + /** |
|
36 | + * @param string|array|WP_Error $message |
|
37 | + * @return void |
|
38 | + */ |
|
39 | + public function addSuccess($message, array $args = []) |
|
40 | + { |
|
41 | + $this->add('success', $message, $args); |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * @param string|array|WP_Error $message |
|
46 | - * @return void |
|
47 | - */ |
|
48 | - public function addWarning($message, array $args = []) |
|
49 | - { |
|
50 | - $this->add('warning', $message, $args); |
|
51 | - } |
|
44 | + /** |
|
45 | + * @param string|array|WP_Error $message |
|
46 | + * @return void |
|
47 | + */ |
|
48 | + public function addWarning($message, array $args = []) |
|
49 | + { |
|
50 | + $this->add('warning', $message, $args); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @return static |
|
55 | - */ |
|
56 | - public function clear() |
|
57 | - { |
|
58 | - global $wp_settings_errors; |
|
59 | - $wp_settings_errors = []; |
|
60 | - delete_transient('settings_errors'); |
|
61 | - return $this; |
|
62 | - } |
|
53 | + /** |
|
54 | + * @return static |
|
55 | + */ |
|
56 | + public function clear() |
|
57 | + { |
|
58 | + global $wp_settings_errors; |
|
59 | + $wp_settings_errors = []; |
|
60 | + delete_transient('settings_errors'); |
|
61 | + return $this; |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @return string |
|
66 | - */ |
|
67 | - public function get() |
|
68 | - { |
|
69 | - $notices = array_map('unserialize', |
|
70 | - array_unique(array_map('serialize', get_settings_errors(Application::ID))) |
|
71 | - ); |
|
72 | - if (empty($notices)) { |
|
73 | - return; |
|
74 | - } |
|
75 | - return array_reduce($notices, function ($carry, $notice) { |
|
76 | - return $carry.$this->buildNotice(json_decode($notice['message'], true)); |
|
77 | - }); |
|
78 | - } |
|
64 | + /** |
|
65 | + * @return string |
|
66 | + */ |
|
67 | + public function get() |
|
68 | + { |
|
69 | + $notices = array_map('unserialize', |
|
70 | + array_unique(array_map('serialize', get_settings_errors(Application::ID))) |
|
71 | + ); |
|
72 | + if (empty($notices)) { |
|
73 | + return; |
|
74 | + } |
|
75 | + return array_reduce($notices, function ($carry, $notice) { |
|
76 | + return $carry.$this->buildNotice(json_decode($notice['message'], true)); |
|
77 | + }); |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * @return string |
|
82 | - */ |
|
83 | - protected function buildNotice(array $args) |
|
84 | - { |
|
85 | - $messages = array_reduce($args['messages'], function ($carry, $message) { |
|
86 | - return $carry.glsr(Builder::class)->p($message); |
|
87 | - }); |
|
88 | - $class = 'notice notice-'.$args['type']; |
|
89 | - if ($args['inline']) { |
|
90 | - $class.= ' inline'; |
|
91 | - } |
|
92 | - if ($args['dismissible']) { |
|
93 | - $class.= ' is-dismissible'; |
|
94 | - } |
|
95 | - return glsr(Builder::class)->div($messages, [ |
|
96 | - 'class' => $class, |
|
97 | - ]); |
|
98 | - } |
|
80 | + /** |
|
81 | + * @return string |
|
82 | + */ |
|
83 | + protected function buildNotice(array $args) |
|
84 | + { |
|
85 | + $messages = array_reduce($args['messages'], function ($carry, $message) { |
|
86 | + return $carry.glsr(Builder::class)->p($message); |
|
87 | + }); |
|
88 | + $class = 'notice notice-'.$args['type']; |
|
89 | + if ($args['inline']) { |
|
90 | + $class.= ' inline'; |
|
91 | + } |
|
92 | + if ($args['dismissible']) { |
|
93 | + $class.= ' is-dismissible'; |
|
94 | + } |
|
95 | + return glsr(Builder::class)->div($messages, [ |
|
96 | + 'class' => $class, |
|
97 | + ]); |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * @return array |
|
102 | - */ |
|
103 | - protected function normalize(array $args) |
|
104 | - { |
|
105 | - $defaults = [ |
|
106 | - 'dismissible' => true, |
|
107 | - 'inline' => true, |
|
108 | - 'message' => '', |
|
109 | - 'type' => '', |
|
110 | - ]; |
|
111 | - $args = shortcode_atts($defaults, $args); |
|
112 | - if (!in_array($args['type'], ['error', 'warning', 'success'])) { |
|
113 | - $args['type'] = 'success'; |
|
114 | - } |
|
115 | - $args['messages'] = is_wp_error($args['message']) |
|
116 | - ? (array) $args['message']->get_error_message() |
|
117 | - : (array) $args['message']; |
|
118 | - unset($args['message']); |
|
119 | - return $args; |
|
120 | - } |
|
100 | + /** |
|
101 | + * @return array |
|
102 | + */ |
|
103 | + protected function normalize(array $args) |
|
104 | + { |
|
105 | + $defaults = [ |
|
106 | + 'dismissible' => true, |
|
107 | + 'inline' => true, |
|
108 | + 'message' => '', |
|
109 | + 'type' => '', |
|
110 | + ]; |
|
111 | + $args = shortcode_atts($defaults, $args); |
|
112 | + if (!in_array($args['type'], ['error', 'warning', 'success'])) { |
|
113 | + $args['type'] = 'success'; |
|
114 | + } |
|
115 | + $args['messages'] = is_wp_error($args['message']) |
|
116 | + ? (array) $args['message']->get_error_message() |
|
117 | + : (array) $args['message']; |
|
118 | + unset($args['message']); |
|
119 | + return $args; |
|
120 | + } |
|
121 | 121 | } |
@@ -10,272 +10,272 @@ |
||
10 | 10 | |
11 | 11 | class Translation |
12 | 12 | { |
13 | - const SEARCH_THRESHOLD = 3; |
|
13 | + const SEARCH_THRESHOLD = 3; |
|
14 | 14 | |
15 | - /** |
|
16 | - * @var array |
|
17 | - */ |
|
18 | - protected $entries; |
|
15 | + /** |
|
16 | + * @var array |
|
17 | + */ |
|
18 | + protected $entries; |
|
19 | 19 | |
20 | - /** |
|
21 | - * @var array |
|
22 | - */ |
|
23 | - protected $results; |
|
20 | + /** |
|
21 | + * @var array |
|
22 | + */ |
|
23 | + protected $results; |
|
24 | 24 | |
25 | - /** |
|
26 | - * Returns all saved custom translations with translation context. |
|
27 | - * @return array |
|
28 | - */ |
|
29 | - public function all() |
|
30 | - { |
|
31 | - $translations = $this->translations(); |
|
32 | - $entries = $this->filter($translations, $this->entries())->results(); |
|
33 | - array_walk($translations, function (&$entry) use ($entries) { |
|
34 | - $entry['desc'] = array_key_exists($entry['id'], $entries) |
|
35 | - ? $this->getEntryString($entries[$entry['id']], 'msgctxt') |
|
36 | - : ''; |
|
37 | - }); |
|
38 | - return $translations; |
|
39 | - } |
|
25 | + /** |
|
26 | + * Returns all saved custom translations with translation context. |
|
27 | + * @return array |
|
28 | + */ |
|
29 | + public function all() |
|
30 | + { |
|
31 | + $translations = $this->translations(); |
|
32 | + $entries = $this->filter($translations, $this->entries())->results(); |
|
33 | + array_walk($translations, function (&$entry) use ($entries) { |
|
34 | + $entry['desc'] = array_key_exists($entry['id'], $entries) |
|
35 | + ? $this->getEntryString($entries[$entry['id']], 'msgctxt') |
|
36 | + : ''; |
|
37 | + }); |
|
38 | + return $translations; |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * @return array |
|
43 | - */ |
|
44 | - public function entries() |
|
45 | - { |
|
46 | - if (!isset($this->entries)) { |
|
47 | - $potFile = glsr()->path(glsr()->languages.'/'.Application::ID.'.pot'); |
|
48 | - $entries = $this->extractEntriesFromPotFile($potFile); |
|
49 | - $entries = apply_filters('site-reviews/translation/entries', $entries); |
|
50 | - $this->entries = $entries; |
|
51 | - } |
|
52 | - return $this->entries; |
|
53 | - } |
|
41 | + /** |
|
42 | + * @return array |
|
43 | + */ |
|
44 | + public function entries() |
|
45 | + { |
|
46 | + if (!isset($this->entries)) { |
|
47 | + $potFile = glsr()->path(glsr()->languages.'/'.Application::ID.'.pot'); |
|
48 | + $entries = $this->extractEntriesFromPotFile($potFile); |
|
49 | + $entries = apply_filters('site-reviews/translation/entries', $entries); |
|
50 | + $this->entries = $entries; |
|
51 | + } |
|
52 | + return $this->entries; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * @param array|null $entriesToExclude |
|
57 | - * @param array|null $entries |
|
58 | - * @return static |
|
59 | - */ |
|
60 | - public function exclude($entriesToExclude = null, $entries = null) |
|
61 | - { |
|
62 | - return $this->filter($entriesToExclude, $entries, false); |
|
63 | - } |
|
55 | + /** |
|
56 | + * @param array|null $entriesToExclude |
|
57 | + * @param array|null $entries |
|
58 | + * @return static |
|
59 | + */ |
|
60 | + public function exclude($entriesToExclude = null, $entries = null) |
|
61 | + { |
|
62 | + return $this->filter($entriesToExclude, $entries, false); |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * @param string $potFile |
|
67 | - * @return array |
|
68 | - */ |
|
69 | - public function extractEntriesFromPotFile($potFile, array $entries = []) |
|
70 | - { |
|
71 | - try { |
|
72 | - $potEntries = $this->normalize(Parser::parseFile($potFile)->getEntries()); |
|
73 | - foreach ($potEntries as $key => $entry) { |
|
74 | - $entries[html_entity_decode($key, ENT_COMPAT, 'UTF-8')] = $entry; |
|
75 | - } |
|
76 | - } catch (Exception $e) { |
|
77 | - glsr_log()->error($e->getMessage()); |
|
78 | - } |
|
79 | - return $entries; |
|
80 | - } |
|
65 | + /** |
|
66 | + * @param string $potFile |
|
67 | + * @return array |
|
68 | + */ |
|
69 | + public function extractEntriesFromPotFile($potFile, array $entries = []) |
|
70 | + { |
|
71 | + try { |
|
72 | + $potEntries = $this->normalize(Parser::parseFile($potFile)->getEntries()); |
|
73 | + foreach ($potEntries as $key => $entry) { |
|
74 | + $entries[html_entity_decode($key, ENT_COMPAT, 'UTF-8')] = $entry; |
|
75 | + } |
|
76 | + } catch (Exception $e) { |
|
77 | + glsr_log()->error($e->getMessage()); |
|
78 | + } |
|
79 | + return $entries; |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * @param array|null $filterWith |
|
84 | - * @param array|null $entries |
|
85 | - * @param bool $intersect |
|
86 | - * @return static |
|
87 | - */ |
|
88 | - public function filter($filterWith = null, $entries = null, $intersect = true) |
|
89 | - { |
|
90 | - if (!is_array($entries)) { |
|
91 | - $entries = $this->results; |
|
92 | - } |
|
93 | - if (!is_array($filterWith)) { |
|
94 | - $filterWith = $this->translations(); |
|
95 | - } |
|
96 | - $keys = array_flip(glsr_array_column($filterWith, 'id')); |
|
97 | - $this->results = $intersect |
|
98 | - ? array_intersect_key($entries, $keys) |
|
99 | - : array_diff_key($entries, $keys); |
|
100 | - return $this; |
|
101 | - } |
|
82 | + /** |
|
83 | + * @param array|null $filterWith |
|
84 | + * @param array|null $entries |
|
85 | + * @param bool $intersect |
|
86 | + * @return static |
|
87 | + */ |
|
88 | + public function filter($filterWith = null, $entries = null, $intersect = true) |
|
89 | + { |
|
90 | + if (!is_array($entries)) { |
|
91 | + $entries = $this->results; |
|
92 | + } |
|
93 | + if (!is_array($filterWith)) { |
|
94 | + $filterWith = $this->translations(); |
|
95 | + } |
|
96 | + $keys = array_flip(glsr_array_column($filterWith, 'id')); |
|
97 | + $this->results = $intersect |
|
98 | + ? array_intersect_key($entries, $keys) |
|
99 | + : array_diff_key($entries, $keys); |
|
100 | + return $this; |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * @param string $template |
|
105 | - * @return string |
|
106 | - */ |
|
107 | - public function render($template, array $entry) |
|
108 | - { |
|
109 | - $data = array_combine( |
|
110 | - array_map(function ($key) { return 'data.'.$key; }, array_keys($entry)), |
|
111 | - $entry |
|
112 | - ); |
|
113 | - $data['data.class'] = $data['data.error'] = ''; |
|
114 | - if (false === array_search($entry['s1'], glsr_array_column($this->entries(), 'msgid'))) { |
|
115 | - $data['data.class'] = 'is-invalid'; |
|
116 | - $data['data.error'] = __('This custom translation is no longer valid as the original text has been changed or removed.', 'site-reviews'); |
|
117 | - } |
|
118 | - return glsr(Template::class)->build('partials/translations/'.$template, [ |
|
119 | - 'context' => $data, |
|
120 | - ]); |
|
121 | - } |
|
103 | + /** |
|
104 | + * @param string $template |
|
105 | + * @return string |
|
106 | + */ |
|
107 | + public function render($template, array $entry) |
|
108 | + { |
|
109 | + $data = array_combine( |
|
110 | + array_map(function ($key) { return 'data.'.$key; }, array_keys($entry)), |
|
111 | + $entry |
|
112 | + ); |
|
113 | + $data['data.class'] = $data['data.error'] = ''; |
|
114 | + if (false === array_search($entry['s1'], glsr_array_column($this->entries(), 'msgid'))) { |
|
115 | + $data['data.class'] = 'is-invalid'; |
|
116 | + $data['data.error'] = __('This custom translation is no longer valid as the original text has been changed or removed.', 'site-reviews'); |
|
117 | + } |
|
118 | + return glsr(Template::class)->build('partials/translations/'.$template, [ |
|
119 | + 'context' => $data, |
|
120 | + ]); |
|
121 | + } |
|
122 | 122 | |
123 | - /** |
|
124 | - * Returns a rendered string of all saved custom translations with translation context. |
|
125 | - * @return string |
|
126 | - */ |
|
127 | - public function renderAll() |
|
128 | - { |
|
129 | - $rendered = ''; |
|
130 | - foreach ($this->all() as $index => $entry) { |
|
131 | - $entry['index'] = $index; |
|
132 | - $entry['prefix'] = OptionManager::databaseKey(); |
|
133 | - $rendered.= $this->render($entry['type'], $entry); |
|
134 | - } |
|
135 | - return $rendered; |
|
136 | - } |
|
123 | + /** |
|
124 | + * Returns a rendered string of all saved custom translations with translation context. |
|
125 | + * @return string |
|
126 | + */ |
|
127 | + public function renderAll() |
|
128 | + { |
|
129 | + $rendered = ''; |
|
130 | + foreach ($this->all() as $index => $entry) { |
|
131 | + $entry['index'] = $index; |
|
132 | + $entry['prefix'] = OptionManager::databaseKey(); |
|
133 | + $rendered.= $this->render($entry['type'], $entry); |
|
134 | + } |
|
135 | + return $rendered; |
|
136 | + } |
|
137 | 137 | |
138 | - /** |
|
139 | - * @param bool $resetAfterRender |
|
140 | - * @return string |
|
141 | - */ |
|
142 | - public function renderResults($resetAfterRender = true) |
|
143 | - { |
|
144 | - $rendered = ''; |
|
145 | - foreach ($this->results as $id => $entry) { |
|
146 | - $data = [ |
|
147 | - 'desc' => $this->getEntryString($entry, 'msgctxt'), |
|
148 | - 'id' => $id, |
|
149 | - 'p1' => $this->getEntryString($entry, 'msgid_plural'), |
|
150 | - 's1' => $this->getEntryString($entry, 'msgid'), |
|
151 | - ]; |
|
152 | - $text = !empty($data['p1']) |
|
153 | - ? sprintf('%s | %s', $data['s1'], $data['p1']) |
|
154 | - : $data['s1']; |
|
155 | - $rendered.= $this->render('result', [ |
|
156 | - 'entry' => json_encode($data, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), |
|
157 | - 'text' => wp_strip_all_tags($text), |
|
158 | - ]); |
|
159 | - } |
|
160 | - if ($resetAfterRender) { |
|
161 | - $this->reset(); |
|
162 | - } |
|
163 | - return $rendered; |
|
164 | - } |
|
138 | + /** |
|
139 | + * @param bool $resetAfterRender |
|
140 | + * @return string |
|
141 | + */ |
|
142 | + public function renderResults($resetAfterRender = true) |
|
143 | + { |
|
144 | + $rendered = ''; |
|
145 | + foreach ($this->results as $id => $entry) { |
|
146 | + $data = [ |
|
147 | + 'desc' => $this->getEntryString($entry, 'msgctxt'), |
|
148 | + 'id' => $id, |
|
149 | + 'p1' => $this->getEntryString($entry, 'msgid_plural'), |
|
150 | + 's1' => $this->getEntryString($entry, 'msgid'), |
|
151 | + ]; |
|
152 | + $text = !empty($data['p1']) |
|
153 | + ? sprintf('%s | %s', $data['s1'], $data['p1']) |
|
154 | + : $data['s1']; |
|
155 | + $rendered.= $this->render('result', [ |
|
156 | + 'entry' => json_encode($data, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), |
|
157 | + 'text' => wp_strip_all_tags($text), |
|
158 | + ]); |
|
159 | + } |
|
160 | + if ($resetAfterRender) { |
|
161 | + $this->reset(); |
|
162 | + } |
|
163 | + return $rendered; |
|
164 | + } |
|
165 | 165 | |
166 | - /** |
|
167 | - * @return void |
|
168 | - */ |
|
169 | - public function reset() |
|
170 | - { |
|
171 | - $this->results = []; |
|
172 | - } |
|
166 | + /** |
|
167 | + * @return void |
|
168 | + */ |
|
169 | + public function reset() |
|
170 | + { |
|
171 | + $this->results = []; |
|
172 | + } |
|
173 | 173 | |
174 | - /** |
|
175 | - * @return array |
|
176 | - */ |
|
177 | - public function results() |
|
178 | - { |
|
179 | - $results = $this->results; |
|
180 | - $this->reset(); |
|
181 | - return $results; |
|
182 | - } |
|
174 | + /** |
|
175 | + * @return array |
|
176 | + */ |
|
177 | + public function results() |
|
178 | + { |
|
179 | + $results = $this->results; |
|
180 | + $this->reset(); |
|
181 | + return $results; |
|
182 | + } |
|
183 | 183 | |
184 | - /** |
|
185 | - * @param string $needle |
|
186 | - * @return static |
|
187 | - */ |
|
188 | - public function search($needle = '') |
|
189 | - { |
|
190 | - $this->reset(); |
|
191 | - $needle = trim(strtolower($needle)); |
|
192 | - foreach ($this->entries() as $key => $entry) { |
|
193 | - $single = strtolower($this->getEntryString($entry, 'msgid')); |
|
194 | - $plural = strtolower($this->getEntryString($entry, 'msgid_plural')); |
|
195 | - if (strlen($needle) < static::SEARCH_THRESHOLD) { |
|
196 | - if (in_array($needle, [$single, $plural])) { |
|
197 | - $this->results[$key] = $entry; |
|
198 | - } |
|
199 | - } elseif (false !== strpos(sprintf('%s %s', $single, $plural), $needle)) { |
|
200 | - $this->results[$key] = $entry; |
|
201 | - } |
|
202 | - } |
|
203 | - return $this; |
|
204 | - } |
|
184 | + /** |
|
185 | + * @param string $needle |
|
186 | + * @return static |
|
187 | + */ |
|
188 | + public function search($needle = '') |
|
189 | + { |
|
190 | + $this->reset(); |
|
191 | + $needle = trim(strtolower($needle)); |
|
192 | + foreach ($this->entries() as $key => $entry) { |
|
193 | + $single = strtolower($this->getEntryString($entry, 'msgid')); |
|
194 | + $plural = strtolower($this->getEntryString($entry, 'msgid_plural')); |
|
195 | + if (strlen($needle) < static::SEARCH_THRESHOLD) { |
|
196 | + if (in_array($needle, [$single, $plural])) { |
|
197 | + $this->results[$key] = $entry; |
|
198 | + } |
|
199 | + } elseif (false !== strpos(sprintf('%s %s', $single, $plural), $needle)) { |
|
200 | + $this->results[$key] = $entry; |
|
201 | + } |
|
202 | + } |
|
203 | + return $this; |
|
204 | + } |
|
205 | 205 | |
206 | - /** |
|
207 | - * Store the translations to avoid unnecessary loops. |
|
208 | - * @return array |
|
209 | - */ |
|
210 | - public function translations() |
|
211 | - { |
|
212 | - static $translations; |
|
213 | - if (empty($translations)) { |
|
214 | - $settings = glsr(OptionManager::class)->get('settings'); |
|
215 | - $translations = isset($settings['strings']) |
|
216 | - ? $this->normalizeSettings((array) $settings['strings']) |
|
217 | - : []; |
|
218 | - } |
|
219 | - return $translations; |
|
220 | - } |
|
206 | + /** |
|
207 | + * Store the translations to avoid unnecessary loops. |
|
208 | + * @return array |
|
209 | + */ |
|
210 | + public function translations() |
|
211 | + { |
|
212 | + static $translations; |
|
213 | + if (empty($translations)) { |
|
214 | + $settings = glsr(OptionManager::class)->get('settings'); |
|
215 | + $translations = isset($settings['strings']) |
|
216 | + ? $this->normalizeSettings((array) $settings['strings']) |
|
217 | + : []; |
|
218 | + } |
|
219 | + return $translations; |
|
220 | + } |
|
221 | 221 | |
222 | - /** |
|
223 | - * @param string $key |
|
224 | - * @return string |
|
225 | - */ |
|
226 | - protected function getEntryString(array $entry, $key) |
|
227 | - { |
|
228 | - return isset($entry[$key]) |
|
229 | - ? implode('', (array) $entry[$key]) |
|
230 | - : ''; |
|
231 | - } |
|
222 | + /** |
|
223 | + * @param string $key |
|
224 | + * @return string |
|
225 | + */ |
|
226 | + protected function getEntryString(array $entry, $key) |
|
227 | + { |
|
228 | + return isset($entry[$key]) |
|
229 | + ? implode('', (array) $entry[$key]) |
|
230 | + : ''; |
|
231 | + } |
|
232 | 232 | |
233 | - /** |
|
234 | - * @return array |
|
235 | - */ |
|
236 | - protected function normalize(array $entries) |
|
237 | - { |
|
238 | - $keys = [ |
|
239 | - 'msgctxt', 'msgid', 'msgid_plural', 'msgstr', 'msgstr[0]', 'msgstr[1]', |
|
240 | - ]; |
|
241 | - array_walk($entries, function (&$entry) use ($keys) { |
|
242 | - foreach ($keys as $key) { |
|
243 | - try { |
|
244 | - $entry = $this->normalizeEntryString($entry, $key); |
|
245 | - } catch (\TypeError $error) { |
|
246 | - glsr_log()->once('error', 'Translation/normalize', $error); |
|
247 | - glsr_log()->once('debug', 'Translation/normalize', $entry); |
|
248 | - } |
|
249 | - } |
|
250 | - }); |
|
251 | - return $entries; |
|
252 | - } |
|
233 | + /** |
|
234 | + * @return array |
|
235 | + */ |
|
236 | + protected function normalize(array $entries) |
|
237 | + { |
|
238 | + $keys = [ |
|
239 | + 'msgctxt', 'msgid', 'msgid_plural', 'msgstr', 'msgstr[0]', 'msgstr[1]', |
|
240 | + ]; |
|
241 | + array_walk($entries, function (&$entry) use ($keys) { |
|
242 | + foreach ($keys as $key) { |
|
243 | + try { |
|
244 | + $entry = $this->normalizeEntryString($entry, $key); |
|
245 | + } catch (\TypeError $error) { |
|
246 | + glsr_log()->once('error', 'Translation/normalize', $error); |
|
247 | + glsr_log()->once('debug', 'Translation/normalize', $entry); |
|
248 | + } |
|
249 | + } |
|
250 | + }); |
|
251 | + return $entries; |
|
252 | + } |
|
253 | 253 | |
254 | - /** |
|
255 | - * @param string $key |
|
256 | - * @return array |
|
257 | - */ |
|
258 | - protected function normalizeEntryString(array $entry, $key) |
|
259 | - { |
|
260 | - if (isset($entry[$key])) { |
|
261 | - $entry[$key] = $this->getEntryString($entry, $key); |
|
262 | - } |
|
263 | - return $entry; |
|
264 | - } |
|
254 | + /** |
|
255 | + * @param string $key |
|
256 | + * @return array |
|
257 | + */ |
|
258 | + protected function normalizeEntryString(array $entry, $key) |
|
259 | + { |
|
260 | + if (isset($entry[$key])) { |
|
261 | + $entry[$key] = $this->getEntryString($entry, $key); |
|
262 | + } |
|
263 | + return $entry; |
|
264 | + } |
|
265 | 265 | |
266 | - /** |
|
267 | - * @return array |
|
268 | - */ |
|
269 | - protected function normalizeSettings(array $strings) |
|
270 | - { |
|
271 | - $defaultString = array_fill_keys(['id', 's1', 's2', 'p1', 'p2'], ''); |
|
272 | - $strings = array_filter($strings, 'is_array'); |
|
273 | - foreach ($strings as &$string) { |
|
274 | - $string['type'] = isset($string['p1']) ? 'plural' : 'single'; |
|
275 | - $string = wp_parse_args($string, $defaultString); |
|
276 | - } |
|
277 | - return array_filter($strings, function ($string) { |
|
278 | - return !empty($string['id']); |
|
279 | - }); |
|
280 | - } |
|
266 | + /** |
|
267 | + * @return array |
|
268 | + */ |
|
269 | + protected function normalizeSettings(array $strings) |
|
270 | + { |
|
271 | + $defaultString = array_fill_keys(['id', 's1', 's2', 'p1', 'p2'], ''); |
|
272 | + $strings = array_filter($strings, 'is_array'); |
|
273 | + foreach ($strings as &$string) { |
|
274 | + $string['type'] = isset($string['p1']) ? 'plural' : 'single'; |
|
275 | + $string = wp_parse_args($string, $defaultString); |
|
276 | + } |
|
277 | + return array_filter($strings, function ($string) { |
|
278 | + return !empty($string['id']); |
|
279 | + }); |
|
280 | + } |
|
281 | 281 | } |
@@ -7,283 +7,283 @@ |
||
7 | 7 | |
8 | 8 | final class Application extends Container |
9 | 9 | { |
10 | - const CAPABILITY = 'edit_others_posts'; |
|
11 | - const CRON_EVENT = 'site-reviews/schedule/session/purge'; |
|
12 | - const ID = 'site-reviews'; |
|
13 | - const PAGED_QUERY_VAR = 'reviews-page'; |
|
14 | - const POST_TYPE = 'site-review'; |
|
15 | - const PREFIX = 'glsr_'; |
|
16 | - const TAXONOMY = 'site-review-category'; |
|
10 | + const CAPABILITY = 'edit_others_posts'; |
|
11 | + const CRON_EVENT = 'site-reviews/schedule/session/purge'; |
|
12 | + const ID = 'site-reviews'; |
|
13 | + const PAGED_QUERY_VAR = 'reviews-page'; |
|
14 | + const POST_TYPE = 'site-review'; |
|
15 | + const PREFIX = 'glsr_'; |
|
16 | + const TAXONOMY = 'site-review-category'; |
|
17 | 17 | |
18 | - public $defaults; |
|
19 | - public $deprecated = []; |
|
20 | - public $file; |
|
21 | - public $languages; |
|
22 | - public $mceShortcodes = []; //defined elsewhere |
|
23 | - public $name; |
|
24 | - public $reviewTypes; |
|
25 | - public $schemas = []; //defined elsewhere |
|
26 | - public $version; |
|
18 | + public $defaults; |
|
19 | + public $deprecated = []; |
|
20 | + public $file; |
|
21 | + public $languages; |
|
22 | + public $mceShortcodes = []; //defined elsewhere |
|
23 | + public $name; |
|
24 | + public $reviewTypes; |
|
25 | + public $schemas = []; //defined elsewhere |
|
26 | + public $version; |
|
27 | 27 | |
28 | - public function __construct() |
|
29 | - { |
|
30 | - static::$instance = $this; |
|
31 | - $this->file = realpath(trailingslashit(dirname(__DIR__)).static::ID.'.php'); |
|
32 | - $plugin = get_file_data($this->file, [ |
|
33 | - 'languages' => 'Domain Path', |
|
34 | - 'name' => 'Plugin Name', |
|
35 | - 'version' => 'Version', |
|
36 | - ], 'plugin'); |
|
37 | - array_walk($plugin, function ($value, $key) { |
|
38 | - $this->$key = $value; |
|
39 | - }); |
|
40 | - } |
|
28 | + public function __construct() |
|
29 | + { |
|
30 | + static::$instance = $this; |
|
31 | + $this->file = realpath(trailingslashit(dirname(__DIR__)).static::ID.'.php'); |
|
32 | + $plugin = get_file_data($this->file, [ |
|
33 | + 'languages' => 'Domain Path', |
|
34 | + 'name' => 'Plugin Name', |
|
35 | + 'version' => 'Version', |
|
36 | + ], 'plugin'); |
|
37 | + array_walk($plugin, function ($value, $key) { |
|
38 | + $this->$key = $value; |
|
39 | + }); |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * @return void |
|
44 | - */ |
|
45 | - public function activate() |
|
46 | - { |
|
47 | - $this->make(DefaultsManager::class)->set(); |
|
48 | - $this->scheduleCronJob(); |
|
49 | - $this->upgrade(); |
|
50 | - } |
|
42 | + /** |
|
43 | + * @return void |
|
44 | + */ |
|
45 | + public function activate() |
|
46 | + { |
|
47 | + $this->make(DefaultsManager::class)->set(); |
|
48 | + $this->scheduleCronJob(); |
|
49 | + $this->upgrade(); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * @return void |
|
54 | - */ |
|
55 | - public function catchFatalError() |
|
56 | - { |
|
57 | - $error = error_get_last(); |
|
58 | - if (E_ERROR !== $error['type'] || false === strpos($error['message'], $this->path())) { |
|
59 | - return; |
|
60 | - } |
|
61 | - glsr_log()->error($error['message']); |
|
62 | - } |
|
52 | + /** |
|
53 | + * @return void |
|
54 | + */ |
|
55 | + public function catchFatalError() |
|
56 | + { |
|
57 | + $error = error_get_last(); |
|
58 | + if (E_ERROR !== $error['type'] || false === strpos($error['message'], $this->path())) { |
|
59 | + return; |
|
60 | + } |
|
61 | + glsr_log()->error($error['message']); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @param string $name |
|
66 | - * @return array |
|
67 | - */ |
|
68 | - public function config($name) |
|
69 | - { |
|
70 | - $configFile = $this->path('config/'.$name.'.php'); |
|
71 | - $config = file_exists($configFile) |
|
72 | - ? include $configFile |
|
73 | - : []; |
|
74 | - return apply_filters('site-reviews/config/'.$name, $config); |
|
75 | - } |
|
64 | + /** |
|
65 | + * @param string $name |
|
66 | + * @return array |
|
67 | + */ |
|
68 | + public function config($name) |
|
69 | + { |
|
70 | + $configFile = $this->path('config/'.$name.'.php'); |
|
71 | + $config = file_exists($configFile) |
|
72 | + ? include $configFile |
|
73 | + : []; |
|
74 | + return apply_filters('site-reviews/config/'.$name, $config); |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * @param string $property |
|
79 | - * @return string |
|
80 | - */ |
|
81 | - public function constant($property, $className = 'static') |
|
82 | - { |
|
83 | - $constant = $className.'::'.$property; |
|
84 | - return defined($constant) |
|
85 | - ? apply_filters('site-reviews/const/'.$property, constant($constant)) |
|
86 | - : ''; |
|
87 | - } |
|
77 | + /** |
|
78 | + * @param string $property |
|
79 | + * @return string |
|
80 | + */ |
|
81 | + public function constant($property, $className = 'static') |
|
82 | + { |
|
83 | + $constant = $className.'::'.$property; |
|
84 | + return defined($constant) |
|
85 | + ? apply_filters('site-reviews/const/'.$property, constant($constant)) |
|
86 | + : ''; |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * @return void |
|
91 | - */ |
|
92 | - public function deactivate() |
|
93 | - { |
|
94 | - $this->unscheduleCronJob(); |
|
95 | - } |
|
89 | + /** |
|
90 | + * @return void |
|
91 | + */ |
|
92 | + public function deactivate() |
|
93 | + { |
|
94 | + $this->unscheduleCronJob(); |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * @param string $view |
|
99 | - * @return void|string |
|
100 | - */ |
|
101 | - public function file($view) |
|
102 | - { |
|
103 | - $view.= '.php'; |
|
104 | - $filePaths = []; |
|
105 | - if (glsr(Helper::class)->startsWith('templates/', $view)) { |
|
106 | - $filePaths[] = $this->themePath(glsr(Helper::class)->removePrefix('templates/', $view)); |
|
107 | - } |
|
108 | - $filePaths[] = $this->path($view); |
|
109 | - $filePaths[] = $this->path('views/'.$view); |
|
110 | - foreach ($filePaths as $file) { |
|
111 | - if (!file_exists($file)) { |
|
112 | - continue; |
|
113 | - } |
|
114 | - return $file; |
|
115 | - } |
|
116 | - } |
|
97 | + /** |
|
98 | + * @param string $view |
|
99 | + * @return void|string |
|
100 | + */ |
|
101 | + public function file($view) |
|
102 | + { |
|
103 | + $view.= '.php'; |
|
104 | + $filePaths = []; |
|
105 | + if (glsr(Helper::class)->startsWith('templates/', $view)) { |
|
106 | + $filePaths[] = $this->themePath(glsr(Helper::class)->removePrefix('templates/', $view)); |
|
107 | + } |
|
108 | + $filePaths[] = $this->path($view); |
|
109 | + $filePaths[] = $this->path('views/'.$view); |
|
110 | + foreach ($filePaths as $file) { |
|
111 | + if (!file_exists($file)) { |
|
112 | + continue; |
|
113 | + } |
|
114 | + return $file; |
|
115 | + } |
|
116 | + } |
|
117 | 117 | |
118 | - /** |
|
119 | - * @return array |
|
120 | - */ |
|
121 | - public function getDefaults() |
|
122 | - { |
|
123 | - if (empty($this->defaults)) { |
|
124 | - $this->defaults = $this->make(DefaultsManager::class)->get(); |
|
125 | - $this->upgrade(); |
|
126 | - } |
|
127 | - return apply_filters('site-reviews/get/defaults', $this->defaults); |
|
128 | - } |
|
118 | + /** |
|
119 | + * @return array |
|
120 | + */ |
|
121 | + public function getDefaults() |
|
122 | + { |
|
123 | + if (empty($this->defaults)) { |
|
124 | + $this->defaults = $this->make(DefaultsManager::class)->get(); |
|
125 | + $this->upgrade(); |
|
126 | + } |
|
127 | + return apply_filters('site-reviews/get/defaults', $this->defaults); |
|
128 | + } |
|
129 | 129 | |
130 | - /** |
|
131 | - * @return bool |
|
132 | - */ |
|
133 | - public function getPermission($page = '') |
|
134 | - { |
|
135 | - $permissions = [ |
|
136 | - 'addons' => 'install_plugins', |
|
137 | - 'settings' => 'manage_options', |
|
138 | - ]; |
|
139 | - return glsr_get($permissions, $page, $this->constant('CAPABILITY')); |
|
140 | - } |
|
130 | + /** |
|
131 | + * @return bool |
|
132 | + */ |
|
133 | + public function getPermission($page = '') |
|
134 | + { |
|
135 | + $permissions = [ |
|
136 | + 'addons' => 'install_plugins', |
|
137 | + 'settings' => 'manage_options', |
|
138 | + ]; |
|
139 | + return glsr_get($permissions, $page, $this->constant('CAPABILITY')); |
|
140 | + } |
|
141 | 141 | |
142 | - /** |
|
143 | - * @return bool |
|
144 | - */ |
|
145 | - public function hasPermission($page = '') |
|
146 | - { |
|
147 | - $isAdmin = $this->isAdmin(); |
|
148 | - return !$isAdmin || ($isAdmin && current_user_can($this->getPermission($page))); |
|
149 | - } |
|
142 | + /** |
|
143 | + * @return bool |
|
144 | + */ |
|
145 | + public function hasPermission($page = '') |
|
146 | + { |
|
147 | + $isAdmin = $this->isAdmin(); |
|
148 | + return !$isAdmin || ($isAdmin && current_user_can($this->getPermission($page))); |
|
149 | + } |
|
150 | 150 | |
151 | - /** |
|
152 | - * @return void |
|
153 | - */ |
|
154 | - public function init() |
|
155 | - { |
|
156 | - $this->make(Actions::class)->run(); |
|
157 | - $this->make(Filters::class)->run(); |
|
158 | - } |
|
151 | + /** |
|
152 | + * @return void |
|
153 | + */ |
|
154 | + public function init() |
|
155 | + { |
|
156 | + $this->make(Actions::class)->run(); |
|
157 | + $this->make(Filters::class)->run(); |
|
158 | + } |
|
159 | 159 | |
160 | - /** |
|
161 | - * @return bool |
|
162 | - */ |
|
163 | - public function isAdmin() |
|
164 | - { |
|
165 | - return is_admin() && !wp_doing_ajax(); |
|
166 | - } |
|
160 | + /** |
|
161 | + * @return bool |
|
162 | + */ |
|
163 | + public function isAdmin() |
|
164 | + { |
|
165 | + return is_admin() && !wp_doing_ajax(); |
|
166 | + } |
|
167 | 167 | |
168 | - /** |
|
169 | - * @param string $file |
|
170 | - * @return string |
|
171 | - */ |
|
172 | - public function path($file = '', $realpath = true) |
|
173 | - { |
|
174 | - $path = plugin_dir_path($this->file); |
|
175 | - if (!$realpath) { |
|
176 | - $path = trailingslashit(WP_PLUGIN_DIR).basename(dirname($this->file)); |
|
177 | - } |
|
178 | - $path = trailingslashit($path).ltrim(trim($file), '/'); |
|
179 | - return apply_filters('site-reviews/path', $path, $file); |
|
180 | - } |
|
168 | + /** |
|
169 | + * @param string $file |
|
170 | + * @return string |
|
171 | + */ |
|
172 | + public function path($file = '', $realpath = true) |
|
173 | + { |
|
174 | + $path = plugin_dir_path($this->file); |
|
175 | + if (!$realpath) { |
|
176 | + $path = trailingslashit(WP_PLUGIN_DIR).basename(dirname($this->file)); |
|
177 | + } |
|
178 | + $path = trailingslashit($path).ltrim(trim($file), '/'); |
|
179 | + return apply_filters('site-reviews/path', $path, $file); |
|
180 | + } |
|
181 | 181 | |
182 | - /** |
|
183 | - * @return void |
|
184 | - */ |
|
185 | - public function registerAddons() |
|
186 | - { |
|
187 | - do_action('site-reviews/addon/register', $this); |
|
188 | - } |
|
182 | + /** |
|
183 | + * @return void |
|
184 | + */ |
|
185 | + public function registerAddons() |
|
186 | + { |
|
187 | + do_action('site-reviews/addon/register', $this); |
|
188 | + } |
|
189 | 189 | |
190 | - /** |
|
191 | - * @return void |
|
192 | - */ |
|
193 | - public function registerLanguages() |
|
194 | - { |
|
195 | - load_plugin_textdomain(static::ID, false, |
|
196 | - trailingslashit(plugin_basename($this->path()).'/'.$this->languages) |
|
197 | - ); |
|
198 | - } |
|
190 | + /** |
|
191 | + * @return void |
|
192 | + */ |
|
193 | + public function registerLanguages() |
|
194 | + { |
|
195 | + load_plugin_textdomain(static::ID, false, |
|
196 | + trailingslashit(plugin_basename($this->path()).'/'.$this->languages) |
|
197 | + ); |
|
198 | + } |
|
199 | 199 | |
200 | - /** |
|
201 | - * @return void |
|
202 | - */ |
|
203 | - public function registerReviewTypes() |
|
204 | - { |
|
205 | - $types = apply_filters('site-reviews/addon/types', []); |
|
206 | - $this->reviewTypes = wp_parse_args($types, [ |
|
207 | - 'local' => __('Local', 'site-reviews'), |
|
208 | - ]); |
|
209 | - } |
|
200 | + /** |
|
201 | + * @return void |
|
202 | + */ |
|
203 | + public function registerReviewTypes() |
|
204 | + { |
|
205 | + $types = apply_filters('site-reviews/addon/types', []); |
|
206 | + $this->reviewTypes = wp_parse_args($types, [ |
|
207 | + 'local' => __('Local', 'site-reviews'), |
|
208 | + ]); |
|
209 | + } |
|
210 | 210 | |
211 | - /** |
|
212 | - * @param string $view |
|
213 | - * @return void |
|
214 | - */ |
|
215 | - public function render($view, array $data = []) |
|
216 | - { |
|
217 | - $view = apply_filters('site-reviews/render/view', $view, $data); |
|
218 | - $file = apply_filters('site-reviews/views/file', $this->file($view), $view, $data); |
|
219 | - if (!file_exists($file)) { |
|
220 | - glsr_log()->error('File not found: '.$file); |
|
221 | - return; |
|
222 | - } |
|
223 | - $data = apply_filters('site-reviews/views/data', $data, $view); |
|
224 | - extract($data); |
|
225 | - include $file; |
|
226 | - } |
|
211 | + /** |
|
212 | + * @param string $view |
|
213 | + * @return void |
|
214 | + */ |
|
215 | + public function render($view, array $data = []) |
|
216 | + { |
|
217 | + $view = apply_filters('site-reviews/render/view', $view, $data); |
|
218 | + $file = apply_filters('site-reviews/views/file', $this->file($view), $view, $data); |
|
219 | + if (!file_exists($file)) { |
|
220 | + glsr_log()->error('File not found: '.$file); |
|
221 | + return; |
|
222 | + } |
|
223 | + $data = apply_filters('site-reviews/views/data', $data, $view); |
|
224 | + extract($data); |
|
225 | + include $file; |
|
226 | + } |
|
227 | 227 | |
228 | - /** |
|
229 | - * @return void |
|
230 | - */ |
|
231 | - public function scheduleCronJob() |
|
232 | - { |
|
233 | - if (wp_next_scheduled(static::CRON_EVENT)) { |
|
234 | - return; |
|
235 | - } |
|
236 | - wp_schedule_event(time(), 'twicedaily', static::CRON_EVENT); |
|
237 | - } |
|
228 | + /** |
|
229 | + * @return void |
|
230 | + */ |
|
231 | + public function scheduleCronJob() |
|
232 | + { |
|
233 | + if (wp_next_scheduled(static::CRON_EVENT)) { |
|
234 | + return; |
|
235 | + } |
|
236 | + wp_schedule_event(time(), 'twicedaily', static::CRON_EVENT); |
|
237 | + } |
|
238 | 238 | |
239 | - /** |
|
240 | - * @param string $file |
|
241 | - * @return string |
|
242 | - */ |
|
243 | - public function themePath($file = '') |
|
244 | - { |
|
245 | - return get_stylesheet_directory().'/'.static::ID.'/'.ltrim(trim($file), '/'); |
|
246 | - } |
|
239 | + /** |
|
240 | + * @param string $file |
|
241 | + * @return string |
|
242 | + */ |
|
243 | + public function themePath($file = '') |
|
244 | + { |
|
245 | + return get_stylesheet_directory().'/'.static::ID.'/'.ltrim(trim($file), '/'); |
|
246 | + } |
|
247 | 247 | |
248 | - /** |
|
249 | - * @return void |
|
250 | - */ |
|
251 | - public function unscheduleCronJob() |
|
252 | - { |
|
253 | - wp_unschedule_event(intval(wp_next_scheduled(static::CRON_EVENT)), static::CRON_EVENT); |
|
254 | - } |
|
248 | + /** |
|
249 | + * @return void |
|
250 | + */ |
|
251 | + public function unscheduleCronJob() |
|
252 | + { |
|
253 | + wp_unschedule_event(intval(wp_next_scheduled(static::CRON_EVENT)), static::CRON_EVENT); |
|
254 | + } |
|
255 | 255 | |
256 | - /** |
|
257 | - * @return void |
|
258 | - */ |
|
259 | - public function upgrade() |
|
260 | - { |
|
261 | - $this->make(Upgrader::class)->run(); |
|
262 | - } |
|
256 | + /** |
|
257 | + * @return void |
|
258 | + */ |
|
259 | + public function upgrade() |
|
260 | + { |
|
261 | + $this->make(Upgrader::class)->run(); |
|
262 | + } |
|
263 | 263 | |
264 | - /** |
|
265 | - * @param mixed $upgrader |
|
266 | - * @return void |
|
267 | - * @action upgrader_process_complete |
|
268 | - */ |
|
269 | - public function upgraded($upgrader, array $data) |
|
270 | - { |
|
271 | - if (array_key_exists('plugins', $data) |
|
272 | - && in_array(plugin_basename($this->file), $data['plugins']) |
|
273 | - && 'update' === $data['action'] |
|
274 | - && 'plugin' === $data['type'] |
|
275 | - ) { |
|
276 | - $this->upgrade(); |
|
277 | - } |
|
278 | - } |
|
264 | + /** |
|
265 | + * @param mixed $upgrader |
|
266 | + * @return void |
|
267 | + * @action upgrader_process_complete |
|
268 | + */ |
|
269 | + public function upgraded($upgrader, array $data) |
|
270 | + { |
|
271 | + if (array_key_exists('plugins', $data) |
|
272 | + && in_array(plugin_basename($this->file), $data['plugins']) |
|
273 | + && 'update' === $data['action'] |
|
274 | + && 'plugin' === $data['type'] |
|
275 | + ) { |
|
276 | + $this->upgrade(); |
|
277 | + } |
|
278 | + } |
|
279 | 279 | |
280 | - /** |
|
281 | - * @param string $path |
|
282 | - * @return string |
|
283 | - */ |
|
284 | - public function url($path = '') |
|
285 | - { |
|
286 | - $url = esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/')); |
|
287 | - return apply_filters('site-reviews/url', $url, $path); |
|
288 | - } |
|
280 | + /** |
|
281 | + * @param string $path |
|
282 | + * @return string |
|
283 | + */ |
|
284 | + public function url($path = '') |
|
285 | + { |
|
286 | + $url = esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/')); |
|
287 | + return apply_filters('site-reviews/url', $url, $path); |
|
288 | + } |
|
289 | 289 | } |
@@ -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' => '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' => '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 | } |
@@ -12,58 +12,58 @@ |
||
12 | 12 | |
13 | 13 | class RestReviewController extends RestController |
14 | 14 | { |
15 | - public function __construct() |
|
16 | - { |
|
17 | - $this->meta = new WP_REST_Post_Meta_Fields(Application::POST_TYPE); |
|
18 | - $this->namespace = Application::ID.'/v1'; |
|
19 | - $this->post_type = Application::POST_TYPE; |
|
20 | - $this->rest_base = 'reviews'; |
|
21 | - } |
|
15 | + public function __construct() |
|
16 | + { |
|
17 | + $this->meta = new WP_REST_Post_Meta_Fields(Application::POST_TYPE); |
|
18 | + $this->namespace = Application::ID.'/v1'; |
|
19 | + $this->post_type = Application::POST_TYPE; |
|
20 | + $this->rest_base = 'reviews'; |
|
21 | + } |
|
22 | 22 | |
23 | - /** |
|
24 | - * @return void |
|
25 | - */ |
|
26 | - public function register_routes() |
|
27 | - { |
|
28 | - // register_rest_route($this->namespace, '/'.$this->rest_base, [ |
|
29 | - // ['callback' => [$this, 'createReview'], 'methods' => Server::CREATABLE], |
|
30 | - // ['callback' => [$this, 'getReviews'], 'methods' => Server::READABLE], |
|
31 | - // ]); |
|
32 | - register_rest_route($this->namespace, '/types', [ |
|
33 | - ['callback' => [$this, 'getReviewTypes'], 'methods' => Server::READABLE], |
|
34 | - ]); |
|
35 | - } |
|
23 | + /** |
|
24 | + * @return void |
|
25 | + */ |
|
26 | + public function register_routes() |
|
27 | + { |
|
28 | + // register_rest_route($this->namespace, '/'.$this->rest_base, [ |
|
29 | + // ['callback' => [$this, 'createReview'], 'methods' => Server::CREATABLE], |
|
30 | + // ['callback' => [$this, 'getReviews'], 'methods' => Server::READABLE], |
|
31 | + // ]); |
|
32 | + register_rest_route($this->namespace, '/types', [ |
|
33 | + ['callback' => [$this, 'getReviewTypes'], 'methods' => Server::READABLE], |
|
34 | + ]); |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * @return WP_Error|Response|mixed |
|
39 | - */ |
|
40 | - public function createReview() |
|
41 | - { |
|
42 | - $response = []; |
|
43 | - return rest_ensure_response($response); |
|
44 | - } |
|
37 | + /** |
|
38 | + * @return WP_Error|Response|mixed |
|
39 | + */ |
|
40 | + public function createReview() |
|
41 | + { |
|
42 | + $response = []; |
|
43 | + return rest_ensure_response($response); |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * @return WP_Error|Response|mixed |
|
48 | - */ |
|
49 | - public function getReviews() |
|
50 | - { |
|
51 | - $response = []; |
|
52 | - return rest_ensure_response($response); |
|
53 | - } |
|
46 | + /** |
|
47 | + * @return WP_Error|Response|mixed |
|
48 | + */ |
|
49 | + public function getReviews() |
|
50 | + { |
|
51 | + $response = []; |
|
52 | + return rest_ensure_response($response); |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * @return WP_Error|Response|mixed |
|
57 | - */ |
|
58 | - public function getReviewTypes() |
|
59 | - { |
|
60 | - $response = []; |
|
61 | - foreach (glsr()->reviewTypes as $slug => $name) { |
|
62 | - $response[] = [ |
|
63 | - 'name' => $name, |
|
64 | - 'slug' => $slug, |
|
65 | - ]; |
|
66 | - } |
|
67 | - return rest_ensure_response($response); |
|
68 | - } |
|
55 | + /** |
|
56 | + * @return WP_Error|Response|mixed |
|
57 | + */ |
|
58 | + public function getReviewTypes() |
|
59 | + { |
|
60 | + $response = []; |
|
61 | + foreach (glsr()->reviewTypes as $slug => $name) { |
|
62 | + $response[] = [ |
|
63 | + 'name' => $name, |
|
64 | + 'slug' => $slug, |
|
65 | + ]; |
|
66 | + } |
|
67 | + return rest_ensure_response($response); |
|
68 | + } |
|
69 | 69 | } |
@@ -5,23 +5,23 @@ |
||
5 | 5 | require_once ABSPATH.WPINC.'/class-phpass.php'; |
6 | 6 | |
7 | 7 | spl_autoload_register(function ($className) { |
8 | - $namespaces = [ |
|
9 | - 'GeminiLabs\\SiteReviews\\' => __DIR__.'/plugin/', |
|
10 | - 'GeminiLabs\\SiteReviews\\Tests\\' => __DIR__.'/tests/', |
|
11 | - 'GeminiLabs\\Sepia\\PoParser\\' => __DIR__.'/vendors/sepia/po-parser/', |
|
12 | - 'GeminiLabs\\Sinergi\\BrowserDetector\\' => __DIR__.'/vendors/sinergi/browser-detector/', |
|
13 | - 'GeminiLabs\\Vectorface\\Whip\\' => __DIR__.'/vendors/vectorface/whip/', |
|
14 | - ]; |
|
15 | - foreach ($namespaces as $prefix => $baseDir) { |
|
16 | - $len = strlen($prefix); |
|
17 | - if (0 !== strncmp($prefix, $className, $len)) { |
|
18 | - continue; |
|
19 | - } |
|
20 | - $file = $baseDir.str_replace('\\', '/', substr($className, $len)).'.php'; |
|
21 | - if (!file_exists($file)) { |
|
22 | - continue; |
|
23 | - } |
|
24 | - require $file; |
|
25 | - break; |
|
26 | - } |
|
8 | + $namespaces = [ |
|
9 | + 'GeminiLabs\\SiteReviews\\' => __DIR__.'/plugin/', |
|
10 | + 'GeminiLabs\\SiteReviews\\Tests\\' => __DIR__.'/tests/', |
|
11 | + 'GeminiLabs\\Sepia\\PoParser\\' => __DIR__.'/vendors/sepia/po-parser/', |
|
12 | + 'GeminiLabs\\Sinergi\\BrowserDetector\\' => __DIR__.'/vendors/sinergi/browser-detector/', |
|
13 | + 'GeminiLabs\\Vectorface\\Whip\\' => __DIR__.'/vendors/vectorface/whip/', |
|
14 | + ]; |
|
15 | + foreach ($namespaces as $prefix => $baseDir) { |
|
16 | + $len = strlen($prefix); |
|
17 | + if (0 !== strncmp($prefix, $className, $len)) { |
|
18 | + continue; |
|
19 | + } |
|
20 | + $file = $baseDir.str_replace('\\', '/', substr($className, $len)).'.php'; |
|
21 | + if (!file_exists($file)) { |
|
22 | + continue; |
|
23 | + } |
|
24 | + require $file; |
|
25 | + break; |
|
26 | + } |
|
27 | 27 | }); |
@@ -8,10 +8,10 @@ discard block |
||
8 | 8 | * @see https://www.elegantthemes.com/gallery/divi/ |
9 | 9 | */ |
10 | 10 | add_action('site-reviews/customize/divi', function ($instance) { |
11 | - if ('label' != $instance->tag || 'checkbox' != $instance->args['type']) { |
|
12 | - return; |
|
13 | - } |
|
14 | - $instance->args['text'] = '<i></i>'.$instance->args['text']; |
|
11 | + if ('label' != $instance->tag || 'checkbox' != $instance->args['type']) { |
|
12 | + return; |
|
13 | + } |
|
14 | + $instance->args['text'] = '<i></i>'.$instance->args['text']; |
|
15 | 15 | }); |
16 | 16 | |
17 | 17 | /* |
@@ -22,14 +22,14 @@ discard block |
||
22 | 22 | * @see https://wordpress.org/plugins/wp-super-cache/ |
23 | 23 | */ |
24 | 24 | add_action('site-reviews/review/created', function ($review, $request) { |
25 | - if (!function_exists('wp_cache_post_change')) { |
|
26 | - return; |
|
27 | - } |
|
28 | - wp_cache_post_change($request->post_id); |
|
29 | - if (empty($review->assigned_to) || $review->assigned_to == $request->post_id) { |
|
30 | - return; |
|
31 | - } |
|
32 | - wp_cache_post_change($review->assigned_to); |
|
25 | + if (!function_exists('wp_cache_post_change')) { |
|
26 | + return; |
|
27 | + } |
|
28 | + wp_cache_post_change($request->post_id); |
|
29 | + if (empty($review->assigned_to) || $review->assigned_to == $request->post_id) { |
|
30 | + return; |
|
31 | + } |
|
32 | + wp_cache_post_change($review->assigned_to); |
|
33 | 33 | }, 10, 2); |
34 | 34 | |
35 | 35 | /* |
@@ -38,8 +38,8 @@ discard block |
||
38 | 38 | * @see https://wordpress.org/plugins/speed-booster-pack/ |
39 | 39 | */ |
40 | 40 | add_filter('sbp_exclude_defer_scripts', function ($scriptHandles) { |
41 | - $scriptHandles[] = 'site-reviews/google-recaptcha'; |
|
42 | - return array_keys(array_flip($scriptHandles)); |
|
41 | + $scriptHandles[] = 'site-reviews/google-recaptcha'; |
|
42 | + return array_keys(array_flip($scriptHandles)); |
|
43 | 43 | }); |
44 | 44 | |
45 | 45 | /* |
@@ -49,13 +49,13 @@ discard block |
||
49 | 49 | * @see https://searchandfilter.com/ |
50 | 50 | */ |
51 | 51 | add_filter('sf_edit_query_args', function ($query) { |
52 | - if (!empty($query['meta_key']) && '_glsr_ranking' == $query['meta_key']) { |
|
53 | - unset($query['meta_key']); |
|
54 | - $query['meta_query'] = [ |
|
55 | - 'relation' => 'OR', |
|
56 | - ['key' => '_glsr_ranking', 'compare' => 'NOT EXISTS'], // this comes first! |
|
57 | - ['key' => '_glsr_ranking', 'compare' => 'EXISTS'], |
|
58 | - ]; |
|
59 | - } |
|
60 | - return $query; |
|
52 | + if (!empty($query['meta_key']) && '_glsr_ranking' == $query['meta_key']) { |
|
53 | + unset($query['meta_key']); |
|
54 | + $query['meta_query'] = [ |
|
55 | + 'relation' => 'OR', |
|
56 | + ['key' => '_glsr_ranking', 'compare' => 'NOT EXISTS'], // this comes first! |
|
57 | + ['key' => '_glsr_ranking', 'compare' => 'EXISTS'], |
|
58 | + ]; |
|
59 | + } |
|
60 | + return $query; |
|
61 | 61 | }, 20); |
@@ -12,154 +12,154 @@ |
||
12 | 12 | |
13 | 13 | class AjaxController extends Controller |
14 | 14 | { |
15 | - /** |
|
16 | - * @return void |
|
17 | - */ |
|
18 | - public function routerChangeStatus(array $request) |
|
19 | - { |
|
20 | - wp_send_json_success($this->execute(new ChangeStatus($request))); |
|
21 | - } |
|
15 | + /** |
|
16 | + * @return void |
|
17 | + */ |
|
18 | + public function routerChangeStatus(array $request) |
|
19 | + { |
|
20 | + wp_send_json_success($this->execute(new ChangeStatus($request))); |
|
21 | + } |
|
22 | 22 | |
23 | - /** |
|
24 | - * @return void |
|
25 | - */ |
|
26 | - public function routerClearConsole() |
|
27 | - { |
|
28 | - glsr(AdminController::class)->routerClearConsole(); |
|
29 | - wp_send_json_success([ |
|
30 | - 'console' => glsr(Console::class)->get(), |
|
31 | - 'notices' => glsr(Notice::class)->get(), |
|
32 | - ]); |
|
33 | - } |
|
23 | + /** |
|
24 | + * @return void |
|
25 | + */ |
|
26 | + public function routerClearConsole() |
|
27 | + { |
|
28 | + glsr(AdminController::class)->routerClearConsole(); |
|
29 | + wp_send_json_success([ |
|
30 | + 'console' => glsr(Console::class)->get(), |
|
31 | + 'notices' => glsr(Notice::class)->get(), |
|
32 | + ]); |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * @return void |
|
37 | - */ |
|
38 | - public function routerCountReviews() |
|
39 | - { |
|
40 | - glsr(AdminController::class)->routerCountReviews(); |
|
41 | - wp_send_json_success([ |
|
42 | - 'notices' => glsr(Notice::class)->get(), |
|
43 | - ]); |
|
44 | - } |
|
35 | + /** |
|
36 | + * @return void |
|
37 | + */ |
|
38 | + public function routerCountReviews() |
|
39 | + { |
|
40 | + glsr(AdminController::class)->routerCountReviews(); |
|
41 | + wp_send_json_success([ |
|
42 | + 'notices' => glsr(Notice::class)->get(), |
|
43 | + ]); |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * @return void |
|
48 | - */ |
|
49 | - public function routerMceShortcode(array $request) |
|
50 | - { |
|
51 | - $shortcode = $request['shortcode']; |
|
52 | - $response = false; |
|
53 | - if (array_key_exists($shortcode, glsr()->mceShortcodes)) { |
|
54 | - $data = glsr()->mceShortcodes[$shortcode]; |
|
55 | - if (!empty($data['errors'])) { |
|
56 | - $data['btn_okay'] = [esc_html__('Okay', 'site-reviews')]; |
|
57 | - } |
|
58 | - $response = [ |
|
59 | - 'body' => $data['fields'], |
|
60 | - 'close' => $data['btn_close'], |
|
61 | - 'ok' => $data['btn_okay'], |
|
62 | - 'shortcode' => $shortcode, |
|
63 | - 'title' => $data['title'], |
|
64 | - ]; |
|
65 | - } |
|
66 | - wp_send_json_success($response); |
|
67 | - } |
|
46 | + /** |
|
47 | + * @return void |
|
48 | + */ |
|
49 | + public function routerMceShortcode(array $request) |
|
50 | + { |
|
51 | + $shortcode = $request['shortcode']; |
|
52 | + $response = false; |
|
53 | + if (array_key_exists($shortcode, glsr()->mceShortcodes)) { |
|
54 | + $data = glsr()->mceShortcodes[$shortcode]; |
|
55 | + if (!empty($data['errors'])) { |
|
56 | + $data['btn_okay'] = [esc_html__('Okay', 'site-reviews')]; |
|
57 | + } |
|
58 | + $response = [ |
|
59 | + 'body' => $data['fields'], |
|
60 | + 'close' => $data['btn_close'], |
|
61 | + 'ok' => $data['btn_okay'], |
|
62 | + 'shortcode' => $shortcode, |
|
63 | + 'title' => $data['title'], |
|
64 | + ]; |
|
65 | + } |
|
66 | + wp_send_json_success($response); |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * @return void |
|
71 | - */ |
|
72 | - public function routerFetchConsole() |
|
73 | - { |
|
74 | - glsr(AdminController::class)->routerFetchConsole(); |
|
75 | - wp_send_json_success([ |
|
76 | - 'console' => glsr(Console::class)->get(), |
|
77 | - 'notices' => glsr(Notice::class)->get(), |
|
78 | - ]); |
|
79 | - } |
|
69 | + /** |
|
70 | + * @return void |
|
71 | + */ |
|
72 | + public function routerFetchConsole() |
|
73 | + { |
|
74 | + glsr(AdminController::class)->routerFetchConsole(); |
|
75 | + wp_send_json_success([ |
|
76 | + 'console' => glsr(Console::class)->get(), |
|
77 | + 'notices' => glsr(Notice::class)->get(), |
|
78 | + ]); |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * @return void |
|
83 | - */ |
|
84 | - public function routerSearchPosts(array $request) |
|
85 | - { |
|
86 | - $results = glsr(Database::class)->searchPosts($request['search']); |
|
87 | - wp_send_json_success([ |
|
88 | - 'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>', |
|
89 | - 'items' => $results, |
|
90 | - ]); |
|
91 | - } |
|
81 | + /** |
|
82 | + * @return void |
|
83 | + */ |
|
84 | + public function routerSearchPosts(array $request) |
|
85 | + { |
|
86 | + $results = glsr(Database::class)->searchPosts($request['search']); |
|
87 | + wp_send_json_success([ |
|
88 | + 'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>', |
|
89 | + 'items' => $results, |
|
90 | + ]); |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * @return void |
|
95 | - */ |
|
96 | - public function routerSearchTranslations(array $request) |
|
97 | - { |
|
98 | - if (empty($request['exclude'])) { |
|
99 | - $request['exclude'] = []; |
|
100 | - } |
|
101 | - $results = glsr(Translation::class) |
|
102 | - ->search($request['search']) |
|
103 | - ->exclude() |
|
104 | - ->exclude($request['exclude']) |
|
105 | - ->renderResults(); |
|
106 | - wp_send_json_success([ |
|
107 | - 'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>', |
|
108 | - 'items' => $results, |
|
109 | - ]); |
|
110 | - } |
|
93 | + /** |
|
94 | + * @return void |
|
95 | + */ |
|
96 | + public function routerSearchTranslations(array $request) |
|
97 | + { |
|
98 | + if (empty($request['exclude'])) { |
|
99 | + $request['exclude'] = []; |
|
100 | + } |
|
101 | + $results = glsr(Translation::class) |
|
102 | + ->search($request['search']) |
|
103 | + ->exclude() |
|
104 | + ->exclude($request['exclude']) |
|
105 | + ->renderResults(); |
|
106 | + wp_send_json_success([ |
|
107 | + 'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>', |
|
108 | + 'items' => $results, |
|
109 | + ]); |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * @return void |
|
114 | - */ |
|
115 | - public function routerSubmitReview(array $request) |
|
116 | - { |
|
117 | - $command = glsr(PublicController::class)->routerSubmitReview($request); |
|
118 | - $redirect = trim(strval(get_post_meta($command->post_id, 'redirect_to', true))); |
|
119 | - $redirect = apply_filters('site-reviews/review/redirect', $redirect, $command); |
|
120 | - $data = [ |
|
121 | - 'errors' => glsr()->sessionGet($command->form_id.'errors', false), |
|
122 | - 'message' => glsr()->sessionGet($command->form_id.'message', ''), |
|
123 | - 'recaptcha' => glsr()->sessionGet($command->form_id.'recaptcha', false), |
|
124 | - 'redirect' => $redirect, |
|
125 | - ]; |
|
126 | - if (false === $data['errors']) { |
|
127 | - glsr()->sessionClear(); |
|
128 | - wp_send_json_success($data); |
|
129 | - } |
|
130 | - wp_send_json_error($data); |
|
131 | - } |
|
112 | + /** |
|
113 | + * @return void |
|
114 | + */ |
|
115 | + public function routerSubmitReview(array $request) |
|
116 | + { |
|
117 | + $command = glsr(PublicController::class)->routerSubmitReview($request); |
|
118 | + $redirect = trim(strval(get_post_meta($command->post_id, 'redirect_to', true))); |
|
119 | + $redirect = apply_filters('site-reviews/review/redirect', $redirect, $command); |
|
120 | + $data = [ |
|
121 | + 'errors' => glsr()->sessionGet($command->form_id.'errors', false), |
|
122 | + 'message' => glsr()->sessionGet($command->form_id.'message', ''), |
|
123 | + 'recaptcha' => glsr()->sessionGet($command->form_id.'recaptcha', false), |
|
124 | + 'redirect' => $redirect, |
|
125 | + ]; |
|
126 | + if (false === $data['errors']) { |
|
127 | + glsr()->sessionClear(); |
|
128 | + wp_send_json_success($data); |
|
129 | + } |
|
130 | + wp_send_json_error($data); |
|
131 | + } |
|
132 | 132 | |
133 | - /** |
|
134 | - * @return void |
|
135 | - */ |
|
136 | - public function routerFetchPagedReviews(array $request) |
|
137 | - { |
|
138 | - $urlQuery = []; |
|
139 | - parse_str(parse_url(glsr_get($request, 'url'), PHP_URL_QUERY), $urlQuery); |
|
140 | - $args = [ |
|
141 | - 'paged' => glsr_get($urlQuery, glsr()->constant('PAGED_QUERY_VAR'), 1), |
|
142 | - 'pagedUrl' => home_url(parse_url(glsr_get($request, 'url'), PHP_URL_PATH)), |
|
143 | - 'pagination' => 'ajax', |
|
144 | - 'schema' => false, |
|
145 | - ]; |
|
146 | - $atts = (array) json_decode(glsr_get($request, 'atts')); |
|
147 | - $html = glsr(SiteReviews::class)->build(wp_parse_args($args, $atts)); |
|
148 | - return wp_send_json_success([ |
|
149 | - 'pagination' => $html->getPagination(), |
|
150 | - 'reviews' => $html->getReviews(), |
|
151 | - ]); |
|
152 | - } |
|
133 | + /** |
|
134 | + * @return void |
|
135 | + */ |
|
136 | + public function routerFetchPagedReviews(array $request) |
|
137 | + { |
|
138 | + $urlQuery = []; |
|
139 | + parse_str(parse_url(glsr_get($request, 'url'), PHP_URL_QUERY), $urlQuery); |
|
140 | + $args = [ |
|
141 | + 'paged' => glsr_get($urlQuery, glsr()->constant('PAGED_QUERY_VAR'), 1), |
|
142 | + 'pagedUrl' => home_url(parse_url(glsr_get($request, 'url'), PHP_URL_PATH)), |
|
143 | + 'pagination' => 'ajax', |
|
144 | + 'schema' => false, |
|
145 | + ]; |
|
146 | + $atts = (array) json_decode(glsr_get($request, 'atts')); |
|
147 | + $html = glsr(SiteReviews::class)->build(wp_parse_args($args, $atts)); |
|
148 | + return wp_send_json_success([ |
|
149 | + 'pagination' => $html->getPagination(), |
|
150 | + 'reviews' => $html->getReviews(), |
|
151 | + ]); |
|
152 | + } |
|
153 | 153 | |
154 | - /** |
|
155 | - * @return void |
|
156 | - */ |
|
157 | - public function routerTogglePinned(array $request) |
|
158 | - { |
|
159 | - $isPinned = $this->execute(new TogglePinned($request)); |
|
160 | - wp_send_json_success([ |
|
161 | - 'notices' => glsr(Notice::class)->get(), |
|
162 | - 'pinned' => $isPinned, |
|
163 | - ]); |
|
164 | - } |
|
154 | + /** |
|
155 | + * @return void |
|
156 | + */ |
|
157 | + public function routerTogglePinned(array $request) |
|
158 | + { |
|
159 | + $isPinned = $this->execute(new TogglePinned($request)); |
|
160 | + wp_send_json_success([ |
|
161 | + 'notices' => glsr(Notice::class)->get(), |
|
162 | + 'pinned' => $isPinned, |
|
163 | + ]); |
|
164 | + } |
|
165 | 165 | } |
@@ -7,76 +7,76 @@ |
||
7 | 7 | |
8 | 8 | class Upgrader |
9 | 9 | { |
10 | - /** |
|
11 | - * @return string |
|
12 | - */ |
|
13 | - public $currentVersion; |
|
10 | + /** |
|
11 | + * @return string |
|
12 | + */ |
|
13 | + public $currentVersion; |
|
14 | 14 | |
15 | - /** |
|
16 | - * @return void |
|
17 | - */ |
|
18 | - public function run() |
|
19 | - { |
|
20 | - $filenames = []; |
|
21 | - $iterator = new DirectoryIterator(dirname(__FILE__).'/Upgrader'); |
|
22 | - foreach ($iterator as $fileinfo) { |
|
23 | - if (!$fileinfo->isFile()) { |
|
24 | - continue; |
|
25 | - } |
|
26 | - $filenames[] = $fileinfo->getFilename(); |
|
27 | - } |
|
28 | - natsort($filenames); |
|
29 | - $this->currentVersion = $this->currentVersion(); |
|
30 | - array_walk($filenames, function ($file) { |
|
31 | - $className = str_replace('.php', '', $file); |
|
32 | - $version = str_replace(['Upgrade_', '_'], ['', '.'], $className); |
|
33 | - $versionSuffix = preg_replace('/[\d.]+(.+)?/', '${1}', glsr()->version); // allow alpha/beta versions |
|
34 | - if ($this->currentVersion == '0.0.0' |
|
35 | - || version_compare($this->currentVersion, $version.$versionSuffix, '>=')) { |
|
36 | - return; |
|
37 | - } |
|
38 | - glsr('Modules\\Upgrader\\'.$className); |
|
39 | - glsr_log()->notice('Completed Upgrade for v'.$version.$versionSuffix); |
|
40 | - }); |
|
41 | - $this->finish(); |
|
42 | - } |
|
15 | + /** |
|
16 | + * @return void |
|
17 | + */ |
|
18 | + public function run() |
|
19 | + { |
|
20 | + $filenames = []; |
|
21 | + $iterator = new DirectoryIterator(dirname(__FILE__).'/Upgrader'); |
|
22 | + foreach ($iterator as $fileinfo) { |
|
23 | + if (!$fileinfo->isFile()) { |
|
24 | + continue; |
|
25 | + } |
|
26 | + $filenames[] = $fileinfo->getFilename(); |
|
27 | + } |
|
28 | + natsort($filenames); |
|
29 | + $this->currentVersion = $this->currentVersion(); |
|
30 | + array_walk($filenames, function ($file) { |
|
31 | + $className = str_replace('.php', '', $file); |
|
32 | + $version = str_replace(['Upgrade_', '_'], ['', '.'], $className); |
|
33 | + $versionSuffix = preg_replace('/[\d.]+(.+)?/', '${1}', glsr()->version); // allow alpha/beta versions |
|
34 | + if ($this->currentVersion == '0.0.0' |
|
35 | + || version_compare($this->currentVersion, $version.$versionSuffix, '>=')) { |
|
36 | + return; |
|
37 | + } |
|
38 | + glsr('Modules\\Upgrader\\'.$className); |
|
39 | + glsr_log()->notice('Completed Upgrade for v'.$version.$versionSuffix); |
|
40 | + }); |
|
41 | + $this->finish(); |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * @return void |
|
46 | - */ |
|
47 | - public function finish() |
|
48 | - { |
|
49 | - if ($this->currentVersion !== glsr()->version) { |
|
50 | - $this->setReviewCounts(); |
|
51 | - $this->updateVersionFrom($this->currentVersion); |
|
52 | - } elseif (!glsr(OptionManager::class)->get('last_review_count', false)) { |
|
53 | - $this->setReviewCounts(); |
|
54 | - } |
|
55 | - } |
|
44 | + /** |
|
45 | + * @return void |
|
46 | + */ |
|
47 | + public function finish() |
|
48 | + { |
|
49 | + if ($this->currentVersion !== glsr()->version) { |
|
50 | + $this->setReviewCounts(); |
|
51 | + $this->updateVersionFrom($this->currentVersion); |
|
52 | + } elseif (!glsr(OptionManager::class)->get('last_review_count', false)) { |
|
53 | + $this->setReviewCounts(); |
|
54 | + } |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * @return string |
|
59 | - */ |
|
60 | - protected function currentVersion() |
|
61 | - { |
|
62 | - return glsr(OptionManager::class)->get('version', '0.0.0'); |
|
63 | - } |
|
57 | + /** |
|
58 | + * @return string |
|
59 | + */ |
|
60 | + protected function currentVersion() |
|
61 | + { |
|
62 | + return glsr(OptionManager::class)->get('version', '0.0.0'); |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * @return void |
|
67 | - */ |
|
68 | - protected function setReviewCounts() |
|
69 | - { |
|
70 | - add_action('admin_init', 'glsr_calculate_ratings'); |
|
71 | - } |
|
65 | + /** |
|
66 | + * @return void |
|
67 | + */ |
|
68 | + protected function setReviewCounts() |
|
69 | + { |
|
70 | + add_action('admin_init', 'glsr_calculate_ratings'); |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * @param string $previousVersion |
|
75 | - * @return void |
|
76 | - */ |
|
77 | - protected function updateVersionFrom($previousVersion) |
|
78 | - { |
|
79 | - glsr(OptionManager::class)->set('version', glsr()->version); |
|
80 | - glsr(OptionManager::class)->set('version_upgraded_from', $previousVersion); |
|
81 | - } |
|
73 | + /** |
|
74 | + * @param string $previousVersion |
|
75 | + * @return void |
|
76 | + */ |
|
77 | + protected function updateVersionFrom($previousVersion) |
|
78 | + { |
|
79 | + glsr(OptionManager::class)->set('version', glsr()->version); |
|
80 | + glsr(OptionManager::class)->set('version_upgraded_from', $previousVersion); |
|
81 | + } |
|
82 | 82 | } |