@@ -12,370 +12,370 @@ |
||
12 | 12 | |
13 | 13 | class System |
14 | 14 | { |
15 | - const PAD = 40; |
|
15 | + const PAD = 40; |
|
16 | 16 | |
17 | - /** |
|
18 | - * @return string |
|
19 | - */ |
|
20 | - public function __toString() |
|
21 | - { |
|
22 | - return $this->get(); |
|
23 | - } |
|
17 | + /** |
|
18 | + * @return string |
|
19 | + */ |
|
20 | + public function __toString() |
|
21 | + { |
|
22 | + return $this->get(); |
|
23 | + } |
|
24 | 24 | |
25 | - /** |
|
26 | - * @return string |
|
27 | - */ |
|
28 | - public function get() |
|
29 | - { |
|
30 | - $details = [ |
|
31 | - 'plugin' => 'Plugin Details', |
|
32 | - 'addon' => 'Addon Details', |
|
33 | - 'browser' => 'Browser Details', |
|
34 | - 'server' => 'Server Details', |
|
35 | - 'php' => 'PHP Configuration', |
|
36 | - 'wordpress' => 'WordPress Configuration', |
|
37 | - 'mu-plugin' => 'Must-Use Plugins', |
|
38 | - 'multisite-plugin' => 'Network Active Plugins', |
|
39 | - 'active-plugin' => 'Active Plugins', |
|
40 | - 'inactive-plugin' => 'Inactive Plugins', |
|
41 | - 'setting' => 'Plugin Settings', |
|
42 | - 'reviews' => 'Review Counts', |
|
43 | - ]; |
|
44 | - $systemInfo = array_reduce(array_keys($details), function ($carry, $key) use ($details) { |
|
45 | - $methodName = Helper::buildMethodName('get-'.$key.'-details'); |
|
46 | - if (method_exists($this, $methodName) && $systemDetails = $this->$methodName()) { |
|
47 | - return $carry.$this->implode( |
|
48 | - strtoupper($details[$key]), |
|
49 | - apply_filters('site-reviews/system/'.$key, $systemDetails) |
|
50 | - ); |
|
51 | - } |
|
52 | - return $carry; |
|
53 | - }); |
|
54 | - return trim($systemInfo); |
|
55 | - } |
|
25 | + /** |
|
26 | + * @return string |
|
27 | + */ |
|
28 | + public function get() |
|
29 | + { |
|
30 | + $details = [ |
|
31 | + 'plugin' => 'Plugin Details', |
|
32 | + 'addon' => 'Addon Details', |
|
33 | + 'browser' => 'Browser Details', |
|
34 | + 'server' => 'Server Details', |
|
35 | + 'php' => 'PHP Configuration', |
|
36 | + 'wordpress' => 'WordPress Configuration', |
|
37 | + 'mu-plugin' => 'Must-Use Plugins', |
|
38 | + 'multisite-plugin' => 'Network Active Plugins', |
|
39 | + 'active-plugin' => 'Active Plugins', |
|
40 | + 'inactive-plugin' => 'Inactive Plugins', |
|
41 | + 'setting' => 'Plugin Settings', |
|
42 | + 'reviews' => 'Review Counts', |
|
43 | + ]; |
|
44 | + $systemInfo = array_reduce(array_keys($details), function ($carry, $key) use ($details) { |
|
45 | + $methodName = Helper::buildMethodName('get-'.$key.'-details'); |
|
46 | + if (method_exists($this, $methodName) && $systemDetails = $this->$methodName()) { |
|
47 | + return $carry.$this->implode( |
|
48 | + strtoupper($details[$key]), |
|
49 | + apply_filters('site-reviews/system/'.$key, $systemDetails) |
|
50 | + ); |
|
51 | + } |
|
52 | + return $carry; |
|
53 | + }); |
|
54 | + return trim($systemInfo); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * @return array |
|
59 | - */ |
|
60 | - public function getActivePluginDetails() |
|
61 | - { |
|
62 | - $plugins = get_plugins(); |
|
63 | - $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array'); |
|
64 | - $inactive = array_diff_key($plugins, array_flip($activePlugins)); |
|
65 | - return $this->normalizePluginList(array_diff_key($plugins, $inactive)); |
|
66 | - } |
|
57 | + /** |
|
58 | + * @return array |
|
59 | + */ |
|
60 | + public function getActivePluginDetails() |
|
61 | + { |
|
62 | + $plugins = get_plugins(); |
|
63 | + $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array'); |
|
64 | + $inactive = array_diff_key($plugins, array_flip($activePlugins)); |
|
65 | + return $this->normalizePluginList(array_diff_key($plugins, $inactive)); |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @return array |
|
70 | - */ |
|
71 | - public function getAddonDetails() |
|
72 | - { |
|
73 | - $details = apply_filters('site-reviews/addon/system-info', []); |
|
74 | - ksort($details); |
|
75 | - return $details; |
|
76 | - } |
|
68 | + /** |
|
69 | + * @return array |
|
70 | + */ |
|
71 | + public function getAddonDetails() |
|
72 | + { |
|
73 | + $details = apply_filters('site-reviews/addon/system-info', []); |
|
74 | + ksort($details); |
|
75 | + return $details; |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @return array |
|
80 | - */ |
|
81 | - public function getBrowserDetails() |
|
82 | - { |
|
83 | - $browser = new Browser(); |
|
84 | - $name = esc_attr($browser->getName()); |
|
85 | - $userAgent = esc_attr($browser->getUserAgent()->getUserAgentString()); |
|
86 | - $version = esc_attr($browser->getVersion()); |
|
87 | - return [ |
|
88 | - 'Browser Name' => sprintf('%s %s', $name, $version), |
|
89 | - 'Browser UA' => $userAgent, |
|
90 | - ]; |
|
91 | - } |
|
78 | + /** |
|
79 | + * @return array |
|
80 | + */ |
|
81 | + public function getBrowserDetails() |
|
82 | + { |
|
83 | + $browser = new Browser(); |
|
84 | + $name = esc_attr($browser->getName()); |
|
85 | + $userAgent = esc_attr($browser->getUserAgent()->getUserAgentString()); |
|
86 | + $version = esc_attr($browser->getVersion()); |
|
87 | + return [ |
|
88 | + 'Browser Name' => sprintf('%s %s', $name, $version), |
|
89 | + 'Browser UA' => $userAgent, |
|
90 | + ]; |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * @return array |
|
95 | - */ |
|
96 | - public function getInactivePluginDetails() |
|
97 | - { |
|
98 | - $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array'); |
|
99 | - $inactivePlugins = $this->normalizePluginList(array_diff_key(get_plugins(), array_flip($activePlugins))); |
|
100 | - $multisitePlugins = $this->getMultisitePluginDetails(); |
|
101 | - return empty($multisitePlugins) |
|
102 | - ? $inactivePlugins |
|
103 | - : array_diff($inactivePlugins, $multisitePlugins); |
|
104 | - } |
|
93 | + /** |
|
94 | + * @return array |
|
95 | + */ |
|
96 | + public function getInactivePluginDetails() |
|
97 | + { |
|
98 | + $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array'); |
|
99 | + $inactivePlugins = $this->normalizePluginList(array_diff_key(get_plugins(), array_flip($activePlugins))); |
|
100 | + $multisitePlugins = $this->getMultisitePluginDetails(); |
|
101 | + return empty($multisitePlugins) |
|
102 | + ? $inactivePlugins |
|
103 | + : array_diff($inactivePlugins, $multisitePlugins); |
|
104 | + } |
|
105 | 105 | |
106 | - /** |
|
107 | - * @return array |
|
108 | - */ |
|
109 | - public function getMuPluginDetails() |
|
110 | - { |
|
111 | - if (empty($plugins = get_mu_plugins())) { |
|
112 | - return []; |
|
113 | - } |
|
114 | - return $this->normalizePluginList($plugins); |
|
115 | - } |
|
106 | + /** |
|
107 | + * @return array |
|
108 | + */ |
|
109 | + public function getMuPluginDetails() |
|
110 | + { |
|
111 | + if (empty($plugins = get_mu_plugins())) { |
|
112 | + return []; |
|
113 | + } |
|
114 | + return $this->normalizePluginList($plugins); |
|
115 | + } |
|
116 | 116 | |
117 | - /** |
|
118 | - * @return array |
|
119 | - */ |
|
120 | - public function getMultisitePluginDetails() |
|
121 | - { |
|
122 | - $activePlugins = (array) get_site_option('active_sitewide_plugins', []); |
|
123 | - if (!is_multisite() || empty($activePlugins)) { |
|
124 | - return []; |
|
125 | - } |
|
126 | - return $this->normalizePluginList(array_intersect_key(get_plugins(), $activePlugins)); |
|
127 | - } |
|
117 | + /** |
|
118 | + * @return array |
|
119 | + */ |
|
120 | + public function getMultisitePluginDetails() |
|
121 | + { |
|
122 | + $activePlugins = (array) get_site_option('active_sitewide_plugins', []); |
|
123 | + if (!is_multisite() || empty($activePlugins)) { |
|
124 | + return []; |
|
125 | + } |
|
126 | + return $this->normalizePluginList(array_intersect_key(get_plugins(), $activePlugins)); |
|
127 | + } |
|
128 | 128 | |
129 | - /** |
|
130 | - * @return array |
|
131 | - */ |
|
132 | - public function getPhpDetails() |
|
133 | - { |
|
134 | - $displayErrors = ini_get('display_errors') |
|
135 | - ? 'On ('.ini_get('display_errors').')' |
|
136 | - : 'N/A'; |
|
137 | - $intlSupport = extension_loaded('intl') |
|
138 | - ? phpversion('intl') |
|
139 | - : 'false'; |
|
140 | - return [ |
|
141 | - 'cURL' => var_export(function_exists('curl_init'), true), |
|
142 | - 'Default Charset' => ini_get('default_charset'), |
|
143 | - 'Display Errors' => $displayErrors, |
|
144 | - 'fsockopen' => var_export(function_exists('fsockopen'), true), |
|
145 | - 'Intl' => $intlSupport, |
|
146 | - 'IPv6' => var_export(defined('AF_INET6'), true), |
|
147 | - 'Max Execution Time' => ini_get('max_execution_time'), |
|
148 | - 'Max Input Nesting Level' => ini_get('max_input_nesting_level'), |
|
149 | - 'Max Input Vars' => ini_get('max_input_vars'), |
|
150 | - 'Memory Limit' => ini_get('memory_limit'), |
|
151 | - 'Post Max Size' => ini_get('post_max_size'), |
|
152 | - 'Sendmail Path' => ini_get('sendmail_path'), |
|
153 | - 'Session Cookie Path' => esc_html(ini_get('session.cookie_path')), |
|
154 | - 'Session Name' => esc_html(ini_get('session.name')), |
|
155 | - 'Session Save Path' => esc_html(ini_get('session.save_path')), |
|
156 | - 'Session Use Cookies' => var_export(wp_validate_boolean(ini_get('session.use_cookies')), true), |
|
157 | - 'Session Use Only Cookies' => var_export(wp_validate_boolean(ini_get('session.use_only_cookies')), true), |
|
158 | - 'Upload Max Filesize' => ini_get('upload_max_filesize'), |
|
159 | - ]; |
|
160 | - } |
|
129 | + /** |
|
130 | + * @return array |
|
131 | + */ |
|
132 | + public function getPhpDetails() |
|
133 | + { |
|
134 | + $displayErrors = ini_get('display_errors') |
|
135 | + ? 'On ('.ini_get('display_errors').')' |
|
136 | + : 'N/A'; |
|
137 | + $intlSupport = extension_loaded('intl') |
|
138 | + ? phpversion('intl') |
|
139 | + : 'false'; |
|
140 | + return [ |
|
141 | + 'cURL' => var_export(function_exists('curl_init'), true), |
|
142 | + 'Default Charset' => ini_get('default_charset'), |
|
143 | + 'Display Errors' => $displayErrors, |
|
144 | + 'fsockopen' => var_export(function_exists('fsockopen'), true), |
|
145 | + 'Intl' => $intlSupport, |
|
146 | + 'IPv6' => var_export(defined('AF_INET6'), true), |
|
147 | + 'Max Execution Time' => ini_get('max_execution_time'), |
|
148 | + 'Max Input Nesting Level' => ini_get('max_input_nesting_level'), |
|
149 | + 'Max Input Vars' => ini_get('max_input_vars'), |
|
150 | + 'Memory Limit' => ini_get('memory_limit'), |
|
151 | + 'Post Max Size' => ini_get('post_max_size'), |
|
152 | + 'Sendmail Path' => ini_get('sendmail_path'), |
|
153 | + 'Session Cookie Path' => esc_html(ini_get('session.cookie_path')), |
|
154 | + 'Session Name' => esc_html(ini_get('session.name')), |
|
155 | + 'Session Save Path' => esc_html(ini_get('session.save_path')), |
|
156 | + 'Session Use Cookies' => var_export(wp_validate_boolean(ini_get('session.use_cookies')), true), |
|
157 | + 'Session Use Only Cookies' => var_export(wp_validate_boolean(ini_get('session.use_only_cookies')), true), |
|
158 | + 'Upload Max Filesize' => ini_get('upload_max_filesize'), |
|
159 | + ]; |
|
160 | + } |
|
161 | 161 | |
162 | - /** |
|
163 | - * @return array |
|
164 | - */ |
|
165 | - public function getReviewsDetails() |
|
166 | - { |
|
167 | - $counts = glsr(CountsManager::class)->getCounts(); |
|
168 | - $counts = Arr::flattenArray($counts); |
|
169 | - array_walk($counts, function (&$ratings) use ($counts) { |
|
170 | - if (!is_array($ratings)) { |
|
171 | - glsr_log() |
|
172 | - ->error('$ratings is not an array, possibly due to incorrectly imported reviews.') |
|
173 | - ->debug($ratings) |
|
174 | - ->debug($counts); |
|
175 | - return; |
|
176 | - } |
|
177 | - $ratings = array_sum($ratings).' ('.implode(', ', $ratings).')'; |
|
178 | - }); |
|
179 | - ksort($counts); |
|
180 | - return $counts; |
|
181 | - } |
|
162 | + /** |
|
163 | + * @return array |
|
164 | + */ |
|
165 | + public function getReviewsDetails() |
|
166 | + { |
|
167 | + $counts = glsr(CountsManager::class)->getCounts(); |
|
168 | + $counts = Arr::flattenArray($counts); |
|
169 | + array_walk($counts, function (&$ratings) use ($counts) { |
|
170 | + if (!is_array($ratings)) { |
|
171 | + glsr_log() |
|
172 | + ->error('$ratings is not an array, possibly due to incorrectly imported reviews.') |
|
173 | + ->debug($ratings) |
|
174 | + ->debug($counts); |
|
175 | + return; |
|
176 | + } |
|
177 | + $ratings = array_sum($ratings).' ('.implode(', ', $ratings).')'; |
|
178 | + }); |
|
179 | + ksort($counts); |
|
180 | + return $counts; |
|
181 | + } |
|
182 | 182 | |
183 | - /** |
|
184 | - * @return array |
|
185 | - */ |
|
186 | - public function getServerDetails() |
|
187 | - { |
|
188 | - global $wpdb; |
|
189 | - return [ |
|
190 | - 'Host Name' => $this->getHostName(), |
|
191 | - 'MySQL Version' => $wpdb->db_version(), |
|
192 | - 'PHP Version' => PHP_VERSION, |
|
193 | - 'Server Software' => filter_input(INPUT_SERVER, 'SERVER_SOFTWARE'), |
|
194 | - ]; |
|
195 | - } |
|
183 | + /** |
|
184 | + * @return array |
|
185 | + */ |
|
186 | + public function getServerDetails() |
|
187 | + { |
|
188 | + global $wpdb; |
|
189 | + return [ |
|
190 | + 'Host Name' => $this->getHostName(), |
|
191 | + 'MySQL Version' => $wpdb->db_version(), |
|
192 | + 'PHP Version' => PHP_VERSION, |
|
193 | + 'Server Software' => filter_input(INPUT_SERVER, 'SERVER_SOFTWARE'), |
|
194 | + ]; |
|
195 | + } |
|
196 | 196 | |
197 | - /** |
|
198 | - * @return array |
|
199 | - */ |
|
200 | - public function getSettingDetails() |
|
201 | - { |
|
202 | - $settings = glsr(OptionManager::class)->get('settings', []); |
|
203 | - $settings = Arr::flattenArray($settings, true); |
|
204 | - $settings = $this->purgeSensitiveData($settings); |
|
205 | - ksort($settings); |
|
206 | - $details = []; |
|
207 | - foreach ($settings as $key => $value) { |
|
208 | - if (Str::startsWith('strings', $key) && Str::endsWith('id', $key)) { |
|
209 | - continue; |
|
210 | - } |
|
211 | - $value = htmlspecialchars(trim(preg_replace('/\s\s+/', '\\n', $value)), ENT_QUOTES, 'UTF-8'); |
|
212 | - $details[$key] = $value; |
|
213 | - } |
|
214 | - return $details; |
|
215 | - } |
|
197 | + /** |
|
198 | + * @return array |
|
199 | + */ |
|
200 | + public function getSettingDetails() |
|
201 | + { |
|
202 | + $settings = glsr(OptionManager::class)->get('settings', []); |
|
203 | + $settings = Arr::flattenArray($settings, true); |
|
204 | + $settings = $this->purgeSensitiveData($settings); |
|
205 | + ksort($settings); |
|
206 | + $details = []; |
|
207 | + foreach ($settings as $key => $value) { |
|
208 | + if (Str::startsWith('strings', $key) && Str::endsWith('id', $key)) { |
|
209 | + continue; |
|
210 | + } |
|
211 | + $value = htmlspecialchars(trim(preg_replace('/\s\s+/', '\\n', $value)), ENT_QUOTES, 'UTF-8'); |
|
212 | + $details[$key] = $value; |
|
213 | + } |
|
214 | + return $details; |
|
215 | + } |
|
216 | 216 | |
217 | - /** |
|
218 | - * @return array |
|
219 | - */ |
|
220 | - public function getPluginDetails() |
|
221 | - { |
|
222 | - return [ |
|
223 | - 'Console level' => glsr(Console::class)->humanLevel(), |
|
224 | - 'Console size' => glsr(Console::class)->humanSize('0'), |
|
225 | - 'Last Rating Count' => date_i18n('Y-m-d H:i', glsr(OptionManager::class)->get('last_review_count')), |
|
226 | - 'Version (current)' => glsr()->version, |
|
227 | - 'Version (previous)' => glsr(OptionManager::class)->get('version_upgraded_from'), |
|
228 | - ]; |
|
229 | - } |
|
217 | + /** |
|
218 | + * @return array |
|
219 | + */ |
|
220 | + public function getPluginDetails() |
|
221 | + { |
|
222 | + return [ |
|
223 | + 'Console level' => glsr(Console::class)->humanLevel(), |
|
224 | + 'Console size' => glsr(Console::class)->humanSize('0'), |
|
225 | + 'Last Rating Count' => date_i18n('Y-m-d H:i', glsr(OptionManager::class)->get('last_review_count')), |
|
226 | + 'Version (current)' => glsr()->version, |
|
227 | + 'Version (previous)' => glsr(OptionManager::class)->get('version_upgraded_from'), |
|
228 | + ]; |
|
229 | + } |
|
230 | 230 | |
231 | - /** |
|
232 | - * @return array |
|
233 | - */ |
|
234 | - public function getWordpressDetails() |
|
235 | - { |
|
236 | - global $wpdb; |
|
237 | - $theme = wp_get_theme(); |
|
238 | - return [ |
|
239 | - 'Active Theme' => sprintf('%s v%s', (string) $theme->Name, (string) $theme->Version), |
|
240 | - 'Email Domain' => substr(strrchr(glsr(OptionManager::class)->getWP('admin_email'), '@'), 1), |
|
241 | - 'Home URL' => home_url(), |
|
242 | - 'Language' => get_locale(), |
|
243 | - 'Memory Limit' => WP_MEMORY_LIMIT, |
|
244 | - 'Multisite' => var_export(is_multisite(), true), |
|
245 | - 'Page For Posts ID' => glsr(OptionManager::class)->getWP('page_for_posts'), |
|
246 | - 'Page On Front ID' => glsr(OptionManager::class)->getWP('page_on_front'), |
|
247 | - 'Permalink Structure' => glsr(OptionManager::class)->getWP('permalink_structure', 'default'), |
|
248 | - 'Post Stati' => implode(', ', get_post_stati()), |
|
249 | - 'Remote Post' => glsr(Cache::class)->getRemotePostTest(), |
|
250 | - 'Show On Front' => glsr(OptionManager::class)->getWP('show_on_front'), |
|
251 | - 'Site URL' => site_url(), |
|
252 | - 'Timezone' => glsr(OptionManager::class)->getWP('timezone_string', ini_get('date.timezone').' (PHP)'), |
|
253 | - 'Version' => get_bloginfo('version'), |
|
254 | - 'WP Debug' => var_export(defined('WP_DEBUG'), true), |
|
255 | - 'WP Max Upload Size' => size_format(wp_max_upload_size()), |
|
256 | - 'WP Memory Limit' => WP_MEMORY_LIMIT, |
|
257 | - ]; |
|
258 | - } |
|
231 | + /** |
|
232 | + * @return array |
|
233 | + */ |
|
234 | + public function getWordpressDetails() |
|
235 | + { |
|
236 | + global $wpdb; |
|
237 | + $theme = wp_get_theme(); |
|
238 | + return [ |
|
239 | + 'Active Theme' => sprintf('%s v%s', (string) $theme->Name, (string) $theme->Version), |
|
240 | + 'Email Domain' => substr(strrchr(glsr(OptionManager::class)->getWP('admin_email'), '@'), 1), |
|
241 | + 'Home URL' => home_url(), |
|
242 | + 'Language' => get_locale(), |
|
243 | + 'Memory Limit' => WP_MEMORY_LIMIT, |
|
244 | + 'Multisite' => var_export(is_multisite(), true), |
|
245 | + 'Page For Posts ID' => glsr(OptionManager::class)->getWP('page_for_posts'), |
|
246 | + 'Page On Front ID' => glsr(OptionManager::class)->getWP('page_on_front'), |
|
247 | + 'Permalink Structure' => glsr(OptionManager::class)->getWP('permalink_structure', 'default'), |
|
248 | + 'Post Stati' => implode(', ', get_post_stati()), |
|
249 | + 'Remote Post' => glsr(Cache::class)->getRemotePostTest(), |
|
250 | + 'Show On Front' => glsr(OptionManager::class)->getWP('show_on_front'), |
|
251 | + 'Site URL' => site_url(), |
|
252 | + 'Timezone' => glsr(OptionManager::class)->getWP('timezone_string', ini_get('date.timezone').' (PHP)'), |
|
253 | + 'Version' => get_bloginfo('version'), |
|
254 | + 'WP Debug' => var_export(defined('WP_DEBUG'), true), |
|
255 | + 'WP Max Upload Size' => size_format(wp_max_upload_size()), |
|
256 | + 'WP Memory Limit' => WP_MEMORY_LIMIT, |
|
257 | + ]; |
|
258 | + } |
|
259 | 259 | |
260 | - /** |
|
261 | - * @return string |
|
262 | - */ |
|
263 | - protected function detectWebhostProvider() |
|
264 | - { |
|
265 | - $checks = [ |
|
266 | - '.accountservergroup.com' => 'Site5', |
|
267 | - '.gridserver.com' => 'MediaTemple Grid', |
|
268 | - '.inmotionhosting.com' => 'InMotion Hosting', |
|
269 | - '.ovh.net' => 'OVH', |
|
270 | - '.pair.com' => 'pair Networks', |
|
271 | - '.stabletransit.com' => 'Rackspace Cloud', |
|
272 | - '.stratoserver.net' => 'STRATO', |
|
273 | - '.sysfix.eu' => 'SysFix.eu Power Hosting', |
|
274 | - 'bluehost.com' => 'Bluehost', |
|
275 | - 'DH_USER' => 'DreamHost', |
|
276 | - 'Flywheel' => 'Flywheel', |
|
277 | - 'ipagemysql.com' => 'iPage', |
|
278 | - 'ipowermysql.com' => 'IPower', |
|
279 | - 'localhost:/tmp/mysql5.sock' => 'ICDSoft', |
|
280 | - 'mysqlv5' => 'NetworkSolutions', |
|
281 | - 'PAGELYBIN' => 'Pagely', |
|
282 | - 'secureserver.net' => 'GoDaddy', |
|
283 | - 'WPE_APIKEY' => 'WP Engine', |
|
284 | - ]; |
|
285 | - foreach ($checks as $key => $value) { |
|
286 | - if (!$this->isWebhostCheckValid($key)) { |
|
287 | - continue; |
|
288 | - } |
|
289 | - return $value; |
|
290 | - } |
|
291 | - return implode(',', array_filter([DB_HOST, filter_input(INPUT_SERVER, 'SERVER_NAME')])); |
|
292 | - } |
|
260 | + /** |
|
261 | + * @return string |
|
262 | + */ |
|
263 | + protected function detectWebhostProvider() |
|
264 | + { |
|
265 | + $checks = [ |
|
266 | + '.accountservergroup.com' => 'Site5', |
|
267 | + '.gridserver.com' => 'MediaTemple Grid', |
|
268 | + '.inmotionhosting.com' => 'InMotion Hosting', |
|
269 | + '.ovh.net' => 'OVH', |
|
270 | + '.pair.com' => 'pair Networks', |
|
271 | + '.stabletransit.com' => 'Rackspace Cloud', |
|
272 | + '.stratoserver.net' => 'STRATO', |
|
273 | + '.sysfix.eu' => 'SysFix.eu Power Hosting', |
|
274 | + 'bluehost.com' => 'Bluehost', |
|
275 | + 'DH_USER' => 'DreamHost', |
|
276 | + 'Flywheel' => 'Flywheel', |
|
277 | + 'ipagemysql.com' => 'iPage', |
|
278 | + 'ipowermysql.com' => 'IPower', |
|
279 | + 'localhost:/tmp/mysql5.sock' => 'ICDSoft', |
|
280 | + 'mysqlv5' => 'NetworkSolutions', |
|
281 | + 'PAGELYBIN' => 'Pagely', |
|
282 | + 'secureserver.net' => 'GoDaddy', |
|
283 | + 'WPE_APIKEY' => 'WP Engine', |
|
284 | + ]; |
|
285 | + foreach ($checks as $key => $value) { |
|
286 | + if (!$this->isWebhostCheckValid($key)) { |
|
287 | + continue; |
|
288 | + } |
|
289 | + return $value; |
|
290 | + } |
|
291 | + return implode(',', array_filter([DB_HOST, filter_input(INPUT_SERVER, 'SERVER_NAME')])); |
|
292 | + } |
|
293 | 293 | |
294 | - /** |
|
295 | - * @return string |
|
296 | - */ |
|
297 | - protected function getHostName() |
|
298 | - { |
|
299 | - return sprintf('%s (%s)', |
|
300 | - $this->detectWebhostProvider(), |
|
301 | - Helper::getIpAddress() |
|
302 | - ); |
|
303 | - } |
|
294 | + /** |
|
295 | + * @return string |
|
296 | + */ |
|
297 | + protected function getHostName() |
|
298 | + { |
|
299 | + return sprintf('%s (%s)', |
|
300 | + $this->detectWebhostProvider(), |
|
301 | + Helper::getIpAddress() |
|
302 | + ); |
|
303 | + } |
|
304 | 304 | |
305 | - /** |
|
306 | - * @return array |
|
307 | - */ |
|
308 | - protected function getWordpressPlugins() |
|
309 | - { |
|
310 | - $plugins = get_plugins(); |
|
311 | - $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array'); |
|
312 | - $inactive = $this->normalizePluginList(array_diff_key($plugins, array_flip($activePlugins))); |
|
313 | - $active = $this->normalizePluginList(array_diff_key($plugins, $inactive)); |
|
314 | - return $active + $inactive; |
|
315 | - } |
|
305 | + /** |
|
306 | + * @return array |
|
307 | + */ |
|
308 | + protected function getWordpressPlugins() |
|
309 | + { |
|
310 | + $plugins = get_plugins(); |
|
311 | + $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array'); |
|
312 | + $inactive = $this->normalizePluginList(array_diff_key($plugins, array_flip($activePlugins))); |
|
313 | + $active = $this->normalizePluginList(array_diff_key($plugins, $inactive)); |
|
314 | + return $active + $inactive; |
|
315 | + } |
|
316 | 316 | |
317 | - /** |
|
318 | - * @param string $title |
|
319 | - * @return string |
|
320 | - */ |
|
321 | - protected function implode($title, array $details) |
|
322 | - { |
|
323 | - $strings = ['['.$title.']']; |
|
324 | - $padding = max(array_map('strlen', array_keys($details))); |
|
325 | - $padding = max([$padding, static::PAD]); |
|
326 | - foreach ($details as $key => $value) { |
|
327 | - $strings[] = is_string($key) |
|
328 | - ? sprintf('%s : %s', str_pad($key, $padding, '.'), $value) |
|
329 | - : ' - '.$value; |
|
330 | - } |
|
331 | - return implode(PHP_EOL, $strings).PHP_EOL.PHP_EOL; |
|
332 | - } |
|
317 | + /** |
|
318 | + * @param string $title |
|
319 | + * @return string |
|
320 | + */ |
|
321 | + protected function implode($title, array $details) |
|
322 | + { |
|
323 | + $strings = ['['.$title.']']; |
|
324 | + $padding = max(array_map('strlen', array_keys($details))); |
|
325 | + $padding = max([$padding, static::PAD]); |
|
326 | + foreach ($details as $key => $value) { |
|
327 | + $strings[] = is_string($key) |
|
328 | + ? sprintf('%s : %s', str_pad($key, $padding, '.'), $value) |
|
329 | + : ' - '.$value; |
|
330 | + } |
|
331 | + return implode(PHP_EOL, $strings).PHP_EOL.PHP_EOL; |
|
332 | + } |
|
333 | 333 | |
334 | - /** |
|
335 | - * @param string $key |
|
336 | - * @return bool |
|
337 | - */ |
|
338 | - protected function isWebhostCheckValid($key) |
|
339 | - { |
|
340 | - return defined($key) |
|
341 | - || filter_input(INPUT_SERVER, $key) |
|
342 | - || false !== strpos(filter_input(INPUT_SERVER, 'SERVER_NAME'), $key) |
|
343 | - || false !== strpos(DB_HOST, $key) |
|
344 | - || false !== strpos(php_uname(), $key); |
|
345 | - } |
|
334 | + /** |
|
335 | + * @param string $key |
|
336 | + * @return bool |
|
337 | + */ |
|
338 | + protected function isWebhostCheckValid($key) |
|
339 | + { |
|
340 | + return defined($key) |
|
341 | + || filter_input(INPUT_SERVER, $key) |
|
342 | + || false !== strpos(filter_input(INPUT_SERVER, 'SERVER_NAME'), $key) |
|
343 | + || false !== strpos(DB_HOST, $key) |
|
344 | + || false !== strpos(php_uname(), $key); |
|
345 | + } |
|
346 | 346 | |
347 | - /** |
|
348 | - * @return array |
|
349 | - */ |
|
350 | - protected function normalizePluginList(array $plugins) |
|
351 | - { |
|
352 | - $plugins = array_map(function ($plugin) { |
|
353 | - return sprintf('%s v%s', Arr::get($plugin, 'Name'), Arr::get($plugin, 'Version')); |
|
354 | - }, $plugins); |
|
355 | - natcasesort($plugins); |
|
356 | - return array_flip($plugins); |
|
357 | - } |
|
347 | + /** |
|
348 | + * @return array |
|
349 | + */ |
|
350 | + protected function normalizePluginList(array $plugins) |
|
351 | + { |
|
352 | + $plugins = array_map(function ($plugin) { |
|
353 | + return sprintf('%s v%s', Arr::get($plugin, 'Name'), Arr::get($plugin, 'Version')); |
|
354 | + }, $plugins); |
|
355 | + natcasesort($plugins); |
|
356 | + return array_flip($plugins); |
|
357 | + } |
|
358 | 358 | |
359 | - /** |
|
360 | - * @return array |
|
361 | - */ |
|
362 | - protected function purgeSensitiveData(array $settings) |
|
363 | - { |
|
364 | - $keys = [ |
|
365 | - 'general.rebusify_serial', |
|
366 | - 'licenses.', |
|
367 | - 'submissions.recaptcha.key', |
|
368 | - 'submissions.recaptcha.secret', |
|
369 | - ]; |
|
370 | - array_walk($settings, function (&$value, $setting) use ($keys) { |
|
371 | - foreach ($keys as $key) { |
|
372 | - if (!Str::startsWith($key, $setting) || empty($value)) { |
|
373 | - continue; |
|
374 | - } |
|
375 | - $value = str_repeat('•', 13); |
|
376 | - return; |
|
377 | - } |
|
378 | - }); |
|
379 | - return $settings; |
|
380 | - } |
|
359 | + /** |
|
360 | + * @return array |
|
361 | + */ |
|
362 | + protected function purgeSensitiveData(array $settings) |
|
363 | + { |
|
364 | + $keys = [ |
|
365 | + 'general.rebusify_serial', |
|
366 | + 'licenses.', |
|
367 | + 'submissions.recaptcha.key', |
|
368 | + 'submissions.recaptcha.secret', |
|
369 | + ]; |
|
370 | + array_walk($settings, function (&$value, $setting) use ($keys) { |
|
371 | + foreach ($keys as $key) { |
|
372 | + if (!Str::startsWith($key, $setting) || empty($value)) { |
|
373 | + continue; |
|
374 | + } |
|
375 | + $value = str_repeat('•', 13); |
|
376 | + return; |
|
377 | + } |
|
378 | + }); |
|
379 | + return $settings; |
|
380 | + } |
|
381 | 381 | } |
@@ -41,17 +41,17 @@ discard block |
||
41 | 41 | 'setting' => 'Plugin Settings', |
42 | 42 | 'reviews' => 'Review Counts', |
43 | 43 | ]; |
44 | - $systemInfo = array_reduce(array_keys($details), function ($carry, $key) use ($details) { |
|
45 | - $methodName = Helper::buildMethodName('get-'.$key.'-details'); |
|
46 | - if (method_exists($this, $methodName) && $systemDetails = $this->$methodName()) { |
|
44 | + $systemInfo = array_reduce( array_keys( $details ), function( $carry, $key ) use ($details) { |
|
45 | + $methodName = Helper::buildMethodName( 'get-'.$key.'-details' ); |
|
46 | + if( method_exists( $this, $methodName ) && $systemDetails = $this->$methodName() ) { |
|
47 | 47 | return $carry.$this->implode( |
48 | - strtoupper($details[$key]), |
|
49 | - apply_filters('site-reviews/system/'.$key, $systemDetails) |
|
48 | + strtoupper( $details[$key] ), |
|
49 | + apply_filters( 'site-reviews/system/'.$key, $systemDetails ) |
|
50 | 50 | ); |
51 | 51 | } |
52 | 52 | return $carry; |
53 | 53 | }); |
54 | - return trim($systemInfo); |
|
54 | + return trim( $systemInfo ); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
@@ -60,9 +60,9 @@ discard block |
||
60 | 60 | public function getActivePluginDetails() |
61 | 61 | { |
62 | 62 | $plugins = get_plugins(); |
63 | - $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array'); |
|
64 | - $inactive = array_diff_key($plugins, array_flip($activePlugins)); |
|
65 | - return $this->normalizePluginList(array_diff_key($plugins, $inactive)); |
|
63 | + $activePlugins = glsr( OptionManager::class )->getWP( 'active_plugins', [], 'array' ); |
|
64 | + $inactive = array_diff_key( $plugins, array_flip( $activePlugins ) ); |
|
65 | + return $this->normalizePluginList( array_diff_key( $plugins, $inactive ) ); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
@@ -70,8 +70,8 @@ discard block |
||
70 | 70 | */ |
71 | 71 | public function getAddonDetails() |
72 | 72 | { |
73 | - $details = apply_filters('site-reviews/addon/system-info', []); |
|
74 | - ksort($details); |
|
73 | + $details = apply_filters( 'site-reviews/addon/system-info', [] ); |
|
74 | + ksort( $details ); |
|
75 | 75 | return $details; |
76 | 76 | } |
77 | 77 | |
@@ -81,11 +81,11 @@ discard block |
||
81 | 81 | public function getBrowserDetails() |
82 | 82 | { |
83 | 83 | $browser = new Browser(); |
84 | - $name = esc_attr($browser->getName()); |
|
85 | - $userAgent = esc_attr($browser->getUserAgent()->getUserAgentString()); |
|
86 | - $version = esc_attr($browser->getVersion()); |
|
84 | + $name = esc_attr( $browser->getName() ); |
|
85 | + $userAgent = esc_attr( $browser->getUserAgent()->getUserAgentString() ); |
|
86 | + $version = esc_attr( $browser->getVersion() ); |
|
87 | 87 | return [ |
88 | - 'Browser Name' => sprintf('%s %s', $name, $version), |
|
88 | + 'Browser Name' => sprintf( '%s %s', $name, $version ), |
|
89 | 89 | 'Browser UA' => $userAgent, |
90 | 90 | ]; |
91 | 91 | } |
@@ -95,12 +95,12 @@ discard block |
||
95 | 95 | */ |
96 | 96 | public function getInactivePluginDetails() |
97 | 97 | { |
98 | - $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array'); |
|
99 | - $inactivePlugins = $this->normalizePluginList(array_diff_key(get_plugins(), array_flip($activePlugins))); |
|
98 | + $activePlugins = glsr( OptionManager::class )->getWP( 'active_plugins', [], 'array' ); |
|
99 | + $inactivePlugins = $this->normalizePluginList( array_diff_key( get_plugins(), array_flip( $activePlugins ) ) ); |
|
100 | 100 | $multisitePlugins = $this->getMultisitePluginDetails(); |
101 | 101 | return empty($multisitePlugins) |
102 | 102 | ? $inactivePlugins |
103 | - : array_diff($inactivePlugins, $multisitePlugins); |
|
103 | + : array_diff( $inactivePlugins, $multisitePlugins ); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
@@ -108,10 +108,10 @@ discard block |
||
108 | 108 | */ |
109 | 109 | public function getMuPluginDetails() |
110 | 110 | { |
111 | - if (empty($plugins = get_mu_plugins())) { |
|
111 | + if( empty($plugins = get_mu_plugins()) ) { |
|
112 | 112 | return []; |
113 | 113 | } |
114 | - return $this->normalizePluginList($plugins); |
|
114 | + return $this->normalizePluginList( $plugins ); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | /** |
@@ -119,11 +119,11 @@ discard block |
||
119 | 119 | */ |
120 | 120 | public function getMultisitePluginDetails() |
121 | 121 | { |
122 | - $activePlugins = (array) get_site_option('active_sitewide_plugins', []); |
|
123 | - if (!is_multisite() || empty($activePlugins)) { |
|
122 | + $activePlugins = (array)get_site_option( 'active_sitewide_plugins', [] ); |
|
123 | + if( !is_multisite() || empty($activePlugins) ) { |
|
124 | 124 | return []; |
125 | 125 | } |
126 | - return $this->normalizePluginList(array_intersect_key(get_plugins(), $activePlugins)); |
|
126 | + return $this->normalizePluginList( array_intersect_key( get_plugins(), $activePlugins ) ); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | /** |
@@ -131,31 +131,31 @@ discard block |
||
131 | 131 | */ |
132 | 132 | public function getPhpDetails() |
133 | 133 | { |
134 | - $displayErrors = ini_get('display_errors') |
|
135 | - ? 'On ('.ini_get('display_errors').')' |
|
134 | + $displayErrors = ini_get( 'display_errors' ) |
|
135 | + ? 'On ('.ini_get( 'display_errors' ).')' |
|
136 | 136 | : 'N/A'; |
137 | - $intlSupport = extension_loaded('intl') |
|
138 | - ? phpversion('intl') |
|
137 | + $intlSupport = extension_loaded( 'intl' ) |
|
138 | + ? phpversion( 'intl' ) |
|
139 | 139 | : 'false'; |
140 | 140 | return [ |
141 | - 'cURL' => var_export(function_exists('curl_init'), true), |
|
142 | - 'Default Charset' => ini_get('default_charset'), |
|
141 | + 'cURL' => var_export( function_exists( 'curl_init' ), true ), |
|
142 | + 'Default Charset' => ini_get( 'default_charset' ), |
|
143 | 143 | 'Display Errors' => $displayErrors, |
144 | - 'fsockopen' => var_export(function_exists('fsockopen'), true), |
|
144 | + 'fsockopen' => var_export( function_exists( 'fsockopen' ), true ), |
|
145 | 145 | 'Intl' => $intlSupport, |
146 | - 'IPv6' => var_export(defined('AF_INET6'), true), |
|
147 | - 'Max Execution Time' => ini_get('max_execution_time'), |
|
148 | - 'Max Input Nesting Level' => ini_get('max_input_nesting_level'), |
|
149 | - 'Max Input Vars' => ini_get('max_input_vars'), |
|
150 | - 'Memory Limit' => ini_get('memory_limit'), |
|
151 | - 'Post Max Size' => ini_get('post_max_size'), |
|
152 | - 'Sendmail Path' => ini_get('sendmail_path'), |
|
153 | - 'Session Cookie Path' => esc_html(ini_get('session.cookie_path')), |
|
154 | - 'Session Name' => esc_html(ini_get('session.name')), |
|
155 | - 'Session Save Path' => esc_html(ini_get('session.save_path')), |
|
156 | - 'Session Use Cookies' => var_export(wp_validate_boolean(ini_get('session.use_cookies')), true), |
|
157 | - 'Session Use Only Cookies' => var_export(wp_validate_boolean(ini_get('session.use_only_cookies')), true), |
|
158 | - 'Upload Max Filesize' => ini_get('upload_max_filesize'), |
|
146 | + 'IPv6' => var_export( defined( 'AF_INET6' ), true ), |
|
147 | + 'Max Execution Time' => ini_get( 'max_execution_time' ), |
|
148 | + 'Max Input Nesting Level' => ini_get( 'max_input_nesting_level' ), |
|
149 | + 'Max Input Vars' => ini_get( 'max_input_vars' ), |
|
150 | + 'Memory Limit' => ini_get( 'memory_limit' ), |
|
151 | + 'Post Max Size' => ini_get( 'post_max_size' ), |
|
152 | + 'Sendmail Path' => ini_get( 'sendmail_path' ), |
|
153 | + 'Session Cookie Path' => esc_html( ini_get( 'session.cookie_path' ) ), |
|
154 | + 'Session Name' => esc_html( ini_get( 'session.name' ) ), |
|
155 | + 'Session Save Path' => esc_html( ini_get( 'session.save_path' ) ), |
|
156 | + 'Session Use Cookies' => var_export( wp_validate_boolean( ini_get( 'session.use_cookies' ) ), true ), |
|
157 | + 'Session Use Only Cookies' => var_export( wp_validate_boolean( ini_get( 'session.use_only_cookies' ) ), true ), |
|
158 | + 'Upload Max Filesize' => ini_get( 'upload_max_filesize' ), |
|
159 | 159 | ]; |
160 | 160 | } |
161 | 161 | |
@@ -164,19 +164,19 @@ discard block |
||
164 | 164 | */ |
165 | 165 | public function getReviewsDetails() |
166 | 166 | { |
167 | - $counts = glsr(CountsManager::class)->getCounts(); |
|
168 | - $counts = Arr::flattenArray($counts); |
|
169 | - array_walk($counts, function (&$ratings) use ($counts) { |
|
170 | - if (!is_array($ratings)) { |
|
167 | + $counts = glsr( CountsManager::class )->getCounts(); |
|
168 | + $counts = Arr::flattenArray( $counts ); |
|
169 | + array_walk( $counts, function( &$ratings ) use ($counts) { |
|
170 | + if( !is_array( $ratings ) ) { |
|
171 | 171 | glsr_log() |
172 | - ->error('$ratings is not an array, possibly due to incorrectly imported reviews.') |
|
173 | - ->debug($ratings) |
|
174 | - ->debug($counts); |
|
172 | + ->error( '$ratings is not an array, possibly due to incorrectly imported reviews.' ) |
|
173 | + ->debug( $ratings ) |
|
174 | + ->debug( $counts ); |
|
175 | 175 | return; |
176 | 176 | } |
177 | - $ratings = array_sum($ratings).' ('.implode(', ', $ratings).')'; |
|
177 | + $ratings = array_sum( $ratings ).' ('.implode( ', ', $ratings ).')'; |
|
178 | 178 | }); |
179 | - ksort($counts); |
|
179 | + ksort( $counts ); |
|
180 | 180 | return $counts; |
181 | 181 | } |
182 | 182 | |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | 'Host Name' => $this->getHostName(), |
191 | 191 | 'MySQL Version' => $wpdb->db_version(), |
192 | 192 | 'PHP Version' => PHP_VERSION, |
193 | - 'Server Software' => filter_input(INPUT_SERVER, 'SERVER_SOFTWARE'), |
|
193 | + 'Server Software' => filter_input( INPUT_SERVER, 'SERVER_SOFTWARE' ), |
|
194 | 194 | ]; |
195 | 195 | } |
196 | 196 | |
@@ -199,16 +199,16 @@ discard block |
||
199 | 199 | */ |
200 | 200 | public function getSettingDetails() |
201 | 201 | { |
202 | - $settings = glsr(OptionManager::class)->get('settings', []); |
|
203 | - $settings = Arr::flattenArray($settings, true); |
|
204 | - $settings = $this->purgeSensitiveData($settings); |
|
205 | - ksort($settings); |
|
202 | + $settings = glsr( OptionManager::class )->get( 'settings', [] ); |
|
203 | + $settings = Arr::flattenArray( $settings, true ); |
|
204 | + $settings = $this->purgeSensitiveData( $settings ); |
|
205 | + ksort( $settings ); |
|
206 | 206 | $details = []; |
207 | - foreach ($settings as $key => $value) { |
|
208 | - if (Str::startsWith('strings', $key) && Str::endsWith('id', $key)) { |
|
207 | + foreach( $settings as $key => $value ) { |
|
208 | + if( Str::startsWith( 'strings', $key ) && Str::endsWith( 'id', $key ) ) { |
|
209 | 209 | continue; |
210 | 210 | } |
211 | - $value = htmlspecialchars(trim(preg_replace('/\s\s+/', '\\n', $value)), ENT_QUOTES, 'UTF-8'); |
|
211 | + $value = htmlspecialchars( trim( preg_replace( '/\s\s+/', '\\n', $value ) ), ENT_QUOTES, 'UTF-8' ); |
|
212 | 212 | $details[$key] = $value; |
213 | 213 | } |
214 | 214 | return $details; |
@@ -220,11 +220,11 @@ discard block |
||
220 | 220 | public function getPluginDetails() |
221 | 221 | { |
222 | 222 | return [ |
223 | - 'Console level' => glsr(Console::class)->humanLevel(), |
|
224 | - 'Console size' => glsr(Console::class)->humanSize('0'), |
|
225 | - 'Last Rating Count' => date_i18n('Y-m-d H:i', glsr(OptionManager::class)->get('last_review_count')), |
|
223 | + 'Console level' => glsr( Console::class )->humanLevel(), |
|
224 | + 'Console size' => glsr( Console::class )->humanSize( '0' ), |
|
225 | + 'Last Rating Count' => date_i18n( 'Y-m-d H:i', glsr( OptionManager::class )->get( 'last_review_count' ) ), |
|
226 | 226 | 'Version (current)' => glsr()->version, |
227 | - 'Version (previous)' => glsr(OptionManager::class)->get('version_upgraded_from'), |
|
227 | + 'Version (previous)' => glsr( OptionManager::class )->get( 'version_upgraded_from' ), |
|
228 | 228 | ]; |
229 | 229 | } |
230 | 230 | |
@@ -236,23 +236,23 @@ discard block |
||
236 | 236 | global $wpdb; |
237 | 237 | $theme = wp_get_theme(); |
238 | 238 | return [ |
239 | - 'Active Theme' => sprintf('%s v%s', (string) $theme->Name, (string) $theme->Version), |
|
240 | - 'Email Domain' => substr(strrchr(glsr(OptionManager::class)->getWP('admin_email'), '@'), 1), |
|
239 | + 'Active Theme' => sprintf( '%s v%s', (string)$theme->Name, (string)$theme->Version ), |
|
240 | + 'Email Domain' => substr( strrchr( glsr( OptionManager::class )->getWP( 'admin_email' ), '@' ), 1 ), |
|
241 | 241 | 'Home URL' => home_url(), |
242 | 242 | 'Language' => get_locale(), |
243 | 243 | 'Memory Limit' => WP_MEMORY_LIMIT, |
244 | - 'Multisite' => var_export(is_multisite(), true), |
|
245 | - 'Page For Posts ID' => glsr(OptionManager::class)->getWP('page_for_posts'), |
|
246 | - 'Page On Front ID' => glsr(OptionManager::class)->getWP('page_on_front'), |
|
247 | - 'Permalink Structure' => glsr(OptionManager::class)->getWP('permalink_structure', 'default'), |
|
248 | - 'Post Stati' => implode(', ', get_post_stati()), |
|
249 | - 'Remote Post' => glsr(Cache::class)->getRemotePostTest(), |
|
250 | - 'Show On Front' => glsr(OptionManager::class)->getWP('show_on_front'), |
|
244 | + 'Multisite' => var_export( is_multisite(), true ), |
|
245 | + 'Page For Posts ID' => glsr( OptionManager::class )->getWP( 'page_for_posts' ), |
|
246 | + 'Page On Front ID' => glsr( OptionManager::class )->getWP( 'page_on_front' ), |
|
247 | + 'Permalink Structure' => glsr( OptionManager::class )->getWP( 'permalink_structure', 'default' ), |
|
248 | + 'Post Stati' => implode( ', ', get_post_stati() ), |
|
249 | + 'Remote Post' => glsr( Cache::class )->getRemotePostTest(), |
|
250 | + 'Show On Front' => glsr( OptionManager::class )->getWP( 'show_on_front' ), |
|
251 | 251 | 'Site URL' => site_url(), |
252 | - 'Timezone' => glsr(OptionManager::class)->getWP('timezone_string', ini_get('date.timezone').' (PHP)'), |
|
253 | - 'Version' => get_bloginfo('version'), |
|
254 | - 'WP Debug' => var_export(defined('WP_DEBUG'), true), |
|
255 | - 'WP Max Upload Size' => size_format(wp_max_upload_size()), |
|
252 | + 'Timezone' => glsr( OptionManager::class )->getWP( 'timezone_string', ini_get( 'date.timezone' ).' (PHP)' ), |
|
253 | + 'Version' => get_bloginfo( 'version' ), |
|
254 | + 'WP Debug' => var_export( defined( 'WP_DEBUG' ), true ), |
|
255 | + 'WP Max Upload Size' => size_format( wp_max_upload_size() ), |
|
256 | 256 | 'WP Memory Limit' => WP_MEMORY_LIMIT, |
257 | 257 | ]; |
258 | 258 | } |
@@ -282,13 +282,13 @@ discard block |
||
282 | 282 | 'secureserver.net' => 'GoDaddy', |
283 | 283 | 'WPE_APIKEY' => 'WP Engine', |
284 | 284 | ]; |
285 | - foreach ($checks as $key => $value) { |
|
286 | - if (!$this->isWebhostCheckValid($key)) { |
|
285 | + foreach( $checks as $key => $value ) { |
|
286 | + if( !$this->isWebhostCheckValid( $key ) ) { |
|
287 | 287 | continue; |
288 | 288 | } |
289 | 289 | return $value; |
290 | 290 | } |
291 | - return implode(',', array_filter([DB_HOST, filter_input(INPUT_SERVER, 'SERVER_NAME')])); |
|
291 | + return implode( ',', array_filter( [DB_HOST, filter_input( INPUT_SERVER, 'SERVER_NAME' )] ) ); |
|
292 | 292 | } |
293 | 293 | |
294 | 294 | /** |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | */ |
297 | 297 | protected function getHostName() |
298 | 298 | { |
299 | - return sprintf('%s (%s)', |
|
299 | + return sprintf( '%s (%s)', |
|
300 | 300 | $this->detectWebhostProvider(), |
301 | 301 | Helper::getIpAddress() |
302 | 302 | ); |
@@ -308,9 +308,9 @@ discard block |
||
308 | 308 | protected function getWordpressPlugins() |
309 | 309 | { |
310 | 310 | $plugins = get_plugins(); |
311 | - $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array'); |
|
312 | - $inactive = $this->normalizePluginList(array_diff_key($plugins, array_flip($activePlugins))); |
|
313 | - $active = $this->normalizePluginList(array_diff_key($plugins, $inactive)); |
|
311 | + $activePlugins = glsr( OptionManager::class )->getWP( 'active_plugins', [], 'array' ); |
|
312 | + $inactive = $this->normalizePluginList( array_diff_key( $plugins, array_flip( $activePlugins ) ) ); |
|
313 | + $active = $this->normalizePluginList( array_diff_key( $plugins, $inactive ) ); |
|
314 | 314 | return $active + $inactive; |
315 | 315 | } |
316 | 316 | |
@@ -318,48 +318,48 @@ discard block |
||
318 | 318 | * @param string $title |
319 | 319 | * @return string |
320 | 320 | */ |
321 | - protected function implode($title, array $details) |
|
321 | + protected function implode( $title, array $details ) |
|
322 | 322 | { |
323 | 323 | $strings = ['['.$title.']']; |
324 | - $padding = max(array_map('strlen', array_keys($details))); |
|
325 | - $padding = max([$padding, static::PAD]); |
|
326 | - foreach ($details as $key => $value) { |
|
327 | - $strings[] = is_string($key) |
|
328 | - ? sprintf('%s : %s', str_pad($key, $padding, '.'), $value) |
|
324 | + $padding = max( array_map( 'strlen', array_keys( $details ) ) ); |
|
325 | + $padding = max( [$padding, static::PAD] ); |
|
326 | + foreach( $details as $key => $value ) { |
|
327 | + $strings[] = is_string( $key ) |
|
328 | + ? sprintf( '%s : %s', str_pad( $key, $padding, '.' ), $value ) |
|
329 | 329 | : ' - '.$value; |
330 | 330 | } |
331 | - return implode(PHP_EOL, $strings).PHP_EOL.PHP_EOL; |
|
331 | + return implode( PHP_EOL, $strings ).PHP_EOL.PHP_EOL; |
|
332 | 332 | } |
333 | 333 | |
334 | 334 | /** |
335 | 335 | * @param string $key |
336 | 336 | * @return bool |
337 | 337 | */ |
338 | - protected function isWebhostCheckValid($key) |
|
338 | + protected function isWebhostCheckValid( $key ) |
|
339 | 339 | { |
340 | - return defined($key) |
|
341 | - || filter_input(INPUT_SERVER, $key) |
|
342 | - || false !== strpos(filter_input(INPUT_SERVER, 'SERVER_NAME'), $key) |
|
343 | - || false !== strpos(DB_HOST, $key) |
|
344 | - || false !== strpos(php_uname(), $key); |
|
340 | + return defined( $key ) |
|
341 | + || filter_input( INPUT_SERVER, $key ) |
|
342 | + || false !== strpos( filter_input( INPUT_SERVER, 'SERVER_NAME' ), $key ) |
|
343 | + || false !== strpos( DB_HOST, $key ) |
|
344 | + || false !== strpos( php_uname(), $key ); |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | /** |
348 | 348 | * @return array |
349 | 349 | */ |
350 | - protected function normalizePluginList(array $plugins) |
|
350 | + protected function normalizePluginList( array $plugins ) |
|
351 | 351 | { |
352 | - $plugins = array_map(function ($plugin) { |
|
353 | - return sprintf('%s v%s', Arr::get($plugin, 'Name'), Arr::get($plugin, 'Version')); |
|
354 | - }, $plugins); |
|
355 | - natcasesort($plugins); |
|
356 | - return array_flip($plugins); |
|
352 | + $plugins = array_map( function( $plugin ) { |
|
353 | + return sprintf( '%s v%s', Arr::get( $plugin, 'Name' ), Arr::get( $plugin, 'Version' ) ); |
|
354 | + }, $plugins ); |
|
355 | + natcasesort( $plugins ); |
|
356 | + return array_flip( $plugins ); |
|
357 | 357 | } |
358 | 358 | |
359 | 359 | /** |
360 | 360 | * @return array |
361 | 361 | */ |
362 | - protected function purgeSensitiveData(array $settings) |
|
362 | + protected function purgeSensitiveData( array $settings ) |
|
363 | 363 | { |
364 | 364 | $keys = [ |
365 | 365 | 'general.rebusify_serial', |
@@ -367,12 +367,12 @@ discard block |
||
367 | 367 | 'submissions.recaptcha.key', |
368 | 368 | 'submissions.recaptcha.secret', |
369 | 369 | ]; |
370 | - array_walk($settings, function (&$value, $setting) use ($keys) { |
|
371 | - foreach ($keys as $key) { |
|
372 | - if (!Str::startsWith($key, $setting) || empty($value)) { |
|
370 | + array_walk( $settings, function( &$value, $setting ) use ($keys) { |
|
371 | + foreach( $keys as $key ) { |
|
372 | + if( !Str::startsWith( $key, $setting ) || empty($value) ) { |
|
373 | 373 | continue; |
374 | 374 | } |
375 | - $value = str_repeat('•', 13); |
|
375 | + $value = str_repeat( '•', 13 ); |
|
376 | 376 | return; |
377 | 377 | } |
378 | 378 | }); |
@@ -13,248 +13,248 @@ |
||
13 | 13 | |
14 | 14 | abstract class BaseType implements ArrayAccess, JsonSerializable, Type |
15 | 15 | { |
16 | - /** |
|
17 | - * @var array |
|
18 | - */ |
|
19 | - public $allowed = []; |
|
16 | + /** |
|
17 | + * @var array |
|
18 | + */ |
|
19 | + public $allowed = []; |
|
20 | 20 | |
21 | - /** |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - public $parents = []; |
|
21 | + /** |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + public $parents = []; |
|
25 | 25 | |
26 | - /** |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - protected $properties = []; |
|
26 | + /** |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + protected $properties = []; |
|
30 | 30 | |
31 | - /** |
|
32 | - * @var string |
|
33 | - */ |
|
34 | - protected $type; |
|
31 | + /** |
|
32 | + * @var string |
|
33 | + */ |
|
34 | + protected $type; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @param string $method |
|
38 | - * @return static |
|
39 | - */ |
|
40 | - public function __call($method, array $arguments) |
|
41 | - { |
|
42 | - return $this->setProperty($method, Arr::get($arguments, 0)); |
|
43 | - } |
|
36 | + /** |
|
37 | + * @param string $method |
|
38 | + * @return static |
|
39 | + */ |
|
40 | + public function __call($method, array $arguments) |
|
41 | + { |
|
42 | + return $this->setProperty($method, Arr::get($arguments, 0)); |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * @param string $type |
|
47 | - */ |
|
48 | - public function __construct($type = null) |
|
49 | - { |
|
50 | - $this->type = !is_string($type) |
|
51 | - ? (new ReflectionClass($this))->getShortName() |
|
52 | - : $type; |
|
53 | - $this->setAllowedProperties(); |
|
54 | - } |
|
45 | + /** |
|
46 | + * @param string $type |
|
47 | + */ |
|
48 | + public function __construct($type = null) |
|
49 | + { |
|
50 | + $this->type = !is_string($type) |
|
51 | + ? (new ReflectionClass($this))->getShortName() |
|
52 | + : $type; |
|
53 | + $this->setAllowedProperties(); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * @return string |
|
58 | - */ |
|
59 | - public function __toString() |
|
60 | - { |
|
61 | - return $this->toScript(); |
|
62 | - } |
|
56 | + /** |
|
57 | + * @return string |
|
58 | + */ |
|
59 | + public function __toString() |
|
60 | + { |
|
61 | + return $this->toScript(); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @return static |
|
66 | - */ |
|
67 | - public function addProperties(array $properties) |
|
68 | - { |
|
69 | - foreach ($properties as $property => $value) { |
|
70 | - $this->setProperty($property, $value); |
|
71 | - } |
|
72 | - return $this; |
|
73 | - } |
|
64 | + /** |
|
65 | + * @return static |
|
66 | + */ |
|
67 | + public function addProperties(array $properties) |
|
68 | + { |
|
69 | + foreach ($properties as $property => $value) { |
|
70 | + $this->setProperty($property, $value); |
|
71 | + } |
|
72 | + return $this; |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * @return string |
|
77 | - */ |
|
78 | - public function getContext() |
|
79 | - { |
|
80 | - return 'https://schema.org'; |
|
81 | - } |
|
75 | + /** |
|
76 | + * @return string |
|
77 | + */ |
|
78 | + public function getContext() |
|
79 | + { |
|
80 | + return 'https://schema.org'; |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * @return array |
|
85 | - */ |
|
86 | - public function getProperties() |
|
87 | - { |
|
88 | - return $this->properties; |
|
89 | - } |
|
83 | + /** |
|
84 | + * @return array |
|
85 | + */ |
|
86 | + public function getProperties() |
|
87 | + { |
|
88 | + return $this->properties; |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * @param string $property |
|
93 | - * @param mixed $default |
|
94 | - * @return mixed |
|
95 | - */ |
|
96 | - public function getProperty($property, $default = null) |
|
97 | - { |
|
98 | - return Arr::get($this->properties, $property, $default); |
|
99 | - } |
|
91 | + /** |
|
92 | + * @param string $property |
|
93 | + * @param mixed $default |
|
94 | + * @return mixed |
|
95 | + */ |
|
96 | + public function getProperty($property, $default = null) |
|
97 | + { |
|
98 | + return Arr::get($this->properties, $property, $default); |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * @return string |
|
103 | - */ |
|
104 | - public function getType() |
|
105 | - { |
|
106 | - return $this->type; |
|
107 | - } |
|
101 | + /** |
|
102 | + * @return string |
|
103 | + */ |
|
104 | + public function getType() |
|
105 | + { |
|
106 | + return $this->type; |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * @param bool $condition |
|
111 | - * @param mixed $callback |
|
112 | - * @return static |
|
113 | - */ |
|
114 | - public function doIf($condition, $callback) |
|
115 | - { |
|
116 | - if ($condition) { |
|
117 | - $callback($this); |
|
118 | - } |
|
119 | - return $this; |
|
120 | - } |
|
109 | + /** |
|
110 | + * @param bool $condition |
|
111 | + * @param mixed $callback |
|
112 | + * @return static |
|
113 | + */ |
|
114 | + public function doIf($condition, $callback) |
|
115 | + { |
|
116 | + if ($condition) { |
|
117 | + $callback($this); |
|
118 | + } |
|
119 | + return $this; |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * @return array |
|
124 | - */ |
|
125 | - public function jsonSerialize() |
|
126 | - { |
|
127 | - return $this->toArray(); |
|
128 | - } |
|
122 | + /** |
|
123 | + * @return array |
|
124 | + */ |
|
125 | + public function jsonSerialize() |
|
126 | + { |
|
127 | + return $this->toArray(); |
|
128 | + } |
|
129 | 129 | |
130 | - /** |
|
131 | - * @param mixed $offset |
|
132 | - * @return bool |
|
133 | - */ |
|
134 | - public function offsetExists($offset) |
|
135 | - { |
|
136 | - return array_key_exists($offset, $this->properties); |
|
137 | - } |
|
130 | + /** |
|
131 | + * @param mixed $offset |
|
132 | + * @return bool |
|
133 | + */ |
|
134 | + public function offsetExists($offset) |
|
135 | + { |
|
136 | + return array_key_exists($offset, $this->properties); |
|
137 | + } |
|
138 | 138 | |
139 | - /** |
|
140 | - * @param string $offset |
|
141 | - * @return mixed |
|
142 | - */ |
|
143 | - public function offsetGet($offset) |
|
144 | - { |
|
145 | - return $this->getProperty($offset); |
|
146 | - } |
|
139 | + /** |
|
140 | + * @param string $offset |
|
141 | + * @return mixed |
|
142 | + */ |
|
143 | + public function offsetGet($offset) |
|
144 | + { |
|
145 | + return $this->getProperty($offset); |
|
146 | + } |
|
147 | 147 | |
148 | - /** |
|
149 | - * @param string $offset |
|
150 | - * @param mixed $value |
|
151 | - * @return void |
|
152 | - */ |
|
153 | - public function offsetSet($offset, $value) |
|
154 | - { |
|
155 | - $this->setProperty($offset, $value); |
|
156 | - } |
|
148 | + /** |
|
149 | + * @param string $offset |
|
150 | + * @param mixed $value |
|
151 | + * @return void |
|
152 | + */ |
|
153 | + public function offsetSet($offset, $value) |
|
154 | + { |
|
155 | + $this->setProperty($offset, $value); |
|
156 | + } |
|
157 | 157 | |
158 | - /** |
|
159 | - * @param string $offset |
|
160 | - * @return void |
|
161 | - */ |
|
162 | - public function offsetUnset($offset) |
|
163 | - { |
|
164 | - unset($this->properties[$offset]); |
|
165 | - } |
|
158 | + /** |
|
159 | + * @param string $offset |
|
160 | + * @return void |
|
161 | + */ |
|
162 | + public function offsetUnset($offset) |
|
163 | + { |
|
164 | + unset($this->properties[$offset]); |
|
165 | + } |
|
166 | 166 | |
167 | - /** |
|
168 | - * @param string $property |
|
169 | - * @param mixed $value |
|
170 | - * @return static |
|
171 | - */ |
|
172 | - public function setProperty($property, $value) |
|
173 | - { |
|
174 | - if (!in_array($property, $this->allowed) |
|
175 | - && 'UnknownType' != (new ReflectionClass($this))->getShortName()) { |
|
176 | - glsr_log()->warning($this->getType().' does not allow the "'.$property.'" property'); |
|
177 | - return $this; |
|
178 | - } |
|
179 | - $this->properties[$property] = $value; |
|
180 | - return $this; |
|
181 | - } |
|
167 | + /** |
|
168 | + * @param string $property |
|
169 | + * @param mixed $value |
|
170 | + * @return static |
|
171 | + */ |
|
172 | + public function setProperty($property, $value) |
|
173 | + { |
|
174 | + if (!in_array($property, $this->allowed) |
|
175 | + && 'UnknownType' != (new ReflectionClass($this))->getShortName()) { |
|
176 | + glsr_log()->warning($this->getType().' does not allow the "'.$property.'" property'); |
|
177 | + return $this; |
|
178 | + } |
|
179 | + $this->properties[$property] = $value; |
|
180 | + return $this; |
|
181 | + } |
|
182 | 182 | |
183 | - /** |
|
184 | - * @return array |
|
185 | - */ |
|
186 | - public function toArray() |
|
187 | - { |
|
188 | - return [ |
|
189 | - '@context' => $this->getContext(), |
|
190 | - '@type' => $this->getType(), |
|
191 | - ] + $this->serializeProperty($this->getProperties()); |
|
192 | - } |
|
183 | + /** |
|
184 | + * @return array |
|
185 | + */ |
|
186 | + public function toArray() |
|
187 | + { |
|
188 | + return [ |
|
189 | + '@context' => $this->getContext(), |
|
190 | + '@type' => $this->getType(), |
|
191 | + ] + $this->serializeProperty($this->getProperties()); |
|
192 | + } |
|
193 | 193 | |
194 | - /** |
|
195 | - * @return string |
|
196 | - */ |
|
197 | - public function toScript() |
|
198 | - { |
|
199 | - return sprintf('<script type="application/ld+json">%s</script>', |
|
200 | - json_encode($this->toArray(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) |
|
201 | - ); |
|
202 | - } |
|
194 | + /** |
|
195 | + * @return string |
|
196 | + */ |
|
197 | + public function toScript() |
|
198 | + { |
|
199 | + return sprintf('<script type="application/ld+json">%s</script>', |
|
200 | + json_encode($this->toArray(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) |
|
201 | + ); |
|
202 | + } |
|
203 | 203 | |
204 | - /** |
|
205 | - * @param array|null $parents |
|
206 | - * @return array |
|
207 | - */ |
|
208 | - protected function getParents($parents = null) |
|
209 | - { |
|
210 | - if (!isset($parents)) { |
|
211 | - $parents = $this->parents; |
|
212 | - } |
|
213 | - $newParents = $parents; |
|
214 | - foreach ($parents as $parent) { |
|
215 | - $parentClass = Helper::buildClassName($parent, __NAMESPACE__); |
|
216 | - if (!class_exists($parentClass)) { |
|
217 | - continue; |
|
218 | - } |
|
219 | - $newParents = array_merge($newParents, $this->getParents((new $parentClass())->parents)); |
|
220 | - } |
|
221 | - return array_values(array_unique($newParents)); |
|
222 | - } |
|
204 | + /** |
|
205 | + * @param array|null $parents |
|
206 | + * @return array |
|
207 | + */ |
|
208 | + protected function getParents($parents = null) |
|
209 | + { |
|
210 | + if (!isset($parents)) { |
|
211 | + $parents = $this->parents; |
|
212 | + } |
|
213 | + $newParents = $parents; |
|
214 | + foreach ($parents as $parent) { |
|
215 | + $parentClass = Helper::buildClassName($parent, __NAMESPACE__); |
|
216 | + if (!class_exists($parentClass)) { |
|
217 | + continue; |
|
218 | + } |
|
219 | + $newParents = array_merge($newParents, $this->getParents((new $parentClass())->parents)); |
|
220 | + } |
|
221 | + return array_values(array_unique($newParents)); |
|
222 | + } |
|
223 | 223 | |
224 | - /** |
|
225 | - * @return void |
|
226 | - */ |
|
227 | - protected function setAllowedProperties() |
|
228 | - { |
|
229 | - $parents = $this->getParents(); |
|
230 | - foreach ($parents as $parent) { |
|
231 | - $parentClass = Helper::buildClassName($parent, __NAMESPACE__); |
|
232 | - if (!class_exists($parentClass)) { |
|
233 | - continue; |
|
234 | - } |
|
235 | - $this->allowed = array_values(array_unique(array_merge((new $parentClass())->allowed, $this->allowed))); |
|
236 | - } |
|
237 | - } |
|
224 | + /** |
|
225 | + * @return void |
|
226 | + */ |
|
227 | + protected function setAllowedProperties() |
|
228 | + { |
|
229 | + $parents = $this->getParents(); |
|
230 | + foreach ($parents as $parent) { |
|
231 | + $parentClass = Helper::buildClassName($parent, __NAMESPACE__); |
|
232 | + if (!class_exists($parentClass)) { |
|
233 | + continue; |
|
234 | + } |
|
235 | + $this->allowed = array_values(array_unique(array_merge((new $parentClass())->allowed, $this->allowed))); |
|
236 | + } |
|
237 | + } |
|
238 | 238 | |
239 | - /** |
|
240 | - * @param mixed $property |
|
241 | - * @return array|string |
|
242 | - */ |
|
243 | - protected function serializeProperty($property) |
|
244 | - { |
|
245 | - if (is_array($property)) { |
|
246 | - return array_map([$this, 'serializeProperty'], $property); |
|
247 | - } |
|
248 | - if ($property instanceof Type) { |
|
249 | - $property = $property->toArray(); |
|
250 | - unset($property['@context']); |
|
251 | - } |
|
252 | - if ($property instanceof DateTimeInterface) { |
|
253 | - $property = $property->format(DateTime::ATOM); |
|
254 | - } |
|
255 | - if (is_object($property)) { |
|
256 | - throw new InvalidProperty(); |
|
257 | - } |
|
258 | - return $property; |
|
259 | - } |
|
239 | + /** |
|
240 | + * @param mixed $property |
|
241 | + * @return array|string |
|
242 | + */ |
|
243 | + protected function serializeProperty($property) |
|
244 | + { |
|
245 | + if (is_array($property)) { |
|
246 | + return array_map([$this, 'serializeProperty'], $property); |
|
247 | + } |
|
248 | + if ($property instanceof Type) { |
|
249 | + $property = $property->toArray(); |
|
250 | + unset($property['@context']); |
|
251 | + } |
|
252 | + if ($property instanceof DateTimeInterface) { |
|
253 | + $property = $property->format(DateTime::ATOM); |
|
254 | + } |
|
255 | + if (is_object($property)) { |
|
256 | + throw new InvalidProperty(); |
|
257 | + } |
|
258 | + return $property; |
|
259 | + } |
|
260 | 260 | } |
@@ -37,18 +37,18 @@ discard block |
||
37 | 37 | * @param string $method |
38 | 38 | * @return static |
39 | 39 | */ |
40 | - public function __call($method, array $arguments) |
|
40 | + public function __call( $method, array $arguments ) |
|
41 | 41 | { |
42 | - return $this->setProperty($method, Arr::get($arguments, 0)); |
|
42 | + return $this->setProperty( $method, Arr::get( $arguments, 0 ) ); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
46 | 46 | * @param string $type |
47 | 47 | */ |
48 | - public function __construct($type = null) |
|
48 | + public function __construct( $type = null ) |
|
49 | 49 | { |
50 | - $this->type = !is_string($type) |
|
51 | - ? (new ReflectionClass($this))->getShortName() |
|
50 | + $this->type = !is_string( $type ) |
|
51 | + ? (new ReflectionClass( $this ))->getShortName() |
|
52 | 52 | : $type; |
53 | 53 | $this->setAllowedProperties(); |
54 | 54 | } |
@@ -64,10 +64,10 @@ discard block |
||
64 | 64 | /** |
65 | 65 | * @return static |
66 | 66 | */ |
67 | - public function addProperties(array $properties) |
|
67 | + public function addProperties( array $properties ) |
|
68 | 68 | { |
69 | - foreach ($properties as $property => $value) { |
|
70 | - $this->setProperty($property, $value); |
|
69 | + foreach( $properties as $property => $value ) { |
|
70 | + $this->setProperty( $property, $value ); |
|
71 | 71 | } |
72 | 72 | return $this; |
73 | 73 | } |
@@ -93,9 +93,9 @@ discard block |
||
93 | 93 | * @param mixed $default |
94 | 94 | * @return mixed |
95 | 95 | */ |
96 | - public function getProperty($property, $default = null) |
|
96 | + public function getProperty( $property, $default = null ) |
|
97 | 97 | { |
98 | - return Arr::get($this->properties, $property, $default); |
|
98 | + return Arr::get( $this->properties, $property, $default ); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -111,10 +111,10 @@ discard block |
||
111 | 111 | * @param mixed $callback |
112 | 112 | * @return static |
113 | 113 | */ |
114 | - public function doIf($condition, $callback) |
|
114 | + public function doIf( $condition, $callback ) |
|
115 | 115 | { |
116 | - if ($condition) { |
|
117 | - $callback($this); |
|
116 | + if( $condition ) { |
|
117 | + $callback( $this ); |
|
118 | 118 | } |
119 | 119 | return $this; |
120 | 120 | } |
@@ -131,18 +131,18 @@ discard block |
||
131 | 131 | * @param mixed $offset |
132 | 132 | * @return bool |
133 | 133 | */ |
134 | - public function offsetExists($offset) |
|
134 | + public function offsetExists( $offset ) |
|
135 | 135 | { |
136 | - return array_key_exists($offset, $this->properties); |
|
136 | + return array_key_exists( $offset, $this->properties ); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | /** |
140 | 140 | * @param string $offset |
141 | 141 | * @return mixed |
142 | 142 | */ |
143 | - public function offsetGet($offset) |
|
143 | + public function offsetGet( $offset ) |
|
144 | 144 | { |
145 | - return $this->getProperty($offset); |
|
145 | + return $this->getProperty( $offset ); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | /** |
@@ -150,16 +150,16 @@ discard block |
||
150 | 150 | * @param mixed $value |
151 | 151 | * @return void |
152 | 152 | */ |
153 | - public function offsetSet($offset, $value) |
|
153 | + public function offsetSet( $offset, $value ) |
|
154 | 154 | { |
155 | - $this->setProperty($offset, $value); |
|
155 | + $this->setProperty( $offset, $value ); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | /** |
159 | 159 | * @param string $offset |
160 | 160 | * @return void |
161 | 161 | */ |
162 | - public function offsetUnset($offset) |
|
162 | + public function offsetUnset( $offset ) |
|
163 | 163 | { |
164 | 164 | unset($this->properties[$offset]); |
165 | 165 | } |
@@ -169,11 +169,11 @@ discard block |
||
169 | 169 | * @param mixed $value |
170 | 170 | * @return static |
171 | 171 | */ |
172 | - public function setProperty($property, $value) |
|
172 | + public function setProperty( $property, $value ) |
|
173 | 173 | { |
174 | - if (!in_array($property, $this->allowed) |
|
175 | - && 'UnknownType' != (new ReflectionClass($this))->getShortName()) { |
|
176 | - glsr_log()->warning($this->getType().' does not allow the "'.$property.'" property'); |
|
174 | + if( !in_array( $property, $this->allowed ) |
|
175 | + && 'UnknownType' != (new ReflectionClass( $this ))->getShortName() ) { |
|
176 | + glsr_log()->warning( $this->getType().' does not allow the "'.$property.'" property' ); |
|
177 | 177 | return $this; |
178 | 178 | } |
179 | 179 | $this->properties[$property] = $value; |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | return [ |
189 | 189 | '@context' => $this->getContext(), |
190 | 190 | '@type' => $this->getType(), |
191 | - ] + $this->serializeProperty($this->getProperties()); |
|
191 | + ] + $this->serializeProperty( $this->getProperties() ); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
@@ -196,8 +196,8 @@ discard block |
||
196 | 196 | */ |
197 | 197 | public function toScript() |
198 | 198 | { |
199 | - return sprintf('<script type="application/ld+json">%s</script>', |
|
200 | - json_encode($this->toArray(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) |
|
199 | + return sprintf( '<script type="application/ld+json">%s</script>', |
|
200 | + json_encode( $this->toArray(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES ) |
|
201 | 201 | ); |
202 | 202 | } |
203 | 203 | |
@@ -205,20 +205,20 @@ discard block |
||
205 | 205 | * @param array|null $parents |
206 | 206 | * @return array |
207 | 207 | */ |
208 | - protected function getParents($parents = null) |
|
208 | + protected function getParents( $parents = null ) |
|
209 | 209 | { |
210 | - if (!isset($parents)) { |
|
210 | + if( !isset($parents) ) { |
|
211 | 211 | $parents = $this->parents; |
212 | 212 | } |
213 | 213 | $newParents = $parents; |
214 | - foreach ($parents as $parent) { |
|
215 | - $parentClass = Helper::buildClassName($parent, __NAMESPACE__); |
|
216 | - if (!class_exists($parentClass)) { |
|
214 | + foreach( $parents as $parent ) { |
|
215 | + $parentClass = Helper::buildClassName( $parent, __NAMESPACE__ ); |
|
216 | + if( !class_exists( $parentClass ) ) { |
|
217 | 217 | continue; |
218 | 218 | } |
219 | - $newParents = array_merge($newParents, $this->getParents((new $parentClass())->parents)); |
|
219 | + $newParents = array_merge( $newParents, $this->getParents( (new $parentClass())->parents ) ); |
|
220 | 220 | } |
221 | - return array_values(array_unique($newParents)); |
|
221 | + return array_values( array_unique( $newParents ) ); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | /** |
@@ -227,12 +227,12 @@ discard block |
||
227 | 227 | protected function setAllowedProperties() |
228 | 228 | { |
229 | 229 | $parents = $this->getParents(); |
230 | - foreach ($parents as $parent) { |
|
231 | - $parentClass = Helper::buildClassName($parent, __NAMESPACE__); |
|
232 | - if (!class_exists($parentClass)) { |
|
230 | + foreach( $parents as $parent ) { |
|
231 | + $parentClass = Helper::buildClassName( $parent, __NAMESPACE__ ); |
|
232 | + if( !class_exists( $parentClass ) ) { |
|
233 | 233 | continue; |
234 | 234 | } |
235 | - $this->allowed = array_values(array_unique(array_merge((new $parentClass())->allowed, $this->allowed))); |
|
235 | + $this->allowed = array_values( array_unique( array_merge( (new $parentClass())->allowed, $this->allowed ) ) ); |
|
236 | 236 | } |
237 | 237 | } |
238 | 238 | |
@@ -240,19 +240,19 @@ discard block |
||
240 | 240 | * @param mixed $property |
241 | 241 | * @return array|string |
242 | 242 | */ |
243 | - protected function serializeProperty($property) |
|
243 | + protected function serializeProperty( $property ) |
|
244 | 244 | { |
245 | - if (is_array($property)) { |
|
246 | - return array_map([$this, 'serializeProperty'], $property); |
|
245 | + if( is_array( $property ) ) { |
|
246 | + return array_map( [$this, 'serializeProperty'], $property ); |
|
247 | 247 | } |
248 | - if ($property instanceof Type) { |
|
248 | + if( $property instanceof Type ) { |
|
249 | 249 | $property = $property->toArray(); |
250 | 250 | unset($property['@context']); |
251 | 251 | } |
252 | - if ($property instanceof DateTimeInterface) { |
|
253 | - $property = $property->format(DateTime::ATOM); |
|
252 | + if( $property instanceof DateTimeInterface ) { |
|
253 | + $property = $property->format( DateTime::ATOM ); |
|
254 | 254 | } |
255 | - if (is_object($property)) { |
|
255 | + if( is_object( $property ) ) { |
|
256 | 256 | throw new InvalidProperty(); |
257 | 257 | } |
258 | 258 | return $property; |
@@ -8,135 +8,135 @@ |
||
8 | 8 | |
9 | 9 | class ReviewsHtml extends ArrayObject |
10 | 10 | { |
11 | - /** |
|
12 | - * @var array |
|
13 | - */ |
|
14 | - public $args; |
|
11 | + /** |
|
12 | + * @var array |
|
13 | + */ |
|
14 | + public $args; |
|
15 | 15 | |
16 | - /** |
|
17 | - * @var int |
|
18 | - */ |
|
19 | - public $max_num_pages; |
|
16 | + /** |
|
17 | + * @var int |
|
18 | + */ |
|
19 | + public $max_num_pages; |
|
20 | 20 | |
21 | - /** |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - public $pagination; |
|
21 | + /** |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + public $pagination; |
|
25 | 25 | |
26 | - /** |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - public $reviews; |
|
26 | + /** |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + public $reviews; |
|
30 | 30 | |
31 | - public function __construct(array $reviews, $maxPageCount, array $args) |
|
32 | - { |
|
33 | - $this->args = $args; |
|
34 | - $this->max_num_pages = $maxPageCount; |
|
35 | - $this->reviews = $reviews; |
|
36 | - $this->pagination = $this->buildPagination(); |
|
37 | - parent::__construct($reviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS); |
|
38 | - } |
|
31 | + public function __construct(array $reviews, $maxPageCount, array $args) |
|
32 | + { |
|
33 | + $this->args = $args; |
|
34 | + $this->max_num_pages = $maxPageCount; |
|
35 | + $this->reviews = $reviews; |
|
36 | + $this->pagination = $this->buildPagination(); |
|
37 | + parent::__construct($reviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS); |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * @return string |
|
42 | - */ |
|
43 | - public function __toString() |
|
44 | - { |
|
45 | - return glsr(Template::class)->build('templates/reviews', [ |
|
46 | - 'args' => $this->args, |
|
47 | - 'context' => [ |
|
48 | - 'assigned_to' => $this->args['assigned_to'], |
|
49 | - 'category' => $this->args['category'], |
|
50 | - 'class' => $this->getClass(), |
|
51 | - 'id' => $this->args['id'], |
|
52 | - 'pagination' => $this->getPagination(), |
|
53 | - 'reviews' => $this->getReviews(), |
|
54 | - ], |
|
55 | - ]); |
|
56 | - } |
|
40 | + /** |
|
41 | + * @return string |
|
42 | + */ |
|
43 | + public function __toString() |
|
44 | + { |
|
45 | + return glsr(Template::class)->build('templates/reviews', [ |
|
46 | + 'args' => $this->args, |
|
47 | + 'context' => [ |
|
48 | + 'assigned_to' => $this->args['assigned_to'], |
|
49 | + 'category' => $this->args['category'], |
|
50 | + 'class' => $this->getClass(), |
|
51 | + 'id' => $this->args['id'], |
|
52 | + 'pagination' => $this->getPagination(), |
|
53 | + 'reviews' => $this->getReviews(), |
|
54 | + ], |
|
55 | + ]); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * @return string |
|
60 | - */ |
|
61 | - public function getPagination() |
|
62 | - { |
|
63 | - return wp_validate_boolean($this->args['pagination']) |
|
64 | - ? $this->pagination |
|
65 | - : ''; |
|
66 | - } |
|
58 | + /** |
|
59 | + * @return string |
|
60 | + */ |
|
61 | + public function getPagination() |
|
62 | + { |
|
63 | + return wp_validate_boolean($this->args['pagination']) |
|
64 | + ? $this->pagination |
|
65 | + : ''; |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @return string |
|
70 | - */ |
|
71 | - public function getReviews() |
|
72 | - { |
|
73 | - $html = empty($this->reviews) |
|
74 | - ? $this->getReviewsFallback() |
|
75 | - : implode(PHP_EOL, $this->reviews); |
|
76 | - $wrapper = '<div class="glsr-reviews">%s</div>'; |
|
77 | - $wrapper = apply_filters('site-reviews/reviews/reviews-wrapper', $wrapper); |
|
78 | - return sprintf($wrapper, $html); |
|
79 | - } |
|
68 | + /** |
|
69 | + * @return string |
|
70 | + */ |
|
71 | + public function getReviews() |
|
72 | + { |
|
73 | + $html = empty($this->reviews) |
|
74 | + ? $this->getReviewsFallback() |
|
75 | + : implode(PHP_EOL, $this->reviews); |
|
76 | + $wrapper = '<div class="glsr-reviews">%s</div>'; |
|
77 | + $wrapper = apply_filters('site-reviews/reviews/reviews-wrapper', $wrapper); |
|
78 | + return sprintf($wrapper, $html); |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * @param mixed $key |
|
83 | - * @return mixed |
|
84 | - */ |
|
85 | - public function offsetGet($key) |
|
86 | - { |
|
87 | - if ('navigation' == $key) { |
|
88 | - glsr()->deprecated[] = 'The $reviewsHtml->navigation property has been been deprecated. Please use the $reviewsHtml->pagination property instead.'; |
|
89 | - return $this->pagination; |
|
90 | - } |
|
91 | - if (property_exists($this, $key)) { |
|
92 | - return $this->$key; |
|
93 | - } |
|
94 | - return array_key_exists($key, $this->reviews) |
|
95 | - ? $this->reviews[$key] |
|
96 | - : null; |
|
97 | - } |
|
81 | + /** |
|
82 | + * @param mixed $key |
|
83 | + * @return mixed |
|
84 | + */ |
|
85 | + public function offsetGet($key) |
|
86 | + { |
|
87 | + if ('navigation' == $key) { |
|
88 | + glsr()->deprecated[] = 'The $reviewsHtml->navigation property has been been deprecated. Please use the $reviewsHtml->pagination property instead.'; |
|
89 | + return $this->pagination; |
|
90 | + } |
|
91 | + if (property_exists($this, $key)) { |
|
92 | + return $this->$key; |
|
93 | + } |
|
94 | + return array_key_exists($key, $this->reviews) |
|
95 | + ? $this->reviews[$key] |
|
96 | + : null; |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - protected function buildPagination() |
|
103 | - { |
|
104 | - $html = glsr(Partial::class)->build('pagination', [ |
|
105 | - 'baseUrl' => Arr::get($this->args, 'pagedUrl'), |
|
106 | - 'current' => Arr::get($this->args, 'paged'), |
|
107 | - 'total' => $this->max_num_pages, |
|
108 | - ]); |
|
109 | - $html.= sprintf('<glsr-pagination hidden data-atts=\'%s\'></glsr-pagination>', $this->args['json']); |
|
110 | - $wrapper = '<div class="glsr-pagination">%s</div>'; |
|
111 | - $wrapper = apply_filters('site-reviews/reviews/pagination-wrapper', $wrapper); |
|
112 | - return sprintf($wrapper, $html); |
|
113 | - } |
|
99 | + /** |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + protected function buildPagination() |
|
103 | + { |
|
104 | + $html = glsr(Partial::class)->build('pagination', [ |
|
105 | + 'baseUrl' => Arr::get($this->args, 'pagedUrl'), |
|
106 | + 'current' => Arr::get($this->args, 'paged'), |
|
107 | + 'total' => $this->max_num_pages, |
|
108 | + ]); |
|
109 | + $html.= sprintf('<glsr-pagination hidden data-atts=\'%s\'></glsr-pagination>', $this->args['json']); |
|
110 | + $wrapper = '<div class="glsr-pagination">%s</div>'; |
|
111 | + $wrapper = apply_filters('site-reviews/reviews/pagination-wrapper', $wrapper); |
|
112 | + return sprintf($wrapper, $html); |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * @return string |
|
117 | - */ |
|
118 | - protected function getClass() |
|
119 | - { |
|
120 | - $defaults = [ |
|
121 | - 'glsr-default', |
|
122 | - ]; |
|
123 | - if ('ajax' == $this->args['pagination']) { |
|
124 | - $defaults[] = 'glsr-ajax-pagination'; |
|
125 | - } |
|
126 | - $classes = explode(' ', $this->args['class']); |
|
127 | - $classes = array_unique(array_merge($defaults, array_filter($classes))); |
|
128 | - return implode(' ', $classes); |
|
129 | - } |
|
115 | + /** |
|
116 | + * @return string |
|
117 | + */ |
|
118 | + protected function getClass() |
|
119 | + { |
|
120 | + $defaults = [ |
|
121 | + 'glsr-default', |
|
122 | + ]; |
|
123 | + if ('ajax' == $this->args['pagination']) { |
|
124 | + $defaults[] = 'glsr-ajax-pagination'; |
|
125 | + } |
|
126 | + $classes = explode(' ', $this->args['class']); |
|
127 | + $classes = array_unique(array_merge($defaults, array_filter($classes))); |
|
128 | + return implode(' ', $classes); |
|
129 | + } |
|
130 | 130 | |
131 | - /** |
|
132 | - * @return string |
|
133 | - */ |
|
134 | - protected function getReviewsFallback() |
|
135 | - { |
|
136 | - if (empty($this->args['fallback']) && glsr(OptionManager::class)->getBool('settings.reviews.fallback')) { |
|
137 | - $this->args['fallback'] = __('There are no reviews yet. Be the first one to write one.', 'site-reviews'); |
|
138 | - } |
|
139 | - $fallback = '<p class="glsr-no-margins">'.$this->args['fallback'].'</p>'; |
|
140 | - return apply_filters('site-reviews/reviews/fallback', $fallback, $this->args); |
|
141 | - } |
|
131 | + /** |
|
132 | + * @return string |
|
133 | + */ |
|
134 | + protected function getReviewsFallback() |
|
135 | + { |
|
136 | + if (empty($this->args['fallback']) && glsr(OptionManager::class)->getBool('settings.reviews.fallback')) { |
|
137 | + $this->args['fallback'] = __('There are no reviews yet. Be the first one to write one.', 'site-reviews'); |
|
138 | + } |
|
139 | + $fallback = '<p class="glsr-no-margins">'.$this->args['fallback'].'</p>'; |
|
140 | + return apply_filters('site-reviews/reviews/fallback', $fallback, $this->args); |
|
141 | + } |
|
142 | 142 | } |
@@ -28,13 +28,13 @@ discard block |
||
28 | 28 | */ |
29 | 29 | public $reviews; |
30 | 30 | |
31 | - public function __construct(array $reviews, $maxPageCount, array $args) |
|
31 | + public function __construct( array $reviews, $maxPageCount, array $args ) |
|
32 | 32 | { |
33 | 33 | $this->args = $args; |
34 | 34 | $this->max_num_pages = $maxPageCount; |
35 | 35 | $this->reviews = $reviews; |
36 | 36 | $this->pagination = $this->buildPagination(); |
37 | - parent::__construct($reviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS); |
|
37 | + parent::__construct( $reviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS ); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function __toString() |
44 | 44 | { |
45 | - return glsr(Template::class)->build('templates/reviews', [ |
|
45 | + return glsr( Template::class )->build( 'templates/reviews', [ |
|
46 | 46 | 'args' => $this->args, |
47 | 47 | 'context' => [ |
48 | 48 | 'assigned_to' => $this->args['assigned_to'], |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | 'pagination' => $this->getPagination(), |
53 | 53 | 'reviews' => $this->getReviews(), |
54 | 54 | ], |
55 | - ]); |
|
55 | + ] ); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | */ |
61 | 61 | public function getPagination() |
62 | 62 | { |
63 | - return wp_validate_boolean($this->args['pagination']) |
|
63 | + return wp_validate_boolean( $this->args['pagination'] ) |
|
64 | 64 | ? $this->pagination |
65 | 65 | : ''; |
66 | 66 | } |
@@ -72,26 +72,26 @@ discard block |
||
72 | 72 | { |
73 | 73 | $html = empty($this->reviews) |
74 | 74 | ? $this->getReviewsFallback() |
75 | - : implode(PHP_EOL, $this->reviews); |
|
75 | + : implode( PHP_EOL, $this->reviews ); |
|
76 | 76 | $wrapper = '<div class="glsr-reviews">%s</div>'; |
77 | - $wrapper = apply_filters('site-reviews/reviews/reviews-wrapper', $wrapper); |
|
78 | - return sprintf($wrapper, $html); |
|
77 | + $wrapper = apply_filters( 'site-reviews/reviews/reviews-wrapper', $wrapper ); |
|
78 | + return sprintf( $wrapper, $html ); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
82 | 82 | * @param mixed $key |
83 | 83 | * @return mixed |
84 | 84 | */ |
85 | - public function offsetGet($key) |
|
85 | + public function offsetGet( $key ) |
|
86 | 86 | { |
87 | - if ('navigation' == $key) { |
|
87 | + if( 'navigation' == $key ) { |
|
88 | 88 | glsr()->deprecated[] = 'The $reviewsHtml->navigation property has been been deprecated. Please use the $reviewsHtml->pagination property instead.'; |
89 | 89 | return $this->pagination; |
90 | 90 | } |
91 | - if (property_exists($this, $key)) { |
|
91 | + if( property_exists( $this, $key ) ) { |
|
92 | 92 | return $this->$key; |
93 | 93 | } |
94 | - return array_key_exists($key, $this->reviews) |
|
94 | + return array_key_exists( $key, $this->reviews ) |
|
95 | 95 | ? $this->reviews[$key] |
96 | 96 | : null; |
97 | 97 | } |
@@ -101,15 +101,15 @@ discard block |
||
101 | 101 | */ |
102 | 102 | protected function buildPagination() |
103 | 103 | { |
104 | - $html = glsr(Partial::class)->build('pagination', [ |
|
105 | - 'baseUrl' => Arr::get($this->args, 'pagedUrl'), |
|
106 | - 'current' => Arr::get($this->args, 'paged'), |
|
104 | + $html = glsr( Partial::class )->build( 'pagination', [ |
|
105 | + 'baseUrl' => Arr::get( $this->args, 'pagedUrl' ), |
|
106 | + 'current' => Arr::get( $this->args, 'paged' ), |
|
107 | 107 | 'total' => $this->max_num_pages, |
108 | - ]); |
|
109 | - $html.= sprintf('<glsr-pagination hidden data-atts=\'%s\'></glsr-pagination>', $this->args['json']); |
|
108 | + ] ); |
|
109 | + $html .= sprintf( '<glsr-pagination hidden data-atts=\'%s\'></glsr-pagination>', $this->args['json'] ); |
|
110 | 110 | $wrapper = '<div class="glsr-pagination">%s</div>'; |
111 | - $wrapper = apply_filters('site-reviews/reviews/pagination-wrapper', $wrapper); |
|
112 | - return sprintf($wrapper, $html); |
|
111 | + $wrapper = apply_filters( 'site-reviews/reviews/pagination-wrapper', $wrapper ); |
|
112 | + return sprintf( $wrapper, $html ); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
@@ -120,12 +120,12 @@ discard block |
||
120 | 120 | $defaults = [ |
121 | 121 | 'glsr-default', |
122 | 122 | ]; |
123 | - if ('ajax' == $this->args['pagination']) { |
|
123 | + if( 'ajax' == $this->args['pagination'] ) { |
|
124 | 124 | $defaults[] = 'glsr-ajax-pagination'; |
125 | 125 | } |
126 | - $classes = explode(' ', $this->args['class']); |
|
127 | - $classes = array_unique(array_merge($defaults, array_filter($classes))); |
|
128 | - return implode(' ', $classes); |
|
126 | + $classes = explode( ' ', $this->args['class'] ); |
|
127 | + $classes = array_unique( array_merge( $defaults, array_filter( $classes ) ) ); |
|
128 | + return implode( ' ', $classes ); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
@@ -133,10 +133,10 @@ discard block |
||
133 | 133 | */ |
134 | 134 | protected function getReviewsFallback() |
135 | 135 | { |
136 | - if (empty($this->args['fallback']) && glsr(OptionManager::class)->getBool('settings.reviews.fallback')) { |
|
137 | - $this->args['fallback'] = __('There are no reviews yet. Be the first one to write one.', 'site-reviews'); |
|
136 | + if( empty($this->args['fallback']) && glsr( OptionManager::class )->getBool( 'settings.reviews.fallback' ) ) { |
|
137 | + $this->args['fallback'] = __( 'There are no reviews yet. Be the first one to write one.', 'site-reviews' ); |
|
138 | 138 | } |
139 | 139 | $fallback = '<p class="glsr-no-margins">'.$this->args['fallback'].'</p>'; |
140 | - return apply_filters('site-reviews/reviews/fallback', $fallback, $this->args); |
|
140 | + return apply_filters( 'site-reviews/reviews/fallback', $fallback, $this->args ); |
|
141 | 141 | } |
142 | 142 | } |
@@ -7,73 +7,73 @@ |
||
7 | 7 | |
8 | 8 | abstract class Field |
9 | 9 | { |
10 | - /** |
|
11 | - * @var Builder |
|
12 | - */ |
|
13 | - protected $builder; |
|
10 | + /** |
|
11 | + * @var Builder |
|
12 | + */ |
|
13 | + protected $builder; |
|
14 | 14 | |
15 | - public function __construct(Builder $builder) |
|
16 | - { |
|
17 | - $this->builder = $builder; |
|
18 | - } |
|
15 | + public function __construct(Builder $builder) |
|
16 | + { |
|
17 | + $this->builder = $builder; |
|
18 | + } |
|
19 | 19 | |
20 | - /** |
|
21 | - * @return string|void |
|
22 | - */ |
|
23 | - public function build() |
|
24 | - { |
|
25 | - glsr_log()->error('Build method is not implemented for '.get_class($this)); |
|
26 | - } |
|
20 | + /** |
|
21 | + * @return string|void |
|
22 | + */ |
|
23 | + public function build() |
|
24 | + { |
|
25 | + glsr_log()->error('Build method is not implemented for '.get_class($this)); |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * @return array |
|
30 | - */ |
|
31 | - public static function defaults() |
|
32 | - { |
|
33 | - return []; |
|
34 | - } |
|
28 | + /** |
|
29 | + * @return array |
|
30 | + */ |
|
31 | + public static function defaults() |
|
32 | + { |
|
33 | + return []; |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * @return array |
|
38 | - */ |
|
39 | - public static function merge(array $args) |
|
40 | - { |
|
41 | - $merged = array_merge( |
|
42 | - wp_parse_args($args, static::defaults()), |
|
43 | - static::required() |
|
44 | - ); |
|
45 | - $merged['class'] = implode(' ', static::mergedAttribute('class', ' ', $args)); |
|
46 | - $merged['style'] = implode(';', static::mergedAttribute('style', ';', $args)); |
|
47 | - return $merged; |
|
48 | - } |
|
36 | + /** |
|
37 | + * @return array |
|
38 | + */ |
|
39 | + public static function merge(array $args) |
|
40 | + { |
|
41 | + $merged = array_merge( |
|
42 | + wp_parse_args($args, static::defaults()), |
|
43 | + static::required() |
|
44 | + ); |
|
45 | + $merged['class'] = implode(' ', static::mergedAttribute('class', ' ', $args)); |
|
46 | + $merged['style'] = implode(';', static::mergedAttribute('style', ';', $args)); |
|
47 | + return $merged; |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @param string $delimiter |
|
52 | - * @param string $key |
|
53 | - * @return array |
|
54 | - */ |
|
55 | - public static function mergedAttribute($key, $delimiter, array $args) |
|
56 | - { |
|
57 | - return array_filter(array_merge( |
|
58 | - explode($delimiter, Arr::get($args, $key)), |
|
59 | - explode($delimiter, Arr::get(static::defaults(), $key)), |
|
60 | - explode($delimiter, Arr::get(static::required(), $key)) |
|
61 | - )); |
|
62 | - } |
|
50 | + /** |
|
51 | + * @param string $delimiter |
|
52 | + * @param string $key |
|
53 | + * @return array |
|
54 | + */ |
|
55 | + public static function mergedAttribute($key, $delimiter, array $args) |
|
56 | + { |
|
57 | + return array_filter(array_merge( |
|
58 | + explode($delimiter, Arr::get($args, $key)), |
|
59 | + explode($delimiter, Arr::get(static::defaults(), $key)), |
|
60 | + explode($delimiter, Arr::get(static::required(), $key)) |
|
61 | + )); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @return array |
|
66 | - */ |
|
67 | - public static function required() |
|
68 | - { |
|
69 | - return []; |
|
70 | - } |
|
64 | + /** |
|
65 | + * @return array |
|
66 | + */ |
|
67 | + public static function required() |
|
68 | + { |
|
69 | + return []; |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * @return void |
|
74 | - */ |
|
75 | - protected function mergeFieldArgs() |
|
76 | - { |
|
77 | - $this->builder->args = static::merge($this->builder->args); |
|
78 | - } |
|
72 | + /** |
|
73 | + * @return void |
|
74 | + */ |
|
75 | + protected function mergeFieldArgs() |
|
76 | + { |
|
77 | + $this->builder->args = static::merge($this->builder->args); |
|
78 | + } |
|
79 | 79 | } |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | */ |
13 | 13 | protected $builder; |
14 | 14 | |
15 | - public function __construct(Builder $builder) |
|
15 | + public function __construct( Builder $builder ) |
|
16 | 16 | { |
17 | 17 | $this->builder = $builder; |
18 | 18 | } |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | */ |
23 | 23 | public function build() |
24 | 24 | { |
25 | - glsr_log()->error('Build method is not implemented for '.get_class($this)); |
|
25 | + glsr_log()->error( 'Build method is not implemented for '.get_class( $this ) ); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | /** |
@@ -36,14 +36,14 @@ discard block |
||
36 | 36 | /** |
37 | 37 | * @return array |
38 | 38 | */ |
39 | - public static function merge(array $args) |
|
39 | + public static function merge( array $args ) |
|
40 | 40 | { |
41 | 41 | $merged = array_merge( |
42 | - wp_parse_args($args, static::defaults()), |
|
42 | + wp_parse_args( $args, static::defaults() ), |
|
43 | 43 | static::required() |
44 | 44 | ); |
45 | - $merged['class'] = implode(' ', static::mergedAttribute('class', ' ', $args)); |
|
46 | - $merged['style'] = implode(';', static::mergedAttribute('style', ';', $args)); |
|
45 | + $merged['class'] = implode( ' ', static::mergedAttribute( 'class', ' ', $args ) ); |
|
46 | + $merged['style'] = implode( ';', static::mergedAttribute( 'style', ';', $args ) ); |
|
47 | 47 | return $merged; |
48 | 48 | } |
49 | 49 | |
@@ -52,13 +52,13 @@ discard block |
||
52 | 52 | * @param string $key |
53 | 53 | * @return array |
54 | 54 | */ |
55 | - public static function mergedAttribute($key, $delimiter, array $args) |
|
55 | + public static function mergedAttribute( $key, $delimiter, array $args ) |
|
56 | 56 | { |
57 | - return array_filter(array_merge( |
|
58 | - explode($delimiter, Arr::get($args, $key)), |
|
59 | - explode($delimiter, Arr::get(static::defaults(), $key)), |
|
60 | - explode($delimiter, Arr::get(static::required(), $key)) |
|
61 | - )); |
|
57 | + return array_filter( array_merge( |
|
58 | + explode( $delimiter, Arr::get( $args, $key ) ), |
|
59 | + explode( $delimiter, Arr::get( static::defaults(), $key ) ), |
|
60 | + explode( $delimiter, Arr::get( static::required(), $key ) ) |
|
61 | + ) ); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
@@ -74,6 +74,6 @@ discard block |
||
74 | 74 | */ |
75 | 75 | protected function mergeFieldArgs() |
76 | 76 | { |
77 | - $this->builder->args = static::merge($this->builder->args); |
|
77 | + $this->builder->args = static::merge( $this->builder->args ); |
|
78 | 78 | } |
79 | 79 | } |
@@ -7,78 +7,78 @@ |
||
7 | 7 | |
8 | 8 | class Template |
9 | 9 | { |
10 | - /** |
|
11 | - * @param string $templatePath |
|
12 | - * @return void|string |
|
13 | - */ |
|
14 | - public function build($templatePath, array $data = []) |
|
15 | - { |
|
16 | - $data = $this->normalize($data); |
|
17 | - ob_start(); |
|
18 | - glsr()->render($templatePath, $data); |
|
19 | - $template = ob_get_clean(); |
|
20 | - $path = Str::removePrefix('templates/', $templatePath); |
|
21 | - $template = apply_filters('site-reviews/build/template/'.$path, $template, $data); |
|
22 | - $template = $this->interpolate($template, $data, $path); |
|
23 | - $template = apply_filters('site-reviews/rendered/template', $template, $templatePath, $data); |
|
24 | - $template = apply_filters('site-reviews/rendered/template/'.$path, $template, $data); |
|
25 | - return $template; |
|
26 | - } |
|
10 | + /** |
|
11 | + * @param string $templatePath |
|
12 | + * @return void|string |
|
13 | + */ |
|
14 | + public function build($templatePath, array $data = []) |
|
15 | + { |
|
16 | + $data = $this->normalize($data); |
|
17 | + ob_start(); |
|
18 | + glsr()->render($templatePath, $data); |
|
19 | + $template = ob_get_clean(); |
|
20 | + $path = Str::removePrefix('templates/', $templatePath); |
|
21 | + $template = apply_filters('site-reviews/build/template/'.$path, $template, $data); |
|
22 | + $template = $this->interpolate($template, $data, $path); |
|
23 | + $template = apply_filters('site-reviews/rendered/template', $template, $templatePath, $data); |
|
24 | + $template = apply_filters('site-reviews/rendered/template/'.$path, $template, $data); |
|
25 | + return $template; |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * Interpolate context values into template placeholders. |
|
30 | - * @param string $template |
|
31 | - * @param string $templatePath |
|
32 | - * @return string |
|
33 | - */ |
|
34 | - public function interpolate($template, array $data = [], $templatePath) |
|
35 | - { |
|
36 | - $context = $this->normalizeContext(Arr::get($data, 'context', [])); |
|
37 | - $context = apply_filters('site-reviews/interpolate/'.$templatePath, $context, $template, $data); |
|
38 | - foreach ($context as $key => $value) { |
|
39 | - $template = strtr( |
|
40 | - $template, |
|
41 | - array_fill_keys(['{'.$key.'}', '{{ '.$key.' }}'], $value) |
|
42 | - ); |
|
43 | - } |
|
44 | - return trim($template); |
|
45 | - } |
|
28 | + /** |
|
29 | + * Interpolate context values into template placeholders. |
|
30 | + * @param string $template |
|
31 | + * @param string $templatePath |
|
32 | + * @return string |
|
33 | + */ |
|
34 | + public function interpolate($template, array $data = [], $templatePath) |
|
35 | + { |
|
36 | + $context = $this->normalizeContext(Arr::get($data, 'context', [])); |
|
37 | + $context = apply_filters('site-reviews/interpolate/'.$templatePath, $context, $template, $data); |
|
38 | + foreach ($context as $key => $value) { |
|
39 | + $template = strtr( |
|
40 | + $template, |
|
41 | + array_fill_keys(['{'.$key.'}', '{{ '.$key.' }}'], $value) |
|
42 | + ); |
|
43 | + } |
|
44 | + return trim($template); |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * @param string $templatePath |
|
49 | - * @return void|string |
|
50 | - */ |
|
51 | - public function render($templatePath, array $data = []) |
|
52 | - { |
|
53 | - echo $this->build($templatePath, $data); |
|
54 | - } |
|
47 | + /** |
|
48 | + * @param string $templatePath |
|
49 | + * @return void|string |
|
50 | + */ |
|
51 | + public function render($templatePath, array $data = []) |
|
52 | + { |
|
53 | + echo $this->build($templatePath, $data); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * @return array |
|
58 | - */ |
|
59 | - protected function normalize(array $data) |
|
60 | - { |
|
61 | - $arrayKeys = ['context', 'globals']; |
|
62 | - $data = wp_parse_args($data, array_fill_keys($arrayKeys, [])); |
|
63 | - foreach ($arrayKeys as $key) { |
|
64 | - if (is_array($data[$key])) { |
|
65 | - continue; |
|
66 | - } |
|
67 | - $data[$key] = []; |
|
68 | - } |
|
69 | - return $data; |
|
70 | - } |
|
56 | + /** |
|
57 | + * @return array |
|
58 | + */ |
|
59 | + protected function normalize(array $data) |
|
60 | + { |
|
61 | + $arrayKeys = ['context', 'globals']; |
|
62 | + $data = wp_parse_args($data, array_fill_keys($arrayKeys, [])); |
|
63 | + foreach ($arrayKeys as $key) { |
|
64 | + if (is_array($data[$key])) { |
|
65 | + continue; |
|
66 | + } |
|
67 | + $data[$key] = []; |
|
68 | + } |
|
69 | + return $data; |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * @return array |
|
74 | - */ |
|
75 | - protected function normalizeContext(array $context) |
|
76 | - { |
|
77 | - $context = array_filter($context, function ($value) { |
|
78 | - return !is_array($value) && !is_object($value); |
|
79 | - }); |
|
80 | - return array_map(function ($value) { |
|
81 | - return (string) $value; |
|
82 | - }, $context); |
|
83 | - } |
|
72 | + /** |
|
73 | + * @return array |
|
74 | + */ |
|
75 | + protected function normalizeContext(array $context) |
|
76 | + { |
|
77 | + $context = array_filter($context, function ($value) { |
|
78 | + return !is_array($value) && !is_object($value); |
|
79 | + }); |
|
80 | + return array_map(function ($value) { |
|
81 | + return (string) $value; |
|
82 | + }, $context); |
|
83 | + } |
|
84 | 84 | } |
@@ -11,17 +11,17 @@ discard block |
||
11 | 11 | * @param string $templatePath |
12 | 12 | * @return void|string |
13 | 13 | */ |
14 | - public function build($templatePath, array $data = []) |
|
14 | + public function build( $templatePath, array $data = [] ) |
|
15 | 15 | { |
16 | - $data = $this->normalize($data); |
|
16 | + $data = $this->normalize( $data ); |
|
17 | 17 | ob_start(); |
18 | - glsr()->render($templatePath, $data); |
|
18 | + glsr()->render( $templatePath, $data ); |
|
19 | 19 | $template = ob_get_clean(); |
20 | - $path = Str::removePrefix('templates/', $templatePath); |
|
21 | - $template = apply_filters('site-reviews/build/template/'.$path, $template, $data); |
|
22 | - $template = $this->interpolate($template, $data, $path); |
|
23 | - $template = apply_filters('site-reviews/rendered/template', $template, $templatePath, $data); |
|
24 | - $template = apply_filters('site-reviews/rendered/template/'.$path, $template, $data); |
|
20 | + $path = Str::removePrefix( 'templates/', $templatePath ); |
|
21 | + $template = apply_filters( 'site-reviews/build/template/'.$path, $template, $data ); |
|
22 | + $template = $this->interpolate( $template, $data, $path ); |
|
23 | + $template = apply_filters( 'site-reviews/rendered/template', $template, $templatePath, $data ); |
|
24 | + $template = apply_filters( 'site-reviews/rendered/template/'.$path, $template, $data ); |
|
25 | 25 | return $template; |
26 | 26 | } |
27 | 27 | |
@@ -31,37 +31,37 @@ discard block |
||
31 | 31 | * @param string $templatePath |
32 | 32 | * @return string |
33 | 33 | */ |
34 | - public function interpolate($template, array $data = [], $templatePath) |
|
34 | + public function interpolate( $template, array $data = [], $templatePath ) |
|
35 | 35 | { |
36 | - $context = $this->normalizeContext(Arr::get($data, 'context', [])); |
|
37 | - $context = apply_filters('site-reviews/interpolate/'.$templatePath, $context, $template, $data); |
|
38 | - foreach ($context as $key => $value) { |
|
36 | + $context = $this->normalizeContext( Arr::get( $data, 'context', [] ) ); |
|
37 | + $context = apply_filters( 'site-reviews/interpolate/'.$templatePath, $context, $template, $data ); |
|
38 | + foreach( $context as $key => $value ) { |
|
39 | 39 | $template = strtr( |
40 | 40 | $template, |
41 | - array_fill_keys(['{'.$key.'}', '{{ '.$key.' }}'], $value) |
|
41 | + array_fill_keys( ['{'.$key.'}', '{{ '.$key.' }}'], $value ) |
|
42 | 42 | ); |
43 | 43 | } |
44 | - return trim($template); |
|
44 | + return trim( $template ); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
48 | 48 | * @param string $templatePath |
49 | 49 | * @return void|string |
50 | 50 | */ |
51 | - public function render($templatePath, array $data = []) |
|
51 | + public function render( $templatePath, array $data = [] ) |
|
52 | 52 | { |
53 | - echo $this->build($templatePath, $data); |
|
53 | + echo $this->build( $templatePath, $data ); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | /** |
57 | 57 | * @return array |
58 | 58 | */ |
59 | - protected function normalize(array $data) |
|
59 | + protected function normalize( array $data ) |
|
60 | 60 | { |
61 | 61 | $arrayKeys = ['context', 'globals']; |
62 | - $data = wp_parse_args($data, array_fill_keys($arrayKeys, [])); |
|
63 | - foreach ($arrayKeys as $key) { |
|
64 | - if (is_array($data[$key])) { |
|
62 | + $data = wp_parse_args( $data, array_fill_keys( $arrayKeys, [] ) ); |
|
63 | + foreach( $arrayKeys as $key ) { |
|
64 | + if( is_array( $data[$key] ) ) { |
|
65 | 65 | continue; |
66 | 66 | } |
67 | 67 | $data[$key] = []; |
@@ -72,13 +72,13 @@ discard block |
||
72 | 72 | /** |
73 | 73 | * @return array |
74 | 74 | */ |
75 | - protected function normalizeContext(array $context) |
|
75 | + protected function normalizeContext( array $context ) |
|
76 | 76 | { |
77 | - $context = array_filter($context, function ($value) { |
|
78 | - return !is_array($value) && !is_object($value); |
|
77 | + $context = array_filter( $context, function( $value ) { |
|
78 | + return !is_array( $value ) && !is_object( $value ); |
|
79 | 79 | }); |
80 | - return array_map(function ($value) { |
|
81 | - return (string) $value; |
|
82 | - }, $context); |
|
80 | + return array_map( function( $value ) { |
|
81 | + return (string)$value; |
|
82 | + }, $context ); |
|
83 | 83 | } |
84 | 84 | } |
@@ -10,55 +10,55 @@ |
||
10 | 10 | |
11 | 11 | class Pagination implements PartialContract |
12 | 12 | { |
13 | - /** |
|
14 | - * @var array |
|
15 | - */ |
|
16 | - protected $args; |
|
13 | + /** |
|
14 | + * @var array |
|
15 | + */ |
|
16 | + protected $args; |
|
17 | 17 | |
18 | - /** |
|
19 | - * @return void|string |
|
20 | - */ |
|
21 | - public function build(array $args = []) |
|
22 | - { |
|
23 | - $this->args = $this->normalize($args); |
|
24 | - if ($this->args['total'] < 2) { |
|
25 | - return; |
|
26 | - } |
|
27 | - return glsr(Template::class)->build('templates/pagination', [ |
|
28 | - 'context' => [ |
|
29 | - 'links' => apply_filters('site-reviews/paginate_links', $this->buildLinks(), $this->args), |
|
30 | - 'loader' => '<div class="glsr-loader"></div>', |
|
31 | - 'screen_reader_text' => __('Site Reviews navigation', 'site-reviews'), |
|
32 | - ], |
|
33 | - ]); |
|
34 | - } |
|
18 | + /** |
|
19 | + * @return void|string |
|
20 | + */ |
|
21 | + public function build(array $args = []) |
|
22 | + { |
|
23 | + $this->args = $this->normalize($args); |
|
24 | + if ($this->args['total'] < 2) { |
|
25 | + return; |
|
26 | + } |
|
27 | + return glsr(Template::class)->build('templates/pagination', [ |
|
28 | + 'context' => [ |
|
29 | + 'links' => apply_filters('site-reviews/paginate_links', $this->buildLinks(), $this->args), |
|
30 | + 'loader' => '<div class="glsr-loader"></div>', |
|
31 | + 'screen_reader_text' => __('Site Reviews navigation', 'site-reviews'), |
|
32 | + ], |
|
33 | + ]); |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * @return string |
|
38 | - */ |
|
39 | - protected function buildLinks() |
|
40 | - { |
|
41 | - $args = glsr(Style::class)->paginationArgs($this->args); |
|
42 | - if (is_front_page()) { |
|
43 | - unset($args['format']); |
|
44 | - } |
|
45 | - if ('array' == $args['type']) { |
|
46 | - $args['type'] = 'plain'; |
|
47 | - } |
|
48 | - return paginate_links($args); |
|
49 | - } |
|
36 | + /** |
|
37 | + * @return string |
|
38 | + */ |
|
39 | + protected function buildLinks() |
|
40 | + { |
|
41 | + $args = glsr(Style::class)->paginationArgs($this->args); |
|
42 | + if (is_front_page()) { |
|
43 | + unset($args['format']); |
|
44 | + } |
|
45 | + if ('array' == $args['type']) { |
|
46 | + $args['type'] = 'plain'; |
|
47 | + } |
|
48 | + return paginate_links($args); |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @return array |
|
53 | - */ |
|
54 | - protected function normalize(array $args) |
|
55 | - { |
|
56 | - if ($baseUrl = Arr::get($args, 'baseUrl')) { |
|
57 | - $args['base'] = $baseUrl.'%_%'; |
|
58 | - } |
|
59 | - return wp_parse_args(array_filter($args), [ |
|
60 | - 'current' => glsr(QueryBuilder::class)->getPaged(), |
|
61 | - 'total' => 1, |
|
62 | - ]); |
|
63 | - } |
|
51 | + /** |
|
52 | + * @return array |
|
53 | + */ |
|
54 | + protected function normalize(array $args) |
|
55 | + { |
|
56 | + if ($baseUrl = Arr::get($args, 'baseUrl')) { |
|
57 | + $args['base'] = $baseUrl.'%_%'; |
|
58 | + } |
|
59 | + return wp_parse_args(array_filter($args), [ |
|
60 | + 'current' => glsr(QueryBuilder::class)->getPaged(), |
|
61 | + 'total' => 1, |
|
62 | + ]); |
|
63 | + } |
|
64 | 64 | } |
@@ -18,19 +18,19 @@ discard block |
||
18 | 18 | /** |
19 | 19 | * @return void|string |
20 | 20 | */ |
21 | - public function build(array $args = []) |
|
21 | + public function build( array $args = [] ) |
|
22 | 22 | { |
23 | - $this->args = $this->normalize($args); |
|
24 | - if ($this->args['total'] < 2) { |
|
23 | + $this->args = $this->normalize( $args ); |
|
24 | + if( $this->args['total'] < 2 ) { |
|
25 | 25 | return; |
26 | 26 | } |
27 | - return glsr(Template::class)->build('templates/pagination', [ |
|
27 | + return glsr( Template::class )->build( 'templates/pagination', [ |
|
28 | 28 | 'context' => [ |
29 | - 'links' => apply_filters('site-reviews/paginate_links', $this->buildLinks(), $this->args), |
|
29 | + 'links' => apply_filters( 'site-reviews/paginate_links', $this->buildLinks(), $this->args ), |
|
30 | 30 | 'loader' => '<div class="glsr-loader"></div>', |
31 | - 'screen_reader_text' => __('Site Reviews navigation', 'site-reviews'), |
|
31 | + 'screen_reader_text' => __( 'Site Reviews navigation', 'site-reviews' ), |
|
32 | 32 | ], |
33 | - ]); |
|
33 | + ] ); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
@@ -38,27 +38,27 @@ discard block |
||
38 | 38 | */ |
39 | 39 | protected function buildLinks() |
40 | 40 | { |
41 | - $args = glsr(Style::class)->paginationArgs($this->args); |
|
42 | - if (is_front_page()) { |
|
41 | + $args = glsr( Style::class )->paginationArgs( $this->args ); |
|
42 | + if( is_front_page() ) { |
|
43 | 43 | unset($args['format']); |
44 | 44 | } |
45 | - if ('array' == $args['type']) { |
|
45 | + if( 'array' == $args['type'] ) { |
|
46 | 46 | $args['type'] = 'plain'; |
47 | 47 | } |
48 | - return paginate_links($args); |
|
48 | + return paginate_links( $args ); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
52 | 52 | * @return array |
53 | 53 | */ |
54 | - protected function normalize(array $args) |
|
54 | + protected function normalize( array $args ) |
|
55 | 55 | { |
56 | - if ($baseUrl = Arr::get($args, 'baseUrl')) { |
|
56 | + if( $baseUrl = Arr::get( $args, 'baseUrl' ) ) { |
|
57 | 57 | $args['base'] = $baseUrl.'%_%'; |
58 | 58 | } |
59 | - return wp_parse_args(array_filter($args), [ |
|
60 | - 'current' => glsr(QueryBuilder::class)->getPaged(), |
|
59 | + return wp_parse_args( array_filter( $args ), [ |
|
60 | + 'current' => glsr( QueryBuilder::class )->getPaged(), |
|
61 | 61 | 'total' => 1, |
62 | - ]); |
|
62 | + ] ); |
|
63 | 63 | } |
64 | 64 | } |
@@ -8,160 +8,160 @@ |
||
8 | 8 | |
9 | 9 | class Upgrade_3_0_0 |
10 | 10 | { |
11 | - const MAPPED_SETTINGS = [ |
|
12 | - 'settings.general.notification' => 'settings.general.notifications', // array |
|
13 | - 'settings.general.notification_email' => 'settings.general.notification_email', |
|
14 | - 'settings.general.notification_message' => 'settings.general.notification_message', |
|
15 | - 'settings.general.require.approval' => 'settings.general.require.approval', |
|
16 | - 'settings.general.require.login' => 'settings.general.require.login', |
|
17 | - 'settings.general.require.login_register' => 'settings.general.require.login_register', |
|
18 | - 'settings.general.webhook_url' => 'settings.general.notification_slack', |
|
19 | - 'settings.reviews-form.akismet' => 'settings.submissions.akismet', |
|
20 | - 'settings.reviews-form.blacklist.action' => 'settings.submissions.blacklist.action', |
|
21 | - 'settings.reviews-form.blacklist.entries' => 'settings.submissions.blacklist.entries', |
|
22 | - 'settings.reviews-form.recaptcha.integration' => 'settings.submissions.recaptcha.integration', |
|
23 | - 'settings.reviews-form.recaptcha.key' => 'settings.submissions.recaptcha.key', |
|
24 | - 'settings.reviews-form.recaptcha.position' => 'settings.submissions.recaptcha.position', |
|
25 | - 'settings.reviews-form.recaptcha.secret' => 'settings.submissions.recaptcha.secret', |
|
26 | - 'settings.reviews-form.required' => 'settings.submissions.required', // array |
|
27 | - 'settings.reviews.assigned_links.enabled' => 'settings.reviews.assigned_links', |
|
28 | - 'settings.reviews.avatars.enabled' => 'settings.reviews.avatars', |
|
29 | - 'settings.reviews.date.custom' => 'settings.reviews.date.custom', |
|
30 | - 'settings.reviews.date.format' => 'settings.reviews.date.format', |
|
31 | - 'settings.reviews.excerpt.enabled' => 'settings.reviews.excerpts', |
|
32 | - 'settings.reviews.excerpt.length' => 'settings.reviews.excerpts_length', |
|
33 | - 'settings.reviews.schema.address' => 'settings.schema.address', |
|
34 | - 'settings.reviews.schema.description.custom' => 'settings.schema.description.custom', |
|
35 | - 'settings.reviews.schema.description.default' => 'settings.schema.description.default', |
|
36 | - 'settings.reviews.schema.highprice' => 'settings.schema.highprice', |
|
37 | - 'settings.reviews.schema.image.custom' => 'settings.schema.image.custom', |
|
38 | - 'settings.reviews.schema.image.default' => 'settings.schema.image.default', |
|
39 | - 'settings.reviews.schema.lowprice' => 'settings.schema.lowprice', |
|
40 | - 'settings.reviews.schema.name.custom' => 'settings.schema.name.custom', |
|
41 | - 'settings.reviews.schema.name.default' => 'settings.schema.name.default', |
|
42 | - 'settings.reviews.schema.pricecurrency' => 'settings.schema.pricecurrency', |
|
43 | - 'settings.reviews.schema.pricerange' => 'settings.schema.pricerange', |
|
44 | - 'settings.reviews.schema.telephone' => 'settings.schema.telephone', |
|
45 | - 'settings.reviews.schema.type.custom' => 'settings.schema.type.custom', |
|
46 | - 'settings.reviews.schema.type.default' => 'settings.schema.type.default', |
|
47 | - 'settings.reviews.schema.url.custom' => 'settings.schema.url.custom', |
|
48 | - 'settings.reviews.schema.url.default' => 'settings.schema.url.default', |
|
49 | - 'version' => 'version_upgraded_from', |
|
50 | - ]; |
|
11 | + const MAPPED_SETTINGS = [ |
|
12 | + 'settings.general.notification' => 'settings.general.notifications', // array |
|
13 | + 'settings.general.notification_email' => 'settings.general.notification_email', |
|
14 | + 'settings.general.notification_message' => 'settings.general.notification_message', |
|
15 | + 'settings.general.require.approval' => 'settings.general.require.approval', |
|
16 | + 'settings.general.require.login' => 'settings.general.require.login', |
|
17 | + 'settings.general.require.login_register' => 'settings.general.require.login_register', |
|
18 | + 'settings.general.webhook_url' => 'settings.general.notification_slack', |
|
19 | + 'settings.reviews-form.akismet' => 'settings.submissions.akismet', |
|
20 | + 'settings.reviews-form.blacklist.action' => 'settings.submissions.blacklist.action', |
|
21 | + 'settings.reviews-form.blacklist.entries' => 'settings.submissions.blacklist.entries', |
|
22 | + 'settings.reviews-form.recaptcha.integration' => 'settings.submissions.recaptcha.integration', |
|
23 | + 'settings.reviews-form.recaptcha.key' => 'settings.submissions.recaptcha.key', |
|
24 | + 'settings.reviews-form.recaptcha.position' => 'settings.submissions.recaptcha.position', |
|
25 | + 'settings.reviews-form.recaptcha.secret' => 'settings.submissions.recaptcha.secret', |
|
26 | + 'settings.reviews-form.required' => 'settings.submissions.required', // array |
|
27 | + 'settings.reviews.assigned_links.enabled' => 'settings.reviews.assigned_links', |
|
28 | + 'settings.reviews.avatars.enabled' => 'settings.reviews.avatars', |
|
29 | + 'settings.reviews.date.custom' => 'settings.reviews.date.custom', |
|
30 | + 'settings.reviews.date.format' => 'settings.reviews.date.format', |
|
31 | + 'settings.reviews.excerpt.enabled' => 'settings.reviews.excerpts', |
|
32 | + 'settings.reviews.excerpt.length' => 'settings.reviews.excerpts_length', |
|
33 | + 'settings.reviews.schema.address' => 'settings.schema.address', |
|
34 | + 'settings.reviews.schema.description.custom' => 'settings.schema.description.custom', |
|
35 | + 'settings.reviews.schema.description.default' => 'settings.schema.description.default', |
|
36 | + 'settings.reviews.schema.highprice' => 'settings.schema.highprice', |
|
37 | + 'settings.reviews.schema.image.custom' => 'settings.schema.image.custom', |
|
38 | + 'settings.reviews.schema.image.default' => 'settings.schema.image.default', |
|
39 | + 'settings.reviews.schema.lowprice' => 'settings.schema.lowprice', |
|
40 | + 'settings.reviews.schema.name.custom' => 'settings.schema.name.custom', |
|
41 | + 'settings.reviews.schema.name.default' => 'settings.schema.name.default', |
|
42 | + 'settings.reviews.schema.pricecurrency' => 'settings.schema.pricecurrency', |
|
43 | + 'settings.reviews.schema.pricerange' => 'settings.schema.pricerange', |
|
44 | + 'settings.reviews.schema.telephone' => 'settings.schema.telephone', |
|
45 | + 'settings.reviews.schema.type.custom' => 'settings.schema.type.custom', |
|
46 | + 'settings.reviews.schema.type.default' => 'settings.schema.type.default', |
|
47 | + 'settings.reviews.schema.url.custom' => 'settings.schema.url.custom', |
|
48 | + 'settings.reviews.schema.url.default' => 'settings.schema.url.default', |
|
49 | + 'version' => 'version_upgraded_from', |
|
50 | + ]; |
|
51 | 51 | |
52 | - /** |
|
53 | - * @var array |
|
54 | - */ |
|
55 | - protected $newSettings; |
|
52 | + /** |
|
53 | + * @var array |
|
54 | + */ |
|
55 | + protected $newSettings; |
|
56 | 56 | |
57 | - /** |
|
58 | - * @var array |
|
59 | - */ |
|
60 | - protected $oldSettings; |
|
57 | + /** |
|
58 | + * @var array |
|
59 | + */ |
|
60 | + protected $oldSettings; |
|
61 | 61 | |
62 | - public function __construct() |
|
63 | - { |
|
64 | - $this->migrateSettings(); |
|
65 | - } |
|
62 | + public function __construct() |
|
63 | + { |
|
64 | + $this->migrateSettings(); |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * @return void |
|
69 | - */ |
|
70 | - public function migrateSettings() |
|
71 | - { |
|
72 | - $this->newSettings = $this->getNewSettings(); |
|
73 | - $this->oldSettings = $this->getOldSettings(); |
|
74 | - if (empty($this->oldSettings)) { |
|
75 | - return; |
|
76 | - } |
|
77 | - foreach (static::MAPPED_SETTINGS as $old => $new) { |
|
78 | - if (empty($this->oldSettings[$old])) { |
|
79 | - continue; |
|
80 | - } |
|
81 | - $this->newSettings[$new] = $this->oldSettings[$old]; |
|
82 | - } |
|
83 | - $this->migrateNotificationSettings(); |
|
84 | - $this->migrateRecaptchaSettings(); |
|
85 | - $this->migrateRequiredSettings(); |
|
86 | - $oldSettings = Arr::convertDotNotationArray($this->oldSettings); |
|
87 | - $newSettings = Arr::convertDotNotationArray($this->newSettings); |
|
88 | - if (isset($oldSettings['settings']['strings']) && is_array($oldSettings['settings']['strings'])) { |
|
89 | - $newSettings['settings']['strings'] = $oldSettings['settings']['strings']; |
|
90 | - } |
|
91 | - glsr(OptionManager::class)->set($newSettings); |
|
92 | - } |
|
67 | + /** |
|
68 | + * @return void |
|
69 | + */ |
|
70 | + public function migrateSettings() |
|
71 | + { |
|
72 | + $this->newSettings = $this->getNewSettings(); |
|
73 | + $this->oldSettings = $this->getOldSettings(); |
|
74 | + if (empty($this->oldSettings)) { |
|
75 | + return; |
|
76 | + } |
|
77 | + foreach (static::MAPPED_SETTINGS as $old => $new) { |
|
78 | + if (empty($this->oldSettings[$old])) { |
|
79 | + continue; |
|
80 | + } |
|
81 | + $this->newSettings[$new] = $this->oldSettings[$old]; |
|
82 | + } |
|
83 | + $this->migrateNotificationSettings(); |
|
84 | + $this->migrateRecaptchaSettings(); |
|
85 | + $this->migrateRequiredSettings(); |
|
86 | + $oldSettings = Arr::convertDotNotationArray($this->oldSettings); |
|
87 | + $newSettings = Arr::convertDotNotationArray($this->newSettings); |
|
88 | + if (isset($oldSettings['settings']['strings']) && is_array($oldSettings['settings']['strings'])) { |
|
89 | + $newSettings['settings']['strings'] = $oldSettings['settings']['strings']; |
|
90 | + } |
|
91 | + glsr(OptionManager::class)->set($newSettings); |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * @return array |
|
96 | - */ |
|
97 | - protected function getNewSettings() |
|
98 | - { |
|
99 | - return wp_parse_args( |
|
100 | - Arr::flattenArray(glsr(OptionManager::class)->all()), |
|
101 | - glsr(DefaultsManager::class)->defaults() |
|
102 | - ); |
|
103 | - } |
|
94 | + /** |
|
95 | + * @return array |
|
96 | + */ |
|
97 | + protected function getNewSettings() |
|
98 | + { |
|
99 | + return wp_parse_args( |
|
100 | + Arr::flattenArray(glsr(OptionManager::class)->all()), |
|
101 | + glsr(DefaultsManager::class)->defaults() |
|
102 | + ); |
|
103 | + } |
|
104 | 104 | |
105 | - /** |
|
106 | - * @return array |
|
107 | - */ |
|
108 | - protected function getOldSettings() |
|
109 | - { |
|
110 | - $defaults = array_fill_keys(array_keys(static::MAPPED_SETTINGS), ''); |
|
111 | - $settings = Arr::flattenArray((array) get_option('geminilabs_site_reviews-v2', [])); |
|
112 | - if (!empty($settings)) { |
|
113 | - $settings = wp_parse_args($settings, $defaults); |
|
114 | - } |
|
115 | - return $settings; |
|
116 | - } |
|
105 | + /** |
|
106 | + * @return array |
|
107 | + */ |
|
108 | + protected function getOldSettings() |
|
109 | + { |
|
110 | + $defaults = array_fill_keys(array_keys(static::MAPPED_SETTINGS), ''); |
|
111 | + $settings = Arr::flattenArray((array) get_option('geminilabs_site_reviews-v2', [])); |
|
112 | + if (!empty($settings)) { |
|
113 | + $settings = wp_parse_args($settings, $defaults); |
|
114 | + } |
|
115 | + return $settings; |
|
116 | + } |
|
117 | 117 | |
118 | - /** |
|
119 | - * @return void |
|
120 | - */ |
|
121 | - protected function migrateNotificationSettings() |
|
122 | - { |
|
123 | - $notifications = [ |
|
124 | - 'custom' => 'custom', |
|
125 | - 'default' => 'admin', |
|
126 | - 'webhook' => 'slack', |
|
127 | - ]; |
|
128 | - $this->newSettings['settings.general.notifications'] = []; |
|
129 | - foreach ($notifications as $old => $new) { |
|
130 | - if ($this->oldSettings['settings.general.notification'] != $old) { |
|
131 | - continue; |
|
132 | - } |
|
133 | - $this->newSettings['settings.general.notifications'][] = $new; |
|
134 | - } |
|
135 | - } |
|
118 | + /** |
|
119 | + * @return void |
|
120 | + */ |
|
121 | + protected function migrateNotificationSettings() |
|
122 | + { |
|
123 | + $notifications = [ |
|
124 | + 'custom' => 'custom', |
|
125 | + 'default' => 'admin', |
|
126 | + 'webhook' => 'slack', |
|
127 | + ]; |
|
128 | + $this->newSettings['settings.general.notifications'] = []; |
|
129 | + foreach ($notifications as $old => $new) { |
|
130 | + if ($this->oldSettings['settings.general.notification'] != $old) { |
|
131 | + continue; |
|
132 | + } |
|
133 | + $this->newSettings['settings.general.notifications'][] = $new; |
|
134 | + } |
|
135 | + } |
|
136 | 136 | |
137 | - /** |
|
138 | - * @return void |
|
139 | - */ |
|
140 | - protected function migrateRecaptchaSettings() |
|
141 | - { |
|
142 | - $recaptcha = [ |
|
143 | - 'BadgePosition' => $this->oldSettings['settings.reviews-form.recaptcha.position'], |
|
144 | - 'SecretKey' => $this->oldSettings['settings.reviews-form.recaptcha.secret'], |
|
145 | - 'SiteKey' => $this->oldSettings['settings.reviews-form.recaptcha.key'], |
|
146 | - ]; |
|
147 | - if (in_array($this->oldSettings['settings.reviews-form.recaptcha.integration'], ['custom', 'invisible-recaptcha'])) { |
|
148 | - $this->newSettings['settings.submissions.recaptcha.integration'] = 'all'; |
|
149 | - } |
|
150 | - if ('invisible-recaptcha' == $this->oldSettings['settings.reviews-form.recaptcha.integration']) { |
|
151 | - $recaptcha = wp_parse_args((array) get_site_option('ic-settings', [], false), $recaptcha); |
|
152 | - } |
|
153 | - $this->newSettings['settings.submissions.recaptcha.key'] = $recaptcha['SiteKey']; |
|
154 | - $this->newSettings['settings.submissions.recaptcha.secret'] = $recaptcha['SecretKey']; |
|
155 | - $this->newSettings['settings.submissions.recaptcha.position'] = $recaptcha['BadgePosition']; |
|
156 | - } |
|
137 | + /** |
|
138 | + * @return void |
|
139 | + */ |
|
140 | + protected function migrateRecaptchaSettings() |
|
141 | + { |
|
142 | + $recaptcha = [ |
|
143 | + 'BadgePosition' => $this->oldSettings['settings.reviews-form.recaptcha.position'], |
|
144 | + 'SecretKey' => $this->oldSettings['settings.reviews-form.recaptcha.secret'], |
|
145 | + 'SiteKey' => $this->oldSettings['settings.reviews-form.recaptcha.key'], |
|
146 | + ]; |
|
147 | + if (in_array($this->oldSettings['settings.reviews-form.recaptcha.integration'], ['custom', 'invisible-recaptcha'])) { |
|
148 | + $this->newSettings['settings.submissions.recaptcha.integration'] = 'all'; |
|
149 | + } |
|
150 | + if ('invisible-recaptcha' == $this->oldSettings['settings.reviews-form.recaptcha.integration']) { |
|
151 | + $recaptcha = wp_parse_args((array) get_site_option('ic-settings', [], false), $recaptcha); |
|
152 | + } |
|
153 | + $this->newSettings['settings.submissions.recaptcha.key'] = $recaptcha['SiteKey']; |
|
154 | + $this->newSettings['settings.submissions.recaptcha.secret'] = $recaptcha['SecretKey']; |
|
155 | + $this->newSettings['settings.submissions.recaptcha.position'] = $recaptcha['BadgePosition']; |
|
156 | + } |
|
157 | 157 | |
158 | - /** |
|
159 | - * @return void |
|
160 | - */ |
|
161 | - protected function migrateRequiredSettings() |
|
162 | - { |
|
163 | - $this->newSettings['settings.submissions.required'] = array_filter((array) $this->oldSettings['settings.reviews-form.required']); |
|
164 | - $this->newSettings['settings.submissions.required'][] = 'rating'; |
|
165 | - $this->newSettings['settings.submissions.required'][] = 'terms'; |
|
166 | - } |
|
158 | + /** |
|
159 | + * @return void |
|
160 | + */ |
|
161 | + protected function migrateRequiredSettings() |
|
162 | + { |
|
163 | + $this->newSettings['settings.submissions.required'] = array_filter((array) $this->oldSettings['settings.reviews-form.required']); |
|
164 | + $this->newSettings['settings.submissions.required'][] = 'rating'; |
|
165 | + $this->newSettings['settings.submissions.required'][] = 'terms'; |
|
166 | + } |
|
167 | 167 | } |
@@ -71,11 +71,11 @@ discard block |
||
71 | 71 | { |
72 | 72 | $this->newSettings = $this->getNewSettings(); |
73 | 73 | $this->oldSettings = $this->getOldSettings(); |
74 | - if (empty($this->oldSettings)) { |
|
74 | + if( empty($this->oldSettings) ) { |
|
75 | 75 | return; |
76 | 76 | } |
77 | - foreach (static::MAPPED_SETTINGS as $old => $new) { |
|
78 | - if (empty($this->oldSettings[$old])) { |
|
77 | + foreach( static::MAPPED_SETTINGS as $old => $new ) { |
|
78 | + if( empty($this->oldSettings[$old]) ) { |
|
79 | 79 | continue; |
80 | 80 | } |
81 | 81 | $this->newSettings[$new] = $this->oldSettings[$old]; |
@@ -83,12 +83,12 @@ discard block |
||
83 | 83 | $this->migrateNotificationSettings(); |
84 | 84 | $this->migrateRecaptchaSettings(); |
85 | 85 | $this->migrateRequiredSettings(); |
86 | - $oldSettings = Arr::convertDotNotationArray($this->oldSettings); |
|
87 | - $newSettings = Arr::convertDotNotationArray($this->newSettings); |
|
88 | - if (isset($oldSettings['settings']['strings']) && is_array($oldSettings['settings']['strings'])) { |
|
86 | + $oldSettings = Arr::convertDotNotationArray( $this->oldSettings ); |
|
87 | + $newSettings = Arr::convertDotNotationArray( $this->newSettings ); |
|
88 | + if( isset($oldSettings['settings']['strings']) && is_array( $oldSettings['settings']['strings'] ) ) { |
|
89 | 89 | $newSettings['settings']['strings'] = $oldSettings['settings']['strings']; |
90 | 90 | } |
91 | - glsr(OptionManager::class)->set($newSettings); |
|
91 | + glsr( OptionManager::class )->set( $newSettings ); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
@@ -97,8 +97,8 @@ discard block |
||
97 | 97 | protected function getNewSettings() |
98 | 98 | { |
99 | 99 | return wp_parse_args( |
100 | - Arr::flattenArray(glsr(OptionManager::class)->all()), |
|
101 | - glsr(DefaultsManager::class)->defaults() |
|
100 | + Arr::flattenArray( glsr( OptionManager::class )->all() ), |
|
101 | + glsr( DefaultsManager::class )->defaults() |
|
102 | 102 | ); |
103 | 103 | } |
104 | 104 | |
@@ -107,10 +107,10 @@ discard block |
||
107 | 107 | */ |
108 | 108 | protected function getOldSettings() |
109 | 109 | { |
110 | - $defaults = array_fill_keys(array_keys(static::MAPPED_SETTINGS), ''); |
|
111 | - $settings = Arr::flattenArray((array) get_option('geminilabs_site_reviews-v2', [])); |
|
112 | - if (!empty($settings)) { |
|
113 | - $settings = wp_parse_args($settings, $defaults); |
|
110 | + $defaults = array_fill_keys( array_keys( static::MAPPED_SETTINGS ), '' ); |
|
111 | + $settings = Arr::flattenArray( (array)get_option( 'geminilabs_site_reviews-v2', [] ) ); |
|
112 | + if( !empty($settings) ) { |
|
113 | + $settings = wp_parse_args( $settings, $defaults ); |
|
114 | 114 | } |
115 | 115 | return $settings; |
116 | 116 | } |
@@ -126,8 +126,8 @@ discard block |
||
126 | 126 | 'webhook' => 'slack', |
127 | 127 | ]; |
128 | 128 | $this->newSettings['settings.general.notifications'] = []; |
129 | - foreach ($notifications as $old => $new) { |
|
130 | - if ($this->oldSettings['settings.general.notification'] != $old) { |
|
129 | + foreach( $notifications as $old => $new ) { |
|
130 | + if( $this->oldSettings['settings.general.notification'] != $old ) { |
|
131 | 131 | continue; |
132 | 132 | } |
133 | 133 | $this->newSettings['settings.general.notifications'][] = $new; |
@@ -144,11 +144,11 @@ discard block |
||
144 | 144 | 'SecretKey' => $this->oldSettings['settings.reviews-form.recaptcha.secret'], |
145 | 145 | 'SiteKey' => $this->oldSettings['settings.reviews-form.recaptcha.key'], |
146 | 146 | ]; |
147 | - if (in_array($this->oldSettings['settings.reviews-form.recaptcha.integration'], ['custom', 'invisible-recaptcha'])) { |
|
147 | + if( in_array( $this->oldSettings['settings.reviews-form.recaptcha.integration'], ['custom', 'invisible-recaptcha'] ) ) { |
|
148 | 148 | $this->newSettings['settings.submissions.recaptcha.integration'] = 'all'; |
149 | 149 | } |
150 | - if ('invisible-recaptcha' == $this->oldSettings['settings.reviews-form.recaptcha.integration']) { |
|
151 | - $recaptcha = wp_parse_args((array) get_site_option('ic-settings', [], false), $recaptcha); |
|
150 | + if( 'invisible-recaptcha' == $this->oldSettings['settings.reviews-form.recaptcha.integration'] ) { |
|
151 | + $recaptcha = wp_parse_args( (array)get_site_option( 'ic-settings', [], false ), $recaptcha ); |
|
152 | 152 | } |
153 | 153 | $this->newSettings['settings.submissions.recaptcha.key'] = $recaptcha['SiteKey']; |
154 | 154 | $this->newSettings['settings.submissions.recaptcha.secret'] = $recaptcha['SecretKey']; |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | */ |
161 | 161 | protected function migrateRequiredSettings() |
162 | 162 | { |
163 | - $this->newSettings['settings.submissions.required'] = array_filter((array) $this->oldSettings['settings.reviews-form.required']); |
|
163 | + $this->newSettings['settings.submissions.required'] = array_filter( (array)$this->oldSettings['settings.reviews-form.required'] ); |
|
164 | 164 | $this->newSettings['settings.submissions.required'][] = 'rating'; |
165 | 165 | $this->newSettings['settings.submissions.required'][] = 'terms'; |
166 | 166 | } |
@@ -12,144 +12,144 @@ |
||
12 | 12 | |
13 | 13 | class Style |
14 | 14 | { |
15 | - /** |
|
16 | - * @var array |
|
17 | - */ |
|
18 | - public $fields; |
|
15 | + /** |
|
16 | + * @var array |
|
17 | + */ |
|
18 | + public $fields; |
|
19 | 19 | |
20 | - /** |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - public $style; |
|
20 | + /** |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + public $style; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @var array |
|
27 | - */ |
|
28 | - public $pagination; |
|
25 | + /** |
|
26 | + * @var array |
|
27 | + */ |
|
28 | + public $pagination; |
|
29 | 29 | |
30 | - /** |
|
31 | - * @var array |
|
32 | - */ |
|
33 | - public $validation; |
|
30 | + /** |
|
31 | + * @var array |
|
32 | + */ |
|
33 | + public $validation; |
|
34 | 34 | |
35 | - public function __construct() |
|
36 | - { |
|
37 | - $this->style = glsr(OptionManager::class)->get('settings.general.style', 'default'); |
|
38 | - $this->setConfig(); |
|
39 | - } |
|
35 | + public function __construct() |
|
36 | + { |
|
37 | + $this->style = glsr(OptionManager::class)->get('settings.general.style', 'default'); |
|
38 | + $this->setConfig(); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * @param string $view |
|
43 | - * @return string |
|
44 | - */ |
|
45 | - public function filterView($view) |
|
46 | - { |
|
47 | - $styledViews = [ |
|
48 | - 'templates/form/field', |
|
49 | - 'templates/form/response', |
|
50 | - 'templates/form/submit-button', |
|
51 | - 'templates/reviews-form', |
|
52 | - ]; |
|
53 | - if (!preg_match('('.implode('|', $styledViews).')', $view)) { |
|
54 | - return $view; |
|
55 | - } |
|
56 | - $views = $this->generatePossibleViews($view); |
|
57 | - foreach ($views as $possibleView) { |
|
58 | - if (!file_exists(glsr()->file($possibleView))) { |
|
59 | - continue; |
|
60 | - } |
|
61 | - return Str::removePrefix('views/', $possibleView); |
|
62 | - } |
|
63 | - return $view; |
|
64 | - } |
|
41 | + /** |
|
42 | + * @param string $view |
|
43 | + * @return string |
|
44 | + */ |
|
45 | + public function filterView($view) |
|
46 | + { |
|
47 | + $styledViews = [ |
|
48 | + 'templates/form/field', |
|
49 | + 'templates/form/response', |
|
50 | + 'templates/form/submit-button', |
|
51 | + 'templates/reviews-form', |
|
52 | + ]; |
|
53 | + if (!preg_match('('.implode('|', $styledViews).')', $view)) { |
|
54 | + return $view; |
|
55 | + } |
|
56 | + $views = $this->generatePossibleViews($view); |
|
57 | + foreach ($views as $possibleView) { |
|
58 | + if (!file_exists(glsr()->file($possibleView))) { |
|
59 | + continue; |
|
60 | + } |
|
61 | + return Str::removePrefix('views/', $possibleView); |
|
62 | + } |
|
63 | + return $view; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @return string |
|
68 | - */ |
|
69 | - public function get() |
|
70 | - { |
|
71 | - return apply_filters('site-reviews/style', $this->style); |
|
72 | - } |
|
66 | + /** |
|
67 | + * @return string |
|
68 | + */ |
|
69 | + public function get() |
|
70 | + { |
|
71 | + return apply_filters('site-reviews/style', $this->style); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @return array |
|
76 | - */ |
|
77 | - public function setConfig() |
|
78 | - { |
|
79 | - $config = shortcode_atts( |
|
80 | - array_fill_keys(['fields', 'pagination', 'validation'], []), |
|
81 | - glsr()->config('styles/'.$this->style) |
|
82 | - ); |
|
83 | - $this->fields = glsr(StyleFieldsDefaults::class)->restrict($config['fields']); |
|
84 | - $this->pagination = glsr(PaginationDefaults::class)->restrict($config['pagination']); |
|
85 | - $this->validation = glsr(StyleValidationDefaults::class)->restrict($config['validation']); |
|
86 | - } |
|
74 | + /** |
|
75 | + * @return array |
|
76 | + */ |
|
77 | + public function setConfig() |
|
78 | + { |
|
79 | + $config = shortcode_atts( |
|
80 | + array_fill_keys(['fields', 'pagination', 'validation'], []), |
|
81 | + glsr()->config('styles/'.$this->style) |
|
82 | + ); |
|
83 | + $this->fields = glsr(StyleFieldsDefaults::class)->restrict($config['fields']); |
|
84 | + $this->pagination = glsr(PaginationDefaults::class)->restrict($config['pagination']); |
|
85 | + $this->validation = glsr(StyleValidationDefaults::class)->restrict($config['validation']); |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * @return void |
|
90 | - */ |
|
91 | - public function modifyField(Builder $instance) |
|
92 | - { |
|
93 | - if (!$this->isPublicInstance($instance) || empty(array_filter($this->fields))) { |
|
94 | - return; |
|
95 | - } |
|
96 | - call_user_func_array([$this, 'customize'], [$instance]); |
|
97 | - } |
|
88 | + /** |
|
89 | + * @return void |
|
90 | + */ |
|
91 | + public function modifyField(Builder $instance) |
|
92 | + { |
|
93 | + if (!$this->isPublicInstance($instance) || empty(array_filter($this->fields))) { |
|
94 | + return; |
|
95 | + } |
|
96 | + call_user_func_array([$this, 'customize'], [$instance]); |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * @return array |
|
101 | - */ |
|
102 | - public function paginationArgs(array $args) |
|
103 | - { |
|
104 | - return wp_parse_args($args, $this->pagination); |
|
105 | - } |
|
99 | + /** |
|
100 | + * @return array |
|
101 | + */ |
|
102 | + public function paginationArgs(array $args) |
|
103 | + { |
|
104 | + return wp_parse_args($args, $this->pagination); |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * @return void |
|
109 | - */ |
|
110 | - protected function customize(Builder $instance) |
|
111 | - { |
|
112 | - if (!array_key_exists($instance->tag, $this->fields)) { |
|
113 | - return; |
|
114 | - } |
|
115 | - $args = wp_parse_args($instance->args, array_fill_keys(['class', 'type'], '')); |
|
116 | - $key = $instance->tag.'_'.$args['type']; |
|
117 | - $classes = Arr::get($this->fields, $key, Arr::get($this->fields, $instance->tag)); |
|
118 | - $instance->args['class'] = trim($args['class'].' '.$classes); |
|
119 | - do_action_ref_array('site-reviews/customize/'.$this->style, [$instance]); |
|
120 | - } |
|
107 | + /** |
|
108 | + * @return void |
|
109 | + */ |
|
110 | + protected function customize(Builder $instance) |
|
111 | + { |
|
112 | + if (!array_key_exists($instance->tag, $this->fields)) { |
|
113 | + return; |
|
114 | + } |
|
115 | + $args = wp_parse_args($instance->args, array_fill_keys(['class', 'type'], '')); |
|
116 | + $key = $instance->tag.'_'.$args['type']; |
|
117 | + $classes = Arr::get($this->fields, $key, Arr::get($this->fields, $instance->tag)); |
|
118 | + $instance->args['class'] = trim($args['class'].' '.$classes); |
|
119 | + do_action_ref_array('site-reviews/customize/'.$this->style, [$instance]); |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * @param string $view |
|
124 | - * @return array |
|
125 | - */ |
|
126 | - protected function generatePossibleViews($view) |
|
127 | - { |
|
128 | - $basename = basename($view); |
|
129 | - $basepath = rtrim($view, $basename); |
|
130 | - $customPath = 'views/partials/styles/'.$this->style.'/'; |
|
131 | - $parts = explode('_', $basename); |
|
132 | - $views = [ |
|
133 | - $customPath.$basename, |
|
134 | - $customPath.$parts[0], |
|
135 | - $view, |
|
136 | - $basepath.$parts[0], |
|
137 | - ]; |
|
138 | - return array_filter($views); |
|
139 | - } |
|
122 | + /** |
|
123 | + * @param string $view |
|
124 | + * @return array |
|
125 | + */ |
|
126 | + protected function generatePossibleViews($view) |
|
127 | + { |
|
128 | + $basename = basename($view); |
|
129 | + $basepath = rtrim($view, $basename); |
|
130 | + $customPath = 'views/partials/styles/'.$this->style.'/'; |
|
131 | + $parts = explode('_', $basename); |
|
132 | + $views = [ |
|
133 | + $customPath.$basename, |
|
134 | + $customPath.$parts[0], |
|
135 | + $view, |
|
136 | + $basepath.$parts[0], |
|
137 | + ]; |
|
138 | + return array_filter($views); |
|
139 | + } |
|
140 | 140 | |
141 | - /** |
|
142 | - * @return bool |
|
143 | - */ |
|
144 | - protected function isPublicInstance(Builder $instance) |
|
145 | - { |
|
146 | - $args = wp_parse_args($instance->args, [ |
|
147 | - 'is_public' => false, |
|
148 | - 'is_raw' => false, |
|
149 | - ]); |
|
150 | - if (is_admin() || !$args['is_public'] || $args['is_raw']) { |
|
151 | - return false; |
|
152 | - } |
|
153 | - return true; |
|
154 | - } |
|
141 | + /** |
|
142 | + * @return bool |
|
143 | + */ |
|
144 | + protected function isPublicInstance(Builder $instance) |
|
145 | + { |
|
146 | + $args = wp_parse_args($instance->args, [ |
|
147 | + 'is_public' => false, |
|
148 | + 'is_raw' => false, |
|
149 | + ]); |
|
150 | + if (is_admin() || !$args['is_public'] || $args['is_raw']) { |
|
151 | + return false; |
|
152 | + } |
|
153 | + return true; |
|
154 | + } |
|
155 | 155 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | |
35 | 35 | public function __construct() |
36 | 36 | { |
37 | - $this->style = glsr(OptionManager::class)->get('settings.general.style', 'default'); |
|
37 | + $this->style = glsr( OptionManager::class )->get( 'settings.general.style', 'default' ); |
|
38 | 38 | $this->setConfig(); |
39 | 39 | } |
40 | 40 | |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | * @param string $view |
43 | 43 | * @return string |
44 | 44 | */ |
45 | - public function filterView($view) |
|
45 | + public function filterView( $view ) |
|
46 | 46 | { |
47 | 47 | $styledViews = [ |
48 | 48 | 'templates/form/field', |
@@ -50,15 +50,15 @@ discard block |
||
50 | 50 | 'templates/form/submit-button', |
51 | 51 | 'templates/reviews-form', |
52 | 52 | ]; |
53 | - if (!preg_match('('.implode('|', $styledViews).')', $view)) { |
|
53 | + if( !preg_match( '('.implode( '|', $styledViews ).')', $view ) ) { |
|
54 | 54 | return $view; |
55 | 55 | } |
56 | - $views = $this->generatePossibleViews($view); |
|
57 | - foreach ($views as $possibleView) { |
|
58 | - if (!file_exists(glsr()->file($possibleView))) { |
|
56 | + $views = $this->generatePossibleViews( $view ); |
|
57 | + foreach( $views as $possibleView ) { |
|
58 | + if( !file_exists( glsr()->file( $possibleView ) ) ) { |
|
59 | 59 | continue; |
60 | 60 | } |
61 | - return Str::removePrefix('views/', $possibleView); |
|
61 | + return Str::removePrefix( 'views/', $possibleView ); |
|
62 | 62 | } |
63 | 63 | return $view; |
64 | 64 | } |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | */ |
69 | 69 | public function get() |
70 | 70 | { |
71 | - return apply_filters('site-reviews/style', $this->style); |
|
71 | + return apply_filters( 'site-reviews/style', $this->style ); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -77,77 +77,77 @@ discard block |
||
77 | 77 | public function setConfig() |
78 | 78 | { |
79 | 79 | $config = shortcode_atts( |
80 | - array_fill_keys(['fields', 'pagination', 'validation'], []), |
|
81 | - glsr()->config('styles/'.$this->style) |
|
80 | + array_fill_keys( ['fields', 'pagination', 'validation'], [] ), |
|
81 | + glsr()->config( 'styles/'.$this->style ) |
|
82 | 82 | ); |
83 | - $this->fields = glsr(StyleFieldsDefaults::class)->restrict($config['fields']); |
|
84 | - $this->pagination = glsr(PaginationDefaults::class)->restrict($config['pagination']); |
|
85 | - $this->validation = glsr(StyleValidationDefaults::class)->restrict($config['validation']); |
|
83 | + $this->fields = glsr( StyleFieldsDefaults::class )->restrict( $config['fields'] ); |
|
84 | + $this->pagination = glsr( PaginationDefaults::class )->restrict( $config['pagination'] ); |
|
85 | + $this->validation = glsr( StyleValidationDefaults::class )->restrict( $config['validation'] ); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
89 | 89 | * @return void |
90 | 90 | */ |
91 | - public function modifyField(Builder $instance) |
|
91 | + public function modifyField( Builder $instance ) |
|
92 | 92 | { |
93 | - if (!$this->isPublicInstance($instance) || empty(array_filter($this->fields))) { |
|
93 | + if( !$this->isPublicInstance( $instance ) || empty(array_filter( $this->fields )) ) { |
|
94 | 94 | return; |
95 | 95 | } |
96 | - call_user_func_array([$this, 'customize'], [$instance]); |
|
96 | + call_user_func_array( [$this, 'customize'], [$instance] ); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
100 | 100 | * @return array |
101 | 101 | */ |
102 | - public function paginationArgs(array $args) |
|
102 | + public function paginationArgs( array $args ) |
|
103 | 103 | { |
104 | - return wp_parse_args($args, $this->pagination); |
|
104 | + return wp_parse_args( $args, $this->pagination ); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
108 | 108 | * @return void |
109 | 109 | */ |
110 | - protected function customize(Builder $instance) |
|
110 | + protected function customize( Builder $instance ) |
|
111 | 111 | { |
112 | - if (!array_key_exists($instance->tag, $this->fields)) { |
|
112 | + if( !array_key_exists( $instance->tag, $this->fields ) ) { |
|
113 | 113 | return; |
114 | 114 | } |
115 | - $args = wp_parse_args($instance->args, array_fill_keys(['class', 'type'], '')); |
|
115 | + $args = wp_parse_args( $instance->args, array_fill_keys( ['class', 'type'], '' ) ); |
|
116 | 116 | $key = $instance->tag.'_'.$args['type']; |
117 | - $classes = Arr::get($this->fields, $key, Arr::get($this->fields, $instance->tag)); |
|
118 | - $instance->args['class'] = trim($args['class'].' '.$classes); |
|
119 | - do_action_ref_array('site-reviews/customize/'.$this->style, [$instance]); |
|
117 | + $classes = Arr::get( $this->fields, $key, Arr::get( $this->fields, $instance->tag ) ); |
|
118 | + $instance->args['class'] = trim( $args['class'].' '.$classes ); |
|
119 | + do_action_ref_array( 'site-reviews/customize/'.$this->style, [$instance] ); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
123 | 123 | * @param string $view |
124 | 124 | * @return array |
125 | 125 | */ |
126 | - protected function generatePossibleViews($view) |
|
126 | + protected function generatePossibleViews( $view ) |
|
127 | 127 | { |
128 | - $basename = basename($view); |
|
129 | - $basepath = rtrim($view, $basename); |
|
128 | + $basename = basename( $view ); |
|
129 | + $basepath = rtrim( $view, $basename ); |
|
130 | 130 | $customPath = 'views/partials/styles/'.$this->style.'/'; |
131 | - $parts = explode('_', $basename); |
|
131 | + $parts = explode( '_', $basename ); |
|
132 | 132 | $views = [ |
133 | 133 | $customPath.$basename, |
134 | 134 | $customPath.$parts[0], |
135 | 135 | $view, |
136 | 136 | $basepath.$parts[0], |
137 | 137 | ]; |
138 | - return array_filter($views); |
|
138 | + return array_filter( $views ); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |
142 | 142 | * @return bool |
143 | 143 | */ |
144 | - protected function isPublicInstance(Builder $instance) |
|
144 | + protected function isPublicInstance( Builder $instance ) |
|
145 | 145 | { |
146 | - $args = wp_parse_args($instance->args, [ |
|
146 | + $args = wp_parse_args( $instance->args, [ |
|
147 | 147 | 'is_public' => false, |
148 | 148 | 'is_raw' => false, |
149 | - ]); |
|
150 | - if (is_admin() || !$args['is_public'] || $args['is_raw']) { |
|
149 | + ] ); |
|
150 | + if( is_admin() || !$args['is_public'] || $args['is_raw'] ) { |
|
151 | 151 | return false; |
152 | 152 | } |
153 | 153 | return true; |
@@ -12,173 +12,173 @@ |
||
12 | 12 | |
13 | 13 | class Review implements \ArrayAccess |
14 | 14 | { |
15 | - public $assigned_to; |
|
16 | - public $author; |
|
17 | - public $avatar; |
|
18 | - public $content; |
|
19 | - public $custom; |
|
20 | - public $date; |
|
21 | - public $email; |
|
22 | - public $ID; |
|
23 | - public $ip_address; |
|
24 | - public $modified; |
|
25 | - public $pinned; |
|
26 | - public $rating; |
|
27 | - public $response; |
|
28 | - public $review_id; |
|
29 | - public $review_type; |
|
30 | - public $status; |
|
31 | - public $term_ids; |
|
32 | - public $title; |
|
33 | - public $url; |
|
34 | - public $user_id; |
|
15 | + public $assigned_to; |
|
16 | + public $author; |
|
17 | + public $avatar; |
|
18 | + public $content; |
|
19 | + public $custom; |
|
20 | + public $date; |
|
21 | + public $email; |
|
22 | + public $ID; |
|
23 | + public $ip_address; |
|
24 | + public $modified; |
|
25 | + public $pinned; |
|
26 | + public $rating; |
|
27 | + public $response; |
|
28 | + public $review_id; |
|
29 | + public $review_type; |
|
30 | + public $status; |
|
31 | + public $term_ids; |
|
32 | + public $title; |
|
33 | + public $url; |
|
34 | + public $user_id; |
|
35 | 35 | |
36 | - public function __construct(WP_Post $post) |
|
37 | - { |
|
38 | - if (Application::POST_TYPE != $post->post_type) { |
|
39 | - return; |
|
40 | - } |
|
41 | - $this->content = $post->post_content; |
|
42 | - $this->date = $post->post_date; |
|
43 | - $this->ID = intval($post->ID); |
|
44 | - $this->status = $post->post_status; |
|
45 | - $this->title = $post->post_title; |
|
46 | - $this->user_id = intval($post->post_author); |
|
47 | - $this->setProperties($post); |
|
48 | - $this->setTermIds($post); |
|
49 | - } |
|
36 | + public function __construct(WP_Post $post) |
|
37 | + { |
|
38 | + if (Application::POST_TYPE != $post->post_type) { |
|
39 | + return; |
|
40 | + } |
|
41 | + $this->content = $post->post_content; |
|
42 | + $this->date = $post->post_date; |
|
43 | + $this->ID = intval($post->ID); |
|
44 | + $this->status = $post->post_status; |
|
45 | + $this->title = $post->post_title; |
|
46 | + $this->user_id = intval($post->post_author); |
|
47 | + $this->setProperties($post); |
|
48 | + $this->setTermIds($post); |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @return mixed |
|
53 | - */ |
|
54 | - public function __get($key) |
|
55 | - { |
|
56 | - return $this->offsetGet($key); |
|
57 | - } |
|
51 | + /** |
|
52 | + * @return mixed |
|
53 | + */ |
|
54 | + public function __get($key) |
|
55 | + { |
|
56 | + return $this->offsetGet($key); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * @return string |
|
61 | - */ |
|
62 | - public function __toString() |
|
63 | - { |
|
64 | - return (string) $this->build(); |
|
65 | - } |
|
59 | + /** |
|
60 | + * @return string |
|
61 | + */ |
|
62 | + public function __toString() |
|
63 | + { |
|
64 | + return (string) $this->build(); |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * @return ReviewHtml |
|
69 | - */ |
|
70 | - public function build(array $args = []) |
|
71 | - { |
|
72 | - if (empty($this->ID)) { |
|
73 | - return new ReviewHtml($this); |
|
74 | - } |
|
75 | - $partial = glsr(SiteReviewsPartial::class); |
|
76 | - $partial->args = glsr(SiteReviewsDefaults::class)->merge($args); |
|
77 | - $partial->options = Arr::flattenArray(glsr(OptionManager::class)->all()); |
|
78 | - return $partial->buildReview($this); |
|
79 | - } |
|
67 | + /** |
|
68 | + * @return ReviewHtml |
|
69 | + */ |
|
70 | + public function build(array $args = []) |
|
71 | + { |
|
72 | + if (empty($this->ID)) { |
|
73 | + return new ReviewHtml($this); |
|
74 | + } |
|
75 | + $partial = glsr(SiteReviewsPartial::class); |
|
76 | + $partial->args = glsr(SiteReviewsDefaults::class)->merge($args); |
|
77 | + $partial->options = Arr::flattenArray(glsr(OptionManager::class)->all()); |
|
78 | + return $partial->buildReview($this); |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * @param mixed $key |
|
83 | - * @return bool |
|
84 | - */ |
|
85 | - public function offsetExists($key) |
|
86 | - { |
|
87 | - return property_exists($this, $key) || array_key_exists($key, (array) $this->custom); |
|
88 | - } |
|
81 | + /** |
|
82 | + * @param mixed $key |
|
83 | + * @return bool |
|
84 | + */ |
|
85 | + public function offsetExists($key) |
|
86 | + { |
|
87 | + return property_exists($this, $key) || array_key_exists($key, (array) $this->custom); |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * @param mixed $key |
|
92 | - * @return mixed |
|
93 | - */ |
|
94 | - public function offsetGet($key) |
|
95 | - { |
|
96 | - return property_exists($this, $key) |
|
97 | - ? $this->$key |
|
98 | - : Arr::get($this->custom, $key, null); |
|
99 | - } |
|
90 | + /** |
|
91 | + * @param mixed $key |
|
92 | + * @return mixed |
|
93 | + */ |
|
94 | + public function offsetGet($key) |
|
95 | + { |
|
96 | + return property_exists($this, $key) |
|
97 | + ? $this->$key |
|
98 | + : Arr::get($this->custom, $key, null); |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * @param mixed $key |
|
103 | - * @param mixed $value |
|
104 | - * @return void |
|
105 | - */ |
|
106 | - public function offsetSet($key, $value) |
|
107 | - { |
|
108 | - if (property_exists($this, $key)) { |
|
109 | - $this->$key = $value; |
|
110 | - return; |
|
111 | - } |
|
112 | - if (!is_array($this->custom)) { |
|
113 | - $this->custom = array_filter((array) $this->custom); |
|
114 | - } |
|
115 | - $this->custom[$key] = $value; |
|
116 | - } |
|
101 | + /** |
|
102 | + * @param mixed $key |
|
103 | + * @param mixed $value |
|
104 | + * @return void |
|
105 | + */ |
|
106 | + public function offsetSet($key, $value) |
|
107 | + { |
|
108 | + if (property_exists($this, $key)) { |
|
109 | + $this->$key = $value; |
|
110 | + return; |
|
111 | + } |
|
112 | + if (!is_array($this->custom)) { |
|
113 | + $this->custom = array_filter((array) $this->custom); |
|
114 | + } |
|
115 | + $this->custom[$key] = $value; |
|
116 | + } |
|
117 | 117 | |
118 | - /** |
|
119 | - * @param mixed $key |
|
120 | - * @return void |
|
121 | - */ |
|
122 | - public function offsetUnset($key) |
|
123 | - { |
|
124 | - $this->offsetSet($key, null); |
|
125 | - } |
|
118 | + /** |
|
119 | + * @param mixed $key |
|
120 | + * @return void |
|
121 | + */ |
|
122 | + public function offsetUnset($key) |
|
123 | + { |
|
124 | + $this->offsetSet($key, null); |
|
125 | + } |
|
126 | 126 | |
127 | - /** |
|
128 | - * @return void |
|
129 | - */ |
|
130 | - public function render() |
|
131 | - { |
|
132 | - echo $this->build(); |
|
133 | - } |
|
127 | + /** |
|
128 | + * @return void |
|
129 | + */ |
|
130 | + public function render() |
|
131 | + { |
|
132 | + echo $this->build(); |
|
133 | + } |
|
134 | 134 | |
135 | - /** |
|
136 | - * @return bool |
|
137 | - */ |
|
138 | - protected function isModified(array $properties) |
|
139 | - { |
|
140 | - return $this->date != $properties['date'] |
|
141 | - || $this->content != $properties['content'] |
|
142 | - || $this->title != $properties['title']; |
|
143 | - } |
|
135 | + /** |
|
136 | + * @return bool |
|
137 | + */ |
|
138 | + protected function isModified(array $properties) |
|
139 | + { |
|
140 | + return $this->date != $properties['date'] |
|
141 | + || $this->content != $properties['content'] |
|
142 | + || $this->title != $properties['title']; |
|
143 | + } |
|
144 | 144 | |
145 | - /** |
|
146 | - * @return void |
|
147 | - */ |
|
148 | - protected function setProperties(WP_Post $post) |
|
149 | - { |
|
150 | - $defaults = [ |
|
151 | - 'author' => __('Anonymous', 'site-reviews'), |
|
152 | - 'date' => '', |
|
153 | - 'review_id' => '', |
|
154 | - 'review_type' => 'local', |
|
155 | - ]; |
|
156 | - $meta = array_filter( |
|
157 | - array_map('array_shift', array_filter((array) get_post_meta($post->ID))), |
|
158 | - 'strlen' |
|
159 | - ); |
|
160 | - $meta = array_merge($defaults, Arr::unprefixArrayKeys($meta)); |
|
161 | - $properties = glsr(CreateReviewDefaults::class)->restrict(array_merge($defaults, $meta)); |
|
162 | - $this->modified = $this->isModified($properties); |
|
163 | - array_walk($properties, function ($value, $key) { |
|
164 | - if (!property_exists($this, $key) || isset($this->$key)) { |
|
165 | - return; |
|
166 | - } |
|
167 | - $this->$key = maybe_unserialize($value); |
|
168 | - }); |
|
169 | - } |
|
145 | + /** |
|
146 | + * @return void |
|
147 | + */ |
|
148 | + protected function setProperties(WP_Post $post) |
|
149 | + { |
|
150 | + $defaults = [ |
|
151 | + 'author' => __('Anonymous', 'site-reviews'), |
|
152 | + 'date' => '', |
|
153 | + 'review_id' => '', |
|
154 | + 'review_type' => 'local', |
|
155 | + ]; |
|
156 | + $meta = array_filter( |
|
157 | + array_map('array_shift', array_filter((array) get_post_meta($post->ID))), |
|
158 | + 'strlen' |
|
159 | + ); |
|
160 | + $meta = array_merge($defaults, Arr::unprefixArrayKeys($meta)); |
|
161 | + $properties = glsr(CreateReviewDefaults::class)->restrict(array_merge($defaults, $meta)); |
|
162 | + $this->modified = $this->isModified($properties); |
|
163 | + array_walk($properties, function ($value, $key) { |
|
164 | + if (!property_exists($this, $key) || isset($this->$key)) { |
|
165 | + return; |
|
166 | + } |
|
167 | + $this->$key = maybe_unserialize($value); |
|
168 | + }); |
|
169 | + } |
|
170 | 170 | |
171 | - /** |
|
172 | - * @return void |
|
173 | - */ |
|
174 | - protected function setTermIds(WP_Post $post) |
|
175 | - { |
|
176 | - $this->term_ids = []; |
|
177 | - if (!is_array($terms = get_the_terms($post, Application::TAXONOMY))) { |
|
178 | - return; |
|
179 | - } |
|
180 | - foreach ($terms as $term) { |
|
181 | - $this->term_ids[] = $term->term_id; |
|
182 | - } |
|
183 | - } |
|
171 | + /** |
|
172 | + * @return void |
|
173 | + */ |
|
174 | + protected function setTermIds(WP_Post $post) |
|
175 | + { |
|
176 | + $this->term_ids = []; |
|
177 | + if (!is_array($terms = get_the_terms($post, Application::TAXONOMY))) { |
|
178 | + return; |
|
179 | + } |
|
180 | + foreach ($terms as $term) { |
|
181 | + $this->term_ids[] = $term->term_id; |
|
182 | + } |
|
183 | + } |
|
184 | 184 | } |
@@ -33,27 +33,27 @@ discard block |
||
33 | 33 | public $url; |
34 | 34 | public $user_id; |
35 | 35 | |
36 | - public function __construct(WP_Post $post) |
|
36 | + public function __construct( WP_Post $post ) |
|
37 | 37 | { |
38 | - if (Application::POST_TYPE != $post->post_type) { |
|
38 | + if( Application::POST_TYPE != $post->post_type ) { |
|
39 | 39 | return; |
40 | 40 | } |
41 | 41 | $this->content = $post->post_content; |
42 | 42 | $this->date = $post->post_date; |
43 | - $this->ID = intval($post->ID); |
|
43 | + $this->ID = intval( $post->ID ); |
|
44 | 44 | $this->status = $post->post_status; |
45 | 45 | $this->title = $post->post_title; |
46 | - $this->user_id = intval($post->post_author); |
|
47 | - $this->setProperties($post); |
|
48 | - $this->setTermIds($post); |
|
46 | + $this->user_id = intval( $post->post_author ); |
|
47 | + $this->setProperties( $post ); |
|
48 | + $this->setTermIds( $post ); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
52 | 52 | * @return mixed |
53 | 53 | */ |
54 | - public function __get($key) |
|
54 | + public function __get( $key ) |
|
55 | 55 | { |
56 | - return $this->offsetGet($key); |
|
56 | + return $this->offsetGet( $key ); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
@@ -61,41 +61,41 @@ discard block |
||
61 | 61 | */ |
62 | 62 | public function __toString() |
63 | 63 | { |
64 | - return (string) $this->build(); |
|
64 | + return (string)$this->build(); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
68 | 68 | * @return ReviewHtml |
69 | 69 | */ |
70 | - public function build(array $args = []) |
|
70 | + public function build( array $args = [] ) |
|
71 | 71 | { |
72 | - if (empty($this->ID)) { |
|
73 | - return new ReviewHtml($this); |
|
72 | + if( empty($this->ID) ) { |
|
73 | + return new ReviewHtml( $this ); |
|
74 | 74 | } |
75 | - $partial = glsr(SiteReviewsPartial::class); |
|
76 | - $partial->args = glsr(SiteReviewsDefaults::class)->merge($args); |
|
77 | - $partial->options = Arr::flattenArray(glsr(OptionManager::class)->all()); |
|
78 | - return $partial->buildReview($this); |
|
75 | + $partial = glsr( SiteReviewsPartial::class ); |
|
76 | + $partial->args = glsr( SiteReviewsDefaults::class )->merge( $args ); |
|
77 | + $partial->options = Arr::flattenArray( glsr( OptionManager::class )->all() ); |
|
78 | + return $partial->buildReview( $this ); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
82 | 82 | * @param mixed $key |
83 | 83 | * @return bool |
84 | 84 | */ |
85 | - public function offsetExists($key) |
|
85 | + public function offsetExists( $key ) |
|
86 | 86 | { |
87 | - return property_exists($this, $key) || array_key_exists($key, (array) $this->custom); |
|
87 | + return property_exists( $this, $key ) || array_key_exists( $key, (array)$this->custom ); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
91 | 91 | * @param mixed $key |
92 | 92 | * @return mixed |
93 | 93 | */ |
94 | - public function offsetGet($key) |
|
94 | + public function offsetGet( $key ) |
|
95 | 95 | { |
96 | - return property_exists($this, $key) |
|
96 | + return property_exists( $this, $key ) |
|
97 | 97 | ? $this->$key |
98 | - : Arr::get($this->custom, $key, null); |
|
98 | + : Arr::get( $this->custom, $key, null ); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -103,14 +103,14 @@ discard block |
||
103 | 103 | * @param mixed $value |
104 | 104 | * @return void |
105 | 105 | */ |
106 | - public function offsetSet($key, $value) |
|
106 | + public function offsetSet( $key, $value ) |
|
107 | 107 | { |
108 | - if (property_exists($this, $key)) { |
|
108 | + if( property_exists( $this, $key ) ) { |
|
109 | 109 | $this->$key = $value; |
110 | 110 | return; |
111 | 111 | } |
112 | - if (!is_array($this->custom)) { |
|
113 | - $this->custom = array_filter((array) $this->custom); |
|
112 | + if( !is_array( $this->custom ) ) { |
|
113 | + $this->custom = array_filter( (array)$this->custom ); |
|
114 | 114 | } |
115 | 115 | $this->custom[$key] = $value; |
116 | 116 | } |
@@ -119,9 +119,9 @@ discard block |
||
119 | 119 | * @param mixed $key |
120 | 120 | * @return void |
121 | 121 | */ |
122 | - public function offsetUnset($key) |
|
122 | + public function offsetUnset( $key ) |
|
123 | 123 | { |
124 | - $this->offsetSet($key, null); |
|
124 | + $this->offsetSet( $key, null ); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | /** |
136 | 136 | * @return bool |
137 | 137 | */ |
138 | - protected function isModified(array $properties) |
|
138 | + protected function isModified( array $properties ) |
|
139 | 139 | { |
140 | 140 | return $this->date != $properties['date'] |
141 | 141 | || $this->content != $properties['content'] |
@@ -145,39 +145,39 @@ discard block |
||
145 | 145 | /** |
146 | 146 | * @return void |
147 | 147 | */ |
148 | - protected function setProperties(WP_Post $post) |
|
148 | + protected function setProperties( WP_Post $post ) |
|
149 | 149 | { |
150 | 150 | $defaults = [ |
151 | - 'author' => __('Anonymous', 'site-reviews'), |
|
151 | + 'author' => __( 'Anonymous', 'site-reviews' ), |
|
152 | 152 | 'date' => '', |
153 | 153 | 'review_id' => '', |
154 | 154 | 'review_type' => 'local', |
155 | 155 | ]; |
156 | 156 | $meta = array_filter( |
157 | - array_map('array_shift', array_filter((array) get_post_meta($post->ID))), |
|
157 | + array_map( 'array_shift', array_filter( (array)get_post_meta( $post->ID ) ) ), |
|
158 | 158 | 'strlen' |
159 | 159 | ); |
160 | - $meta = array_merge($defaults, Arr::unprefixArrayKeys($meta)); |
|
161 | - $properties = glsr(CreateReviewDefaults::class)->restrict(array_merge($defaults, $meta)); |
|
162 | - $this->modified = $this->isModified($properties); |
|
163 | - array_walk($properties, function ($value, $key) { |
|
164 | - if (!property_exists($this, $key) || isset($this->$key)) { |
|
160 | + $meta = array_merge( $defaults, Arr::unprefixArrayKeys( $meta ) ); |
|
161 | + $properties = glsr( CreateReviewDefaults::class )->restrict( array_merge( $defaults, $meta ) ); |
|
162 | + $this->modified = $this->isModified( $properties ); |
|
163 | + array_walk( $properties, function( $value, $key ) { |
|
164 | + if( !property_exists( $this, $key ) || isset($this->$key) ) { |
|
165 | 165 | return; |
166 | 166 | } |
167 | - $this->$key = maybe_unserialize($value); |
|
167 | + $this->$key = maybe_unserialize( $value ); |
|
168 | 168 | }); |
169 | 169 | } |
170 | 170 | |
171 | 171 | /** |
172 | 172 | * @return void |
173 | 173 | */ |
174 | - protected function setTermIds(WP_Post $post) |
|
174 | + protected function setTermIds( WP_Post $post ) |
|
175 | 175 | { |
176 | 176 | $this->term_ids = []; |
177 | - if (!is_array($terms = get_the_terms($post, Application::TAXONOMY))) { |
|
177 | + if( !is_array( $terms = get_the_terms( $post, Application::TAXONOMY ) ) ) { |
|
178 | 178 | return; |
179 | 179 | } |
180 | - foreach ($terms as $term) { |
|
180 | + foreach( $terms as $term ) { |
|
181 | 181 | $this->term_ids[] = $term->term_id; |
182 | 182 | } |
183 | 183 | } |