@@ -7,283 +7,283 @@ |
||
7 | 7 | |
8 | 8 | final class Application extends Container |
9 | 9 | { |
10 | - const CAPABILITY = 'edit_others_posts'; |
|
11 | - const CRON_EVENT = 'site-reviews/schedule/session/purge'; |
|
12 | - const ID = 'site-reviews'; |
|
13 | - const PAGED_QUERY_VAR = 'reviews-page'; |
|
14 | - const POST_TYPE = 'site-review'; |
|
15 | - const PREFIX = 'glsr_'; |
|
16 | - const TAXONOMY = 'site-review-category'; |
|
10 | + const CAPABILITY = 'edit_others_posts'; |
|
11 | + const CRON_EVENT = 'site-reviews/schedule/session/purge'; |
|
12 | + const ID = 'site-reviews'; |
|
13 | + const PAGED_QUERY_VAR = 'reviews-page'; |
|
14 | + const POST_TYPE = 'site-review'; |
|
15 | + const PREFIX = 'glsr_'; |
|
16 | + const TAXONOMY = 'site-review-category'; |
|
17 | 17 | |
18 | - public $defaults; |
|
19 | - public $deprecated = []; |
|
20 | - public $file; |
|
21 | - public $languages; |
|
22 | - public $mceShortcodes = []; //defined elsewhere |
|
23 | - public $name; |
|
24 | - public $reviewTypes; |
|
25 | - public $schemas = []; //defined elsewhere |
|
26 | - public $version; |
|
18 | + public $defaults; |
|
19 | + public $deprecated = []; |
|
20 | + public $file; |
|
21 | + public $languages; |
|
22 | + public $mceShortcodes = []; //defined elsewhere |
|
23 | + public $name; |
|
24 | + public $reviewTypes; |
|
25 | + public $schemas = []; //defined elsewhere |
|
26 | + public $version; |
|
27 | 27 | |
28 | - public function __construct() |
|
29 | - { |
|
30 | - static::$instance = $this; |
|
31 | - $this->file = realpath(trailingslashit(dirname(__DIR__)).static::ID.'.php'); |
|
32 | - $plugin = get_file_data($this->file, [ |
|
33 | - 'languages' => 'Domain Path', |
|
34 | - 'name' => 'Plugin Name', |
|
35 | - 'version' => 'Version', |
|
36 | - ], 'plugin'); |
|
37 | - array_walk($plugin, function ($value, $key) { |
|
38 | - $this->$key = $value; |
|
39 | - }); |
|
40 | - } |
|
28 | + public function __construct() |
|
29 | + { |
|
30 | + static::$instance = $this; |
|
31 | + $this->file = realpath(trailingslashit(dirname(__DIR__)).static::ID.'.php'); |
|
32 | + $plugin = get_file_data($this->file, [ |
|
33 | + 'languages' => 'Domain Path', |
|
34 | + 'name' => 'Plugin Name', |
|
35 | + 'version' => 'Version', |
|
36 | + ], 'plugin'); |
|
37 | + array_walk($plugin, function ($value, $key) { |
|
38 | + $this->$key = $value; |
|
39 | + }); |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * @return void |
|
44 | - */ |
|
45 | - public function activate() |
|
46 | - { |
|
47 | - $this->make(DefaultsManager::class)->set(); |
|
48 | - $this->scheduleCronJob(); |
|
49 | - $this->upgrade(); |
|
50 | - } |
|
42 | + /** |
|
43 | + * @return void |
|
44 | + */ |
|
45 | + public function activate() |
|
46 | + { |
|
47 | + $this->make(DefaultsManager::class)->set(); |
|
48 | + $this->scheduleCronJob(); |
|
49 | + $this->upgrade(); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * @return void |
|
54 | - */ |
|
55 | - public function catchFatalError() |
|
56 | - { |
|
57 | - $error = error_get_last(); |
|
58 | - if (E_ERROR !== $error['type'] || false === strpos($error['message'], $this->path())) { |
|
59 | - return; |
|
60 | - } |
|
61 | - glsr_log()->error($error['message']); |
|
62 | - } |
|
52 | + /** |
|
53 | + * @return void |
|
54 | + */ |
|
55 | + public function catchFatalError() |
|
56 | + { |
|
57 | + $error = error_get_last(); |
|
58 | + if (E_ERROR !== $error['type'] || false === strpos($error['message'], $this->path())) { |
|
59 | + return; |
|
60 | + } |
|
61 | + glsr_log()->error($error['message']); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @param string $name |
|
66 | - * @return array |
|
67 | - */ |
|
68 | - public function config($name) |
|
69 | - { |
|
70 | - $configFile = $this->path('config/'.$name.'.php'); |
|
71 | - $config = file_exists($configFile) |
|
72 | - ? include $configFile |
|
73 | - : []; |
|
74 | - return apply_filters('site-reviews/config/'.$name, $config); |
|
75 | - } |
|
64 | + /** |
|
65 | + * @param string $name |
|
66 | + * @return array |
|
67 | + */ |
|
68 | + public function config($name) |
|
69 | + { |
|
70 | + $configFile = $this->path('config/'.$name.'.php'); |
|
71 | + $config = file_exists($configFile) |
|
72 | + ? include $configFile |
|
73 | + : []; |
|
74 | + return apply_filters('site-reviews/config/'.$name, $config); |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * @param string $property |
|
79 | - * @return string |
|
80 | - */ |
|
81 | - public function constant($property, $className = 'static') |
|
82 | - { |
|
83 | - $constant = $className.'::'.$property; |
|
84 | - return defined($constant) |
|
85 | - ? apply_filters('site-reviews/const/'.$property, constant($constant)) |
|
86 | - : ''; |
|
87 | - } |
|
77 | + /** |
|
78 | + * @param string $property |
|
79 | + * @return string |
|
80 | + */ |
|
81 | + public function constant($property, $className = 'static') |
|
82 | + { |
|
83 | + $constant = $className.'::'.$property; |
|
84 | + return defined($constant) |
|
85 | + ? apply_filters('site-reviews/const/'.$property, constant($constant)) |
|
86 | + : ''; |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * @return void |
|
91 | - */ |
|
92 | - public function deactivate() |
|
93 | - { |
|
94 | - $this->unscheduleCronJob(); |
|
95 | - } |
|
89 | + /** |
|
90 | + * @return void |
|
91 | + */ |
|
92 | + public function deactivate() |
|
93 | + { |
|
94 | + $this->unscheduleCronJob(); |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * @param string $view |
|
99 | - * @return void|string |
|
100 | - */ |
|
101 | - public function file($view) |
|
102 | - { |
|
103 | - $view.= '.php'; |
|
104 | - $filePaths = []; |
|
105 | - if (glsr(Helper::class)->startsWith('templates/', $view)) { |
|
106 | - $filePaths[] = $this->themePath(glsr(Helper::class)->removePrefix('templates/', $view)); |
|
107 | - } |
|
108 | - $filePaths[] = $this->path($view); |
|
109 | - $filePaths[] = $this->path('views/'.$view); |
|
110 | - foreach ($filePaths as $file) { |
|
111 | - if (!file_exists($file)) { |
|
112 | - continue; |
|
113 | - } |
|
114 | - return $file; |
|
115 | - } |
|
116 | - } |
|
97 | + /** |
|
98 | + * @param string $view |
|
99 | + * @return void|string |
|
100 | + */ |
|
101 | + public function file($view) |
|
102 | + { |
|
103 | + $view.= '.php'; |
|
104 | + $filePaths = []; |
|
105 | + if (glsr(Helper::class)->startsWith('templates/', $view)) { |
|
106 | + $filePaths[] = $this->themePath(glsr(Helper::class)->removePrefix('templates/', $view)); |
|
107 | + } |
|
108 | + $filePaths[] = $this->path($view); |
|
109 | + $filePaths[] = $this->path('views/'.$view); |
|
110 | + foreach ($filePaths as $file) { |
|
111 | + if (!file_exists($file)) { |
|
112 | + continue; |
|
113 | + } |
|
114 | + return $file; |
|
115 | + } |
|
116 | + } |
|
117 | 117 | |
118 | - /** |
|
119 | - * @return array |
|
120 | - */ |
|
121 | - public function getDefaults() |
|
122 | - { |
|
123 | - if (empty($this->defaults)) { |
|
124 | - $this->defaults = $this->make(DefaultsManager::class)->get(); |
|
125 | - $this->upgrade(); |
|
126 | - } |
|
127 | - return apply_filters('site-reviews/get/defaults', $this->defaults); |
|
128 | - } |
|
118 | + /** |
|
119 | + * @return array |
|
120 | + */ |
|
121 | + public function getDefaults() |
|
122 | + { |
|
123 | + if (empty($this->defaults)) { |
|
124 | + $this->defaults = $this->make(DefaultsManager::class)->get(); |
|
125 | + $this->upgrade(); |
|
126 | + } |
|
127 | + return apply_filters('site-reviews/get/defaults', $this->defaults); |
|
128 | + } |
|
129 | 129 | |
130 | - /** |
|
131 | - * @return bool |
|
132 | - */ |
|
133 | - public function getPermission($page = '') |
|
134 | - { |
|
135 | - $permissions = [ |
|
136 | - 'addons' => 'install_plugins', |
|
137 | - 'settings' => 'manage_options', |
|
138 | - ]; |
|
139 | - return glsr_get($permissions, $page, $this->constant('CAPABILITY')); |
|
140 | - } |
|
130 | + /** |
|
131 | + * @return bool |
|
132 | + */ |
|
133 | + public function getPermission($page = '') |
|
134 | + { |
|
135 | + $permissions = [ |
|
136 | + 'addons' => 'install_plugins', |
|
137 | + 'settings' => 'manage_options', |
|
138 | + ]; |
|
139 | + return glsr_get($permissions, $page, $this->constant('CAPABILITY')); |
|
140 | + } |
|
141 | 141 | |
142 | - /** |
|
143 | - * @return bool |
|
144 | - */ |
|
145 | - public function hasPermission($page = '') |
|
146 | - { |
|
147 | - $isAdmin = $this->isAdmin(); |
|
148 | - return !$isAdmin || ($isAdmin && current_user_can($this->getPermission($page))); |
|
149 | - } |
|
142 | + /** |
|
143 | + * @return bool |
|
144 | + */ |
|
145 | + public function hasPermission($page = '') |
|
146 | + { |
|
147 | + $isAdmin = $this->isAdmin(); |
|
148 | + return !$isAdmin || ($isAdmin && current_user_can($this->getPermission($page))); |
|
149 | + } |
|
150 | 150 | |
151 | - /** |
|
152 | - * @return void |
|
153 | - */ |
|
154 | - public function init() |
|
155 | - { |
|
156 | - $this->make(Actions::class)->run(); |
|
157 | - $this->make(Filters::class)->run(); |
|
158 | - } |
|
151 | + /** |
|
152 | + * @return void |
|
153 | + */ |
|
154 | + public function init() |
|
155 | + { |
|
156 | + $this->make(Actions::class)->run(); |
|
157 | + $this->make(Filters::class)->run(); |
|
158 | + } |
|
159 | 159 | |
160 | - /** |
|
161 | - * @return bool |
|
162 | - */ |
|
163 | - public function isAdmin() |
|
164 | - { |
|
165 | - return is_admin() && !wp_doing_ajax(); |
|
166 | - } |
|
160 | + /** |
|
161 | + * @return bool |
|
162 | + */ |
|
163 | + public function isAdmin() |
|
164 | + { |
|
165 | + return is_admin() && !wp_doing_ajax(); |
|
166 | + } |
|
167 | 167 | |
168 | - /** |
|
169 | - * @param string $file |
|
170 | - * @return string |
|
171 | - */ |
|
172 | - public function path($file = '', $realpath = true) |
|
173 | - { |
|
174 | - $path = plugin_dir_path($this->file); |
|
175 | - if (!$realpath) { |
|
176 | - $path = trailingslashit(WP_PLUGIN_DIR).basename(dirname($this->file)); |
|
177 | - } |
|
178 | - $path = trailingslashit($path).ltrim(trim($file), '/'); |
|
179 | - return apply_filters('site-reviews/path', $path, $file); |
|
180 | - } |
|
168 | + /** |
|
169 | + * @param string $file |
|
170 | + * @return string |
|
171 | + */ |
|
172 | + public function path($file = '', $realpath = true) |
|
173 | + { |
|
174 | + $path = plugin_dir_path($this->file); |
|
175 | + if (!$realpath) { |
|
176 | + $path = trailingslashit(WP_PLUGIN_DIR).basename(dirname($this->file)); |
|
177 | + } |
|
178 | + $path = trailingslashit($path).ltrim(trim($file), '/'); |
|
179 | + return apply_filters('site-reviews/path', $path, $file); |
|
180 | + } |
|
181 | 181 | |
182 | - /** |
|
183 | - * @return void |
|
184 | - */ |
|
185 | - public function registerAddons() |
|
186 | - { |
|
187 | - do_action('site-reviews/addon/register', $this); |
|
188 | - } |
|
182 | + /** |
|
183 | + * @return void |
|
184 | + */ |
|
185 | + public function registerAddons() |
|
186 | + { |
|
187 | + do_action('site-reviews/addon/register', $this); |
|
188 | + } |
|
189 | 189 | |
190 | - /** |
|
191 | - * @return void |
|
192 | - */ |
|
193 | - public function registerLanguages() |
|
194 | - { |
|
195 | - load_plugin_textdomain(static::ID, false, |
|
196 | - trailingslashit(plugin_basename($this->path()).'/'.$this->languages) |
|
197 | - ); |
|
198 | - } |
|
190 | + /** |
|
191 | + * @return void |
|
192 | + */ |
|
193 | + public function registerLanguages() |
|
194 | + { |
|
195 | + load_plugin_textdomain(static::ID, false, |
|
196 | + trailingslashit(plugin_basename($this->path()).'/'.$this->languages) |
|
197 | + ); |
|
198 | + } |
|
199 | 199 | |
200 | - /** |
|
201 | - * @return void |
|
202 | - */ |
|
203 | - public function registerReviewTypes() |
|
204 | - { |
|
205 | - $types = apply_filters('site-reviews/addon/types', []); |
|
206 | - $this->reviewTypes = wp_parse_args($types, [ |
|
207 | - 'local' => __('Local', 'site-reviews'), |
|
208 | - ]); |
|
209 | - } |
|
200 | + /** |
|
201 | + * @return void |
|
202 | + */ |
|
203 | + public function registerReviewTypes() |
|
204 | + { |
|
205 | + $types = apply_filters('site-reviews/addon/types', []); |
|
206 | + $this->reviewTypes = wp_parse_args($types, [ |
|
207 | + 'local' => __('Local', 'site-reviews'), |
|
208 | + ]); |
|
209 | + } |
|
210 | 210 | |
211 | - /** |
|
212 | - * @param string $view |
|
213 | - * @return void |
|
214 | - */ |
|
215 | - public function render($view, array $data = []) |
|
216 | - { |
|
217 | - $view = apply_filters('site-reviews/render/view', $view, $data); |
|
218 | - $file = apply_filters('site-reviews/views/file', $this->file($view), $view, $data); |
|
219 | - if (!file_exists($file)) { |
|
220 | - glsr_log()->error('File not found: '.$file); |
|
221 | - return; |
|
222 | - } |
|
223 | - $data = apply_filters('site-reviews/views/data', $data, $view); |
|
224 | - extract($data); |
|
225 | - include $file; |
|
226 | - } |
|
211 | + /** |
|
212 | + * @param string $view |
|
213 | + * @return void |
|
214 | + */ |
|
215 | + public function render($view, array $data = []) |
|
216 | + { |
|
217 | + $view = apply_filters('site-reviews/render/view', $view, $data); |
|
218 | + $file = apply_filters('site-reviews/views/file', $this->file($view), $view, $data); |
|
219 | + if (!file_exists($file)) { |
|
220 | + glsr_log()->error('File not found: '.$file); |
|
221 | + return; |
|
222 | + } |
|
223 | + $data = apply_filters('site-reviews/views/data', $data, $view); |
|
224 | + extract($data); |
|
225 | + include $file; |
|
226 | + } |
|
227 | 227 | |
228 | - /** |
|
229 | - * @return void |
|
230 | - */ |
|
231 | - public function scheduleCronJob() |
|
232 | - { |
|
233 | - if (wp_next_scheduled(static::CRON_EVENT)) { |
|
234 | - return; |
|
235 | - } |
|
236 | - wp_schedule_event(time(), 'twicedaily', static::CRON_EVENT); |
|
237 | - } |
|
228 | + /** |
|
229 | + * @return void |
|
230 | + */ |
|
231 | + public function scheduleCronJob() |
|
232 | + { |
|
233 | + if (wp_next_scheduled(static::CRON_EVENT)) { |
|
234 | + return; |
|
235 | + } |
|
236 | + wp_schedule_event(time(), 'twicedaily', static::CRON_EVENT); |
|
237 | + } |
|
238 | 238 | |
239 | - /** |
|
240 | - * @param string $file |
|
241 | - * @return string |
|
242 | - */ |
|
243 | - public function themePath($file = '') |
|
244 | - { |
|
245 | - return get_stylesheet_directory().'/'.static::ID.'/'.ltrim(trim($file), '/'); |
|
246 | - } |
|
239 | + /** |
|
240 | + * @param string $file |
|
241 | + * @return string |
|
242 | + */ |
|
243 | + public function themePath($file = '') |
|
244 | + { |
|
245 | + return get_stylesheet_directory().'/'.static::ID.'/'.ltrim(trim($file), '/'); |
|
246 | + } |
|
247 | 247 | |
248 | - /** |
|
249 | - * @return void |
|
250 | - */ |
|
251 | - public function unscheduleCronJob() |
|
252 | - { |
|
253 | - wp_unschedule_event(intval(wp_next_scheduled(static::CRON_EVENT)), static::CRON_EVENT); |
|
254 | - } |
|
248 | + /** |
|
249 | + * @return void |
|
250 | + */ |
|
251 | + public function unscheduleCronJob() |
|
252 | + { |
|
253 | + wp_unschedule_event(intval(wp_next_scheduled(static::CRON_EVENT)), static::CRON_EVENT); |
|
254 | + } |
|
255 | 255 | |
256 | - /** |
|
257 | - * @return void |
|
258 | - */ |
|
259 | - public function upgrade() |
|
260 | - { |
|
261 | - $this->make(Upgrader::class)->run(); |
|
262 | - } |
|
256 | + /** |
|
257 | + * @return void |
|
258 | + */ |
|
259 | + public function upgrade() |
|
260 | + { |
|
261 | + $this->make(Upgrader::class)->run(); |
|
262 | + } |
|
263 | 263 | |
264 | - /** |
|
265 | - * @param mixed $upgrader |
|
266 | - * @return void |
|
267 | - * @action upgrader_process_complete |
|
268 | - */ |
|
269 | - public function upgraded($upgrader, array $data) |
|
270 | - { |
|
271 | - if (array_key_exists('plugins', $data) |
|
272 | - && in_array(plugin_basename($this->file), $data['plugins']) |
|
273 | - && 'update' === $data['action'] |
|
274 | - && 'plugin' === $data['type'] |
|
275 | - ) { |
|
276 | - $this->upgrade(); |
|
277 | - } |
|
278 | - } |
|
264 | + /** |
|
265 | + * @param mixed $upgrader |
|
266 | + * @return void |
|
267 | + * @action upgrader_process_complete |
|
268 | + */ |
|
269 | + public function upgraded($upgrader, array $data) |
|
270 | + { |
|
271 | + if (array_key_exists('plugins', $data) |
|
272 | + && in_array(plugin_basename($this->file), $data['plugins']) |
|
273 | + && 'update' === $data['action'] |
|
274 | + && 'plugin' === $data['type'] |
|
275 | + ) { |
|
276 | + $this->upgrade(); |
|
277 | + } |
|
278 | + } |
|
279 | 279 | |
280 | - /** |
|
281 | - * @param string $path |
|
282 | - * @return string |
|
283 | - */ |
|
284 | - public function url($path = '') |
|
285 | - { |
|
286 | - $url = esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/')); |
|
287 | - return apply_filters('site-reviews/url', $url, $path); |
|
288 | - } |
|
280 | + /** |
|
281 | + * @param string $path |
|
282 | + * @return string |
|
283 | + */ |
|
284 | + public function url($path = '') |
|
285 | + { |
|
286 | + $url = esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/')); |
|
287 | + return apply_filters('site-reviews/url', $url, $path); |
|
288 | + } |
|
289 | 289 | } |
@@ -28,13 +28,13 @@ discard block |
||
28 | 28 | public function __construct() |
29 | 29 | { |
30 | 30 | static::$instance = $this; |
31 | - $this->file = realpath(trailingslashit(dirname(__DIR__)).static::ID.'.php'); |
|
32 | - $plugin = get_file_data($this->file, [ |
|
31 | + $this->file = realpath( trailingslashit( dirname( __DIR__ ) ).static::ID.'.php' ); |
|
32 | + $plugin = get_file_data( $this->file, [ |
|
33 | 33 | 'languages' => 'Domain Path', |
34 | 34 | 'name' => 'Plugin Name', |
35 | 35 | 'version' => 'Version', |
36 | - ], 'plugin'); |
|
37 | - array_walk($plugin, function ($value, $key) { |
|
36 | + ], 'plugin' ); |
|
37 | + array_walk( $plugin, function( $value, $key ) { |
|
38 | 38 | $this->$key = $value; |
39 | 39 | }); |
40 | 40 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | */ |
45 | 45 | public function activate() |
46 | 46 | { |
47 | - $this->make(DefaultsManager::class)->set(); |
|
47 | + $this->make( DefaultsManager::class )->set(); |
|
48 | 48 | $this->scheduleCronJob(); |
49 | 49 | $this->upgrade(); |
50 | 50 | } |
@@ -55,34 +55,34 @@ discard block |
||
55 | 55 | public function catchFatalError() |
56 | 56 | { |
57 | 57 | $error = error_get_last(); |
58 | - if (E_ERROR !== $error['type'] || false === strpos($error['message'], $this->path())) { |
|
58 | + if( E_ERROR !== $error['type'] || false === strpos( $error['message'], $this->path() ) ) { |
|
59 | 59 | return; |
60 | 60 | } |
61 | - glsr_log()->error($error['message']); |
|
61 | + glsr_log()->error( $error['message'] ); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
65 | 65 | * @param string $name |
66 | 66 | * @return array |
67 | 67 | */ |
68 | - public function config($name) |
|
68 | + public function config( $name ) |
|
69 | 69 | { |
70 | - $configFile = $this->path('config/'.$name.'.php'); |
|
71 | - $config = file_exists($configFile) |
|
70 | + $configFile = $this->path( 'config/'.$name.'.php' ); |
|
71 | + $config = file_exists( $configFile ) |
|
72 | 72 | ? include $configFile |
73 | 73 | : []; |
74 | - return apply_filters('site-reviews/config/'.$name, $config); |
|
74 | + return apply_filters( 'site-reviews/config/'.$name, $config ); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | /** |
78 | 78 | * @param string $property |
79 | 79 | * @return string |
80 | 80 | */ |
81 | - public function constant($property, $className = 'static') |
|
81 | + public function constant( $property, $className = 'static' ) |
|
82 | 82 | { |
83 | 83 | $constant = $className.'::'.$property; |
84 | - return defined($constant) |
|
85 | - ? apply_filters('site-reviews/const/'.$property, constant($constant)) |
|
84 | + return defined( $constant ) |
|
85 | + ? apply_filters( 'site-reviews/const/'.$property, constant( $constant ) ) |
|
86 | 86 | : ''; |
87 | 87 | } |
88 | 88 | |
@@ -98,17 +98,17 @@ discard block |
||
98 | 98 | * @param string $view |
99 | 99 | * @return void|string |
100 | 100 | */ |
101 | - public function file($view) |
|
101 | + public function file( $view ) |
|
102 | 102 | { |
103 | - $view.= '.php'; |
|
103 | + $view .= '.php'; |
|
104 | 104 | $filePaths = []; |
105 | - if (glsr(Helper::class)->startsWith('templates/', $view)) { |
|
106 | - $filePaths[] = $this->themePath(glsr(Helper::class)->removePrefix('templates/', $view)); |
|
105 | + if( glsr( Helper::class )->startsWith( 'templates/', $view ) ) { |
|
106 | + $filePaths[] = $this->themePath( glsr( Helper::class )->removePrefix( 'templates/', $view ) ); |
|
107 | 107 | } |
108 | - $filePaths[] = $this->path($view); |
|
109 | - $filePaths[] = $this->path('views/'.$view); |
|
110 | - foreach ($filePaths as $file) { |
|
111 | - if (!file_exists($file)) { |
|
108 | + $filePaths[] = $this->path( $view ); |
|
109 | + $filePaths[] = $this->path( 'views/'.$view ); |
|
110 | + foreach( $filePaths as $file ) { |
|
111 | + if( !file_exists( $file ) ) { |
|
112 | 112 | continue; |
113 | 113 | } |
114 | 114 | return $file; |
@@ -120,32 +120,32 @@ discard block |
||
120 | 120 | */ |
121 | 121 | public function getDefaults() |
122 | 122 | { |
123 | - if (empty($this->defaults)) { |
|
124 | - $this->defaults = $this->make(DefaultsManager::class)->get(); |
|
123 | + if( empty($this->defaults) ) { |
|
124 | + $this->defaults = $this->make( DefaultsManager::class )->get(); |
|
125 | 125 | $this->upgrade(); |
126 | 126 | } |
127 | - return apply_filters('site-reviews/get/defaults', $this->defaults); |
|
127 | + return apply_filters( 'site-reviews/get/defaults', $this->defaults ); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
131 | 131 | * @return bool |
132 | 132 | */ |
133 | - public function getPermission($page = '') |
|
133 | + public function getPermission( $page = '' ) |
|
134 | 134 | { |
135 | 135 | $permissions = [ |
136 | 136 | 'addons' => 'install_plugins', |
137 | 137 | 'settings' => 'manage_options', |
138 | 138 | ]; |
139 | - return glsr_get($permissions, $page, $this->constant('CAPABILITY')); |
|
139 | + return glsr_get( $permissions, $page, $this->constant( 'CAPABILITY' ) ); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
143 | 143 | * @return bool |
144 | 144 | */ |
145 | - public function hasPermission($page = '') |
|
145 | + public function hasPermission( $page = '' ) |
|
146 | 146 | { |
147 | 147 | $isAdmin = $this->isAdmin(); |
148 | - return !$isAdmin || ($isAdmin && current_user_can($this->getPermission($page))); |
|
148 | + return !$isAdmin || ($isAdmin && current_user_can( $this->getPermission( $page ) )); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | /** |
@@ -153,8 +153,8 @@ discard block |
||
153 | 153 | */ |
154 | 154 | public function init() |
155 | 155 | { |
156 | - $this->make(Actions::class)->run(); |
|
157 | - $this->make(Filters::class)->run(); |
|
156 | + $this->make( Actions::class )->run(); |
|
157 | + $this->make( Filters::class )->run(); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | /** |
@@ -169,14 +169,14 @@ discard block |
||
169 | 169 | * @param string $file |
170 | 170 | * @return string |
171 | 171 | */ |
172 | - public function path($file = '', $realpath = true) |
|
172 | + public function path( $file = '', $realpath = true ) |
|
173 | 173 | { |
174 | - $path = plugin_dir_path($this->file); |
|
175 | - if (!$realpath) { |
|
176 | - $path = trailingslashit(WP_PLUGIN_DIR).basename(dirname($this->file)); |
|
174 | + $path = plugin_dir_path( $this->file ); |
|
175 | + if( !$realpath ) { |
|
176 | + $path = trailingslashit( WP_PLUGIN_DIR ).basename( dirname( $this->file ) ); |
|
177 | 177 | } |
178 | - $path = trailingslashit($path).ltrim(trim($file), '/'); |
|
179 | - return apply_filters('site-reviews/path', $path, $file); |
|
178 | + $path = trailingslashit( $path ).ltrim( trim( $file ), '/' ); |
|
179 | + return apply_filters( 'site-reviews/path', $path, $file ); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | /** |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | */ |
185 | 185 | public function registerAddons() |
186 | 186 | { |
187 | - do_action('site-reviews/addon/register', $this); |
|
187 | + do_action( 'site-reviews/addon/register', $this ); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
@@ -192,8 +192,8 @@ discard block |
||
192 | 192 | */ |
193 | 193 | public function registerLanguages() |
194 | 194 | { |
195 | - load_plugin_textdomain(static::ID, false, |
|
196 | - trailingslashit(plugin_basename($this->path()).'/'.$this->languages) |
|
195 | + load_plugin_textdomain( static::ID, false, |
|
196 | + trailingslashit( plugin_basename( $this->path() ).'/'.$this->languages ) |
|
197 | 197 | ); |
198 | 198 | } |
199 | 199 | |
@@ -202,26 +202,26 @@ discard block |
||
202 | 202 | */ |
203 | 203 | public function registerReviewTypes() |
204 | 204 | { |
205 | - $types = apply_filters('site-reviews/addon/types', []); |
|
206 | - $this->reviewTypes = wp_parse_args($types, [ |
|
207 | - 'local' => __('Local', 'site-reviews'), |
|
208 | - ]); |
|
205 | + $types = apply_filters( 'site-reviews/addon/types', [] ); |
|
206 | + $this->reviewTypes = wp_parse_args( $types, [ |
|
207 | + 'local' => __( 'Local', 'site-reviews' ), |
|
208 | + ] ); |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | /** |
212 | 212 | * @param string $view |
213 | 213 | * @return void |
214 | 214 | */ |
215 | - public function render($view, array $data = []) |
|
215 | + public function render( $view, array $data = [] ) |
|
216 | 216 | { |
217 | - $view = apply_filters('site-reviews/render/view', $view, $data); |
|
218 | - $file = apply_filters('site-reviews/views/file', $this->file($view), $view, $data); |
|
219 | - if (!file_exists($file)) { |
|
220 | - glsr_log()->error('File not found: '.$file); |
|
217 | + $view = apply_filters( 'site-reviews/render/view', $view, $data ); |
|
218 | + $file = apply_filters( 'site-reviews/views/file', $this->file( $view ), $view, $data ); |
|
219 | + if( !file_exists( $file ) ) { |
|
220 | + glsr_log()->error( 'File not found: '.$file ); |
|
221 | 221 | return; |
222 | 222 | } |
223 | - $data = apply_filters('site-reviews/views/data', $data, $view); |
|
224 | - extract($data); |
|
223 | + $data = apply_filters( 'site-reviews/views/data', $data, $view ); |
|
224 | + extract( $data ); |
|
225 | 225 | include $file; |
226 | 226 | } |
227 | 227 | |
@@ -230,19 +230,19 @@ discard block |
||
230 | 230 | */ |
231 | 231 | public function scheduleCronJob() |
232 | 232 | { |
233 | - if (wp_next_scheduled(static::CRON_EVENT)) { |
|
233 | + if( wp_next_scheduled( static::CRON_EVENT ) ) { |
|
234 | 234 | return; |
235 | 235 | } |
236 | - wp_schedule_event(time(), 'twicedaily', static::CRON_EVENT); |
|
236 | + wp_schedule_event( time(), 'twicedaily', static::CRON_EVENT ); |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | /** |
240 | 240 | * @param string $file |
241 | 241 | * @return string |
242 | 242 | */ |
243 | - public function themePath($file = '') |
|
243 | + public function themePath( $file = '' ) |
|
244 | 244 | { |
245 | - return get_stylesheet_directory().'/'.static::ID.'/'.ltrim(trim($file), '/'); |
|
245 | + return get_stylesheet_directory().'/'.static::ID.'/'.ltrim( trim( $file ), '/' ); |
|
246 | 246 | } |
247 | 247 | |
248 | 248 | /** |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | */ |
251 | 251 | public function unscheduleCronJob() |
252 | 252 | { |
253 | - wp_unschedule_event(intval(wp_next_scheduled(static::CRON_EVENT)), static::CRON_EVENT); |
|
253 | + wp_unschedule_event( intval( wp_next_scheduled( static::CRON_EVENT ) ), static::CRON_EVENT ); |
|
254 | 254 | } |
255 | 255 | |
256 | 256 | /** |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | */ |
259 | 259 | public function upgrade() |
260 | 260 | { |
261 | - $this->make(Upgrader::class)->run(); |
|
261 | + $this->make( Upgrader::class )->run(); |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | /** |
@@ -266,10 +266,10 @@ discard block |
||
266 | 266 | * @return void |
267 | 267 | * @action upgrader_process_complete |
268 | 268 | */ |
269 | - public function upgraded($upgrader, array $data) |
|
269 | + public function upgraded( $upgrader, array $data ) |
|
270 | 270 | { |
271 | - if (array_key_exists('plugins', $data) |
|
272 | - && in_array(plugin_basename($this->file), $data['plugins']) |
|
271 | + if( array_key_exists( 'plugins', $data ) |
|
272 | + && in_array( plugin_basename( $this->file ), $data['plugins'] ) |
|
273 | 273 | && 'update' === $data['action'] |
274 | 274 | && 'plugin' === $data['type'] |
275 | 275 | ) { |
@@ -281,9 +281,9 @@ discard block |
||
281 | 281 | * @param string $path |
282 | 282 | * @return string |
283 | 283 | */ |
284 | - public function url($path = '') |
|
284 | + public function url( $path = '' ) |
|
285 | 285 | { |
286 | - $url = esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/')); |
|
287 | - return apply_filters('site-reviews/url', $url, $path); |
|
286 | + $url = esc_url( plugin_dir_url( $this->file ).ltrim( trim( $path ), '/' ) ); |
|
287 | + return apply_filters( 'site-reviews/url', $url, $path ); |
|
288 | 288 | } |
289 | 289 | } |
@@ -9,148 +9,148 @@ |
||
9 | 9 | |
10 | 10 | class EnqueuePublicAssets |
11 | 11 | { |
12 | - /** |
|
13 | - * @return void |
|
14 | - */ |
|
15 | - public function handle() |
|
16 | - { |
|
17 | - $this->enqueueAssets(); |
|
18 | - $this->enqueuePolyfillService(); |
|
19 | - $this->enqueueRecaptchaScript(); |
|
20 | - $this->inlineScript(); |
|
21 | - $this->inlineStyles(); |
|
22 | - } |
|
12 | + /** |
|
13 | + * @return void |
|
14 | + */ |
|
15 | + public function handle() |
|
16 | + { |
|
17 | + $this->enqueueAssets(); |
|
18 | + $this->enqueuePolyfillService(); |
|
19 | + $this->enqueueRecaptchaScript(); |
|
20 | + $this->inlineScript(); |
|
21 | + $this->inlineStyles(); |
|
22 | + } |
|
23 | 23 | |
24 | - /** |
|
25 | - * @return void |
|
26 | - */ |
|
27 | - public function enqueueAssets() |
|
28 | - { |
|
29 | - if (apply_filters('site-reviews/assets/css', true)) { |
|
30 | - wp_enqueue_style( |
|
31 | - Application::ID, |
|
32 | - $this->getStylesheet(), |
|
33 | - [], |
|
34 | - glsr()->version |
|
35 | - ); |
|
36 | - } |
|
37 | - if (apply_filters('site-reviews/assets/js', true)) { |
|
38 | - $dependencies = apply_filters('site-reviews/assets/polyfill', true) |
|
39 | - ? [Application::ID.'/polyfill'] |
|
40 | - : []; |
|
41 | - $dependencies = apply_filters('site-reviews/enqueue/public/dependencies', $dependencies); |
|
42 | - wp_enqueue_script( |
|
43 | - Application::ID, |
|
44 | - glsr()->url('assets/scripts/'.Application::ID.'.js'), |
|
45 | - $dependencies, |
|
46 | - glsr()->version, |
|
47 | - true |
|
48 | - ); |
|
49 | - } |
|
50 | - } |
|
24 | + /** |
|
25 | + * @return void |
|
26 | + */ |
|
27 | + public function enqueueAssets() |
|
28 | + { |
|
29 | + if (apply_filters('site-reviews/assets/css', true)) { |
|
30 | + wp_enqueue_style( |
|
31 | + Application::ID, |
|
32 | + $this->getStylesheet(), |
|
33 | + [], |
|
34 | + glsr()->version |
|
35 | + ); |
|
36 | + } |
|
37 | + if (apply_filters('site-reviews/assets/js', true)) { |
|
38 | + $dependencies = apply_filters('site-reviews/assets/polyfill', true) |
|
39 | + ? [Application::ID.'/polyfill'] |
|
40 | + : []; |
|
41 | + $dependencies = apply_filters('site-reviews/enqueue/public/dependencies', $dependencies); |
|
42 | + wp_enqueue_script( |
|
43 | + Application::ID, |
|
44 | + glsr()->url('assets/scripts/'.Application::ID.'.js'), |
|
45 | + $dependencies, |
|
46 | + glsr()->version, |
|
47 | + true |
|
48 | + ); |
|
49 | + } |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * @return void |
|
54 | - */ |
|
55 | - public function enqueuePolyfillService() |
|
56 | - { |
|
57 | - if (!apply_filters('site-reviews/assets/polyfill', true)) { |
|
58 | - return; |
|
59 | - } |
|
60 | - wp_enqueue_script(Application::ID.'/polyfill', add_query_arg([ |
|
61 | - 'features' => 'CustomEvent,Element.prototype.closest,Element.prototype.dataset,Event,XMLHttpRequest,MutationObserver', |
|
62 | - 'flags' => 'gated', |
|
63 | - ], 'https://polyfill.io/v3/polyfill.min.js')); |
|
64 | - } |
|
52 | + /** |
|
53 | + * @return void |
|
54 | + */ |
|
55 | + public function enqueuePolyfillService() |
|
56 | + { |
|
57 | + if (!apply_filters('site-reviews/assets/polyfill', true)) { |
|
58 | + return; |
|
59 | + } |
|
60 | + wp_enqueue_script(Application::ID.'/polyfill', add_query_arg([ |
|
61 | + 'features' => 'CustomEvent,Element.prototype.closest,Element.prototype.dataset,Event,XMLHttpRequest,MutationObserver', |
|
62 | + 'flags' => 'gated', |
|
63 | + ], 'https://polyfill.io/v3/polyfill.min.js')); |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @return void |
|
68 | - */ |
|
69 | - public function enqueueRecaptchaScript() |
|
70 | - { |
|
71 | - // wpforms-recaptcha |
|
72 | - // google-recaptcha |
|
73 | - // nf-google-recaptcha |
|
74 | - if (!glsr(OptionManager::class)->isRecaptchaEnabled()) { |
|
75 | - return; |
|
76 | - } |
|
77 | - $language = apply_filters('site-reviews/recaptcha/language', get_locale()); |
|
78 | - wp_enqueue_script(Application::ID.'/google-recaptcha', add_query_arg([ |
|
79 | - 'hl' => $language, |
|
80 | - 'render' => 'explicit', |
|
81 | - ], 'https://www.google.com/recaptcha/api.js')); |
|
82 | - } |
|
66 | + /** |
|
67 | + * @return void |
|
68 | + */ |
|
69 | + public function enqueueRecaptchaScript() |
|
70 | + { |
|
71 | + // wpforms-recaptcha |
|
72 | + // google-recaptcha |
|
73 | + // nf-google-recaptcha |
|
74 | + if (!glsr(OptionManager::class)->isRecaptchaEnabled()) { |
|
75 | + return; |
|
76 | + } |
|
77 | + $language = apply_filters('site-reviews/recaptcha/language', get_locale()); |
|
78 | + wp_enqueue_script(Application::ID.'/google-recaptcha', add_query_arg([ |
|
79 | + 'hl' => $language, |
|
80 | + 'render' => 'explicit', |
|
81 | + ], 'https://www.google.com/recaptcha/api.js')); |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * @return void |
|
86 | - */ |
|
87 | - public function inlineScript() |
|
88 | - { |
|
89 | - $variables = [ |
|
90 | - 'action' => Application::PREFIX.'action', |
|
91 | - 'ajaxpagination' => $this->getFixedSelectorsForPagination(), |
|
92 | - 'ajaxurl' => admin_url('admin-ajax.php'), |
|
93 | - 'nameprefix' => Application::ID, |
|
94 | - 'validationconfig' => glsr(Style::class)->validation, |
|
95 | - 'validationstrings' => glsr(ValidationStringsDefaults::class)->defaults(), |
|
96 | - ]; |
|
97 | - $variables = apply_filters('site-reviews/enqueue/public/localize', $variables); |
|
98 | - wp_add_inline_script(Application::ID, $this->buildInlineScript($variables), 'before'); |
|
99 | - } |
|
84 | + /** |
|
85 | + * @return void |
|
86 | + */ |
|
87 | + public function inlineScript() |
|
88 | + { |
|
89 | + $variables = [ |
|
90 | + 'action' => Application::PREFIX.'action', |
|
91 | + 'ajaxpagination' => $this->getFixedSelectorsForPagination(), |
|
92 | + 'ajaxurl' => admin_url('admin-ajax.php'), |
|
93 | + 'nameprefix' => Application::ID, |
|
94 | + 'validationconfig' => glsr(Style::class)->validation, |
|
95 | + 'validationstrings' => glsr(ValidationStringsDefaults::class)->defaults(), |
|
96 | + ]; |
|
97 | + $variables = apply_filters('site-reviews/enqueue/public/localize', $variables); |
|
98 | + wp_add_inline_script(Application::ID, $this->buildInlineScript($variables), 'before'); |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * @return void |
|
103 | - */ |
|
104 | - public function inlineStyles() |
|
105 | - { |
|
106 | - $inlineStylesheetPath = glsr()->path('assets/styles/inline-styles.css'); |
|
107 | - if (!apply_filters('site-reviews/assets/css', true)) { |
|
108 | - return; |
|
109 | - } |
|
110 | - if (!file_exists($inlineStylesheetPath)) { |
|
111 | - glsr_log()->error('Inline stylesheet is missing: '.$inlineStylesheetPath); |
|
112 | - return; |
|
113 | - } |
|
114 | - $inlineStylesheetValues = glsr()->config('inline-styles'); |
|
115 | - $stylesheet = str_replace( |
|
116 | - array_keys($inlineStylesheetValues), |
|
117 | - array_values($inlineStylesheetValues), |
|
118 | - file_get_contents($inlineStylesheetPath) |
|
119 | - ); |
|
120 | - wp_add_inline_style(Application::ID, $stylesheet); |
|
121 | - } |
|
101 | + /** |
|
102 | + * @return void |
|
103 | + */ |
|
104 | + public function inlineStyles() |
|
105 | + { |
|
106 | + $inlineStylesheetPath = glsr()->path('assets/styles/inline-styles.css'); |
|
107 | + if (!apply_filters('site-reviews/assets/css', true)) { |
|
108 | + return; |
|
109 | + } |
|
110 | + if (!file_exists($inlineStylesheetPath)) { |
|
111 | + glsr_log()->error('Inline stylesheet is missing: '.$inlineStylesheetPath); |
|
112 | + return; |
|
113 | + } |
|
114 | + $inlineStylesheetValues = glsr()->config('inline-styles'); |
|
115 | + $stylesheet = str_replace( |
|
116 | + array_keys($inlineStylesheetValues), |
|
117 | + array_values($inlineStylesheetValues), |
|
118 | + file_get_contents($inlineStylesheetPath) |
|
119 | + ); |
|
120 | + wp_add_inline_style(Application::ID, $stylesheet); |
|
121 | + } |
|
122 | 122 | |
123 | - /** |
|
124 | - * @return string |
|
125 | - */ |
|
126 | - protected function buildInlineScript(array $variables) |
|
127 | - { |
|
128 | - $script = 'window.hasOwnProperty("GLSR")||(window.GLSR={});'; |
|
129 | - foreach ($variables as $key => $value) { |
|
130 | - $script.= sprintf('GLSR.%s=%s;', $key, json_encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); |
|
131 | - } |
|
132 | - $pattern = '/\"([^ \-\"]+)\"(:[{\[\"])/'; // removes unnecessary quotes surrounding object keys |
|
133 | - $optimizedScript = preg_replace($pattern, '$1$2', $script); |
|
134 | - return apply_filters('site-reviews/enqueue/public/inline-script', $optimizedScript, $script, $variables); |
|
135 | - } |
|
123 | + /** |
|
124 | + * @return string |
|
125 | + */ |
|
126 | + protected function buildInlineScript(array $variables) |
|
127 | + { |
|
128 | + $script = 'window.hasOwnProperty("GLSR")||(window.GLSR={});'; |
|
129 | + foreach ($variables as $key => $value) { |
|
130 | + $script.= sprintf('GLSR.%s=%s;', $key, json_encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); |
|
131 | + } |
|
132 | + $pattern = '/\"([^ \-\"]+)\"(:[{\[\"])/'; // removes unnecessary quotes surrounding object keys |
|
133 | + $optimizedScript = preg_replace($pattern, '$1$2', $script); |
|
134 | + return apply_filters('site-reviews/enqueue/public/inline-script', $optimizedScript, $script, $variables); |
|
135 | + } |
|
136 | 136 | |
137 | - /** |
|
138 | - * @return array |
|
139 | - */ |
|
140 | - protected function getFixedSelectorsForPagination() |
|
141 | - { |
|
142 | - $selectors = ['#wpadminbar', '.site-navigation-fixed']; |
|
143 | - return apply_filters('site-reviews/enqueue/public/localize/ajax-pagination', $selectors); |
|
144 | - } |
|
137 | + /** |
|
138 | + * @return array |
|
139 | + */ |
|
140 | + protected function getFixedSelectorsForPagination() |
|
141 | + { |
|
142 | + $selectors = ['#wpadminbar', '.site-navigation-fixed']; |
|
143 | + return apply_filters('site-reviews/enqueue/public/localize/ajax-pagination', $selectors); |
|
144 | + } |
|
145 | 145 | |
146 | - /** |
|
147 | - * @return string |
|
148 | - */ |
|
149 | - protected function getStylesheet() |
|
150 | - { |
|
151 | - $currentStyle = glsr(Style::class)->style; |
|
152 | - return file_exists(glsr()->path('assets/styles/custom/'.$currentStyle.'.css')) |
|
153 | - ? glsr()->url('assets/styles/custom/'.$currentStyle.'.css') |
|
154 | - : glsr()->url('assets/styles/'.Application::ID.'.css'); |
|
155 | - } |
|
146 | + /** |
|
147 | + * @return string |
|
148 | + */ |
|
149 | + protected function getStylesheet() |
|
150 | + { |
|
151 | + $currentStyle = glsr(Style::class)->style; |
|
152 | + return file_exists(glsr()->path('assets/styles/custom/'.$currentStyle.'.css')) |
|
153 | + ? glsr()->url('assets/styles/custom/'.$currentStyle.'.css') |
|
154 | + : glsr()->url('assets/styles/'.Application::ID.'.css'); |
|
155 | + } |
|
156 | 156 | } |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | */ |
27 | 27 | public function enqueueAssets() |
28 | 28 | { |
29 | - if (apply_filters('site-reviews/assets/css', true)) { |
|
29 | + if( apply_filters( 'site-reviews/assets/css', true ) ) { |
|
30 | 30 | wp_enqueue_style( |
31 | 31 | Application::ID, |
32 | 32 | $this->getStylesheet(), |
@@ -34,14 +34,14 @@ discard block |
||
34 | 34 | glsr()->version |
35 | 35 | ); |
36 | 36 | } |
37 | - if (apply_filters('site-reviews/assets/js', true)) { |
|
38 | - $dependencies = apply_filters('site-reviews/assets/polyfill', true) |
|
37 | + if( apply_filters( 'site-reviews/assets/js', true ) ) { |
|
38 | + $dependencies = apply_filters( 'site-reviews/assets/polyfill', true ) |
|
39 | 39 | ? [Application::ID.'/polyfill'] |
40 | 40 | : []; |
41 | - $dependencies = apply_filters('site-reviews/enqueue/public/dependencies', $dependencies); |
|
41 | + $dependencies = apply_filters( 'site-reviews/enqueue/public/dependencies', $dependencies ); |
|
42 | 42 | wp_enqueue_script( |
43 | 43 | Application::ID, |
44 | - glsr()->url('assets/scripts/'.Application::ID.'.js'), |
|
44 | + glsr()->url( 'assets/scripts/'.Application::ID.'.js' ), |
|
45 | 45 | $dependencies, |
46 | 46 | glsr()->version, |
47 | 47 | true |
@@ -54,13 +54,13 @@ discard block |
||
54 | 54 | */ |
55 | 55 | public function enqueuePolyfillService() |
56 | 56 | { |
57 | - if (!apply_filters('site-reviews/assets/polyfill', true)) { |
|
57 | + if( !apply_filters( 'site-reviews/assets/polyfill', true ) ) { |
|
58 | 58 | return; |
59 | 59 | } |
60 | - wp_enqueue_script(Application::ID.'/polyfill', add_query_arg([ |
|
60 | + wp_enqueue_script( Application::ID.'/polyfill', add_query_arg( [ |
|
61 | 61 | 'features' => 'CustomEvent,Element.prototype.closest,Element.prototype.dataset,Event,XMLHttpRequest,MutationObserver', |
62 | 62 | 'flags' => 'gated', |
63 | - ], 'https://polyfill.io/v3/polyfill.min.js')); |
|
63 | + ], 'https://polyfill.io/v3/polyfill.min.js' ) ); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
@@ -71,14 +71,14 @@ discard block |
||
71 | 71 | // wpforms-recaptcha |
72 | 72 | // google-recaptcha |
73 | 73 | // nf-google-recaptcha |
74 | - if (!glsr(OptionManager::class)->isRecaptchaEnabled()) { |
|
74 | + if( !glsr( OptionManager::class )->isRecaptchaEnabled() ) { |
|
75 | 75 | return; |
76 | 76 | } |
77 | - $language = apply_filters('site-reviews/recaptcha/language', get_locale()); |
|
78 | - wp_enqueue_script(Application::ID.'/google-recaptcha', add_query_arg([ |
|
77 | + $language = apply_filters( 'site-reviews/recaptcha/language', get_locale() ); |
|
78 | + wp_enqueue_script( Application::ID.'/google-recaptcha', add_query_arg( [ |
|
79 | 79 | 'hl' => $language, |
80 | 80 | 'render' => 'explicit', |
81 | - ], 'https://www.google.com/recaptcha/api.js')); |
|
81 | + ], 'https://www.google.com/recaptcha/api.js' ) ); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
@@ -89,13 +89,13 @@ discard block |
||
89 | 89 | $variables = [ |
90 | 90 | 'action' => Application::PREFIX.'action', |
91 | 91 | 'ajaxpagination' => $this->getFixedSelectorsForPagination(), |
92 | - 'ajaxurl' => admin_url('admin-ajax.php'), |
|
92 | + 'ajaxurl' => admin_url( 'admin-ajax.php' ), |
|
93 | 93 | 'nameprefix' => Application::ID, |
94 | - 'validationconfig' => glsr(Style::class)->validation, |
|
95 | - 'validationstrings' => glsr(ValidationStringsDefaults::class)->defaults(), |
|
94 | + 'validationconfig' => glsr( Style::class )->validation, |
|
95 | + 'validationstrings' => glsr( ValidationStringsDefaults::class )->defaults(), |
|
96 | 96 | ]; |
97 | - $variables = apply_filters('site-reviews/enqueue/public/localize', $variables); |
|
98 | - wp_add_inline_script(Application::ID, $this->buildInlineScript($variables), 'before'); |
|
97 | + $variables = apply_filters( 'site-reviews/enqueue/public/localize', $variables ); |
|
98 | + wp_add_inline_script( Application::ID, $this->buildInlineScript( $variables ), 'before' ); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -103,35 +103,35 @@ discard block |
||
103 | 103 | */ |
104 | 104 | public function inlineStyles() |
105 | 105 | { |
106 | - $inlineStylesheetPath = glsr()->path('assets/styles/inline-styles.css'); |
|
107 | - if (!apply_filters('site-reviews/assets/css', true)) { |
|
106 | + $inlineStylesheetPath = glsr()->path( 'assets/styles/inline-styles.css' ); |
|
107 | + if( !apply_filters( 'site-reviews/assets/css', true ) ) { |
|
108 | 108 | return; |
109 | 109 | } |
110 | - if (!file_exists($inlineStylesheetPath)) { |
|
111 | - glsr_log()->error('Inline stylesheet is missing: '.$inlineStylesheetPath); |
|
110 | + if( !file_exists( $inlineStylesheetPath ) ) { |
|
111 | + glsr_log()->error( 'Inline stylesheet is missing: '.$inlineStylesheetPath ); |
|
112 | 112 | return; |
113 | 113 | } |
114 | - $inlineStylesheetValues = glsr()->config('inline-styles'); |
|
114 | + $inlineStylesheetValues = glsr()->config( 'inline-styles' ); |
|
115 | 115 | $stylesheet = str_replace( |
116 | - array_keys($inlineStylesheetValues), |
|
117 | - array_values($inlineStylesheetValues), |
|
118 | - file_get_contents($inlineStylesheetPath) |
|
116 | + array_keys( $inlineStylesheetValues ), |
|
117 | + array_values( $inlineStylesheetValues ), |
|
118 | + file_get_contents( $inlineStylesheetPath ) |
|
119 | 119 | ); |
120 | - wp_add_inline_style(Application::ID, $stylesheet); |
|
120 | + wp_add_inline_style( Application::ID, $stylesheet ); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
124 | 124 | * @return string |
125 | 125 | */ |
126 | - protected function buildInlineScript(array $variables) |
|
126 | + protected function buildInlineScript( array $variables ) |
|
127 | 127 | { |
128 | 128 | $script = 'window.hasOwnProperty("GLSR")||(window.GLSR={});'; |
129 | - foreach ($variables as $key => $value) { |
|
130 | - $script.= sprintf('GLSR.%s=%s;', $key, json_encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); |
|
129 | + foreach( $variables as $key => $value ) { |
|
130 | + $script .= sprintf( 'GLSR.%s=%s;', $key, json_encode( $value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ) ); |
|
131 | 131 | } |
132 | 132 | $pattern = '/\"([^ \-\"]+)\"(:[{\[\"])/'; // removes unnecessary quotes surrounding object keys |
133 | - $optimizedScript = preg_replace($pattern, '$1$2', $script); |
|
134 | - return apply_filters('site-reviews/enqueue/public/inline-script', $optimizedScript, $script, $variables); |
|
133 | + $optimizedScript = preg_replace( $pattern, '$1$2', $script ); |
|
134 | + return apply_filters( 'site-reviews/enqueue/public/inline-script', $optimizedScript, $script, $variables ); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | /** |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | protected function getFixedSelectorsForPagination() |
141 | 141 | { |
142 | 142 | $selectors = ['#wpadminbar', '.site-navigation-fixed']; |
143 | - return apply_filters('site-reviews/enqueue/public/localize/ajax-pagination', $selectors); |
|
143 | + return apply_filters( 'site-reviews/enqueue/public/localize/ajax-pagination', $selectors ); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -148,9 +148,9 @@ discard block |
||
148 | 148 | */ |
149 | 149 | protected function getStylesheet() |
150 | 150 | { |
151 | - $currentStyle = glsr(Style::class)->style; |
|
152 | - return file_exists(glsr()->path('assets/styles/custom/'.$currentStyle.'.css')) |
|
153 | - ? glsr()->url('assets/styles/custom/'.$currentStyle.'.css') |
|
154 | - : glsr()->url('assets/styles/'.Application::ID.'.css'); |
|
151 | + $currentStyle = glsr( Style::class )->style; |
|
152 | + return file_exists( glsr()->path( 'assets/styles/custom/'.$currentStyle.'.css' ) ) |
|
153 | + ? glsr()->url( 'assets/styles/custom/'.$currentStyle.'.css' ) |
|
154 | + : glsr()->url( 'assets/styles/'.Application::ID.'.css' ); |
|
155 | 155 | } |
156 | 156 | } |
@@ -5,23 +5,23 @@ |
||
5 | 5 | require_once ABSPATH.WPINC.'/class-phpass.php'; |
6 | 6 | |
7 | 7 | spl_autoload_register(function ($className) { |
8 | - $namespaces = [ |
|
9 | - 'GeminiLabs\\SiteReviews\\' => __DIR__.'/plugin/', |
|
10 | - 'GeminiLabs\\SiteReviews\\Tests\\' => __DIR__.'/tests/', |
|
11 | - 'GeminiLabs\\Sepia\\PoParser\\' => __DIR__.'/vendors/sepia/po-parser/', |
|
12 | - 'GeminiLabs\\Sinergi\\BrowserDetector\\' => __DIR__.'/vendors/sinergi/browser-detector/', |
|
13 | - 'GeminiLabs\\Vectorface\\Whip\\' => __DIR__.'/vendors/vectorface/whip/', |
|
14 | - ]; |
|
15 | - foreach ($namespaces as $prefix => $baseDir) { |
|
16 | - $len = strlen($prefix); |
|
17 | - if (0 !== strncmp($prefix, $className, $len)) { |
|
18 | - continue; |
|
19 | - } |
|
20 | - $file = $baseDir.str_replace('\\', '/', substr($className, $len)).'.php'; |
|
21 | - if (!file_exists($file)) { |
|
22 | - continue; |
|
23 | - } |
|
24 | - require $file; |
|
25 | - break; |
|
26 | - } |
|
8 | + $namespaces = [ |
|
9 | + 'GeminiLabs\\SiteReviews\\' => __DIR__.'/plugin/', |
|
10 | + 'GeminiLabs\\SiteReviews\\Tests\\' => __DIR__.'/tests/', |
|
11 | + 'GeminiLabs\\Sepia\\PoParser\\' => __DIR__.'/vendors/sepia/po-parser/', |
|
12 | + 'GeminiLabs\\Sinergi\\BrowserDetector\\' => __DIR__.'/vendors/sinergi/browser-detector/', |
|
13 | + 'GeminiLabs\\Vectorface\\Whip\\' => __DIR__.'/vendors/vectorface/whip/', |
|
14 | + ]; |
|
15 | + foreach ($namespaces as $prefix => $baseDir) { |
|
16 | + $len = strlen($prefix); |
|
17 | + if (0 !== strncmp($prefix, $className, $len)) { |
|
18 | + continue; |
|
19 | + } |
|
20 | + $file = $baseDir.str_replace('\\', '/', substr($className, $len)).'.php'; |
|
21 | + if (!file_exists($file)) { |
|
22 | + continue; |
|
23 | + } |
|
24 | + require $file; |
|
25 | + break; |
|
26 | + } |
|
27 | 27 | }); |
@@ -1,10 +1,10 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -defined('WPINC') || die; |
|
3 | +defined( 'WPINC' ) || die; |
|
4 | 4 | |
5 | 5 | require_once ABSPATH.WPINC.'/class-phpass.php'; |
6 | 6 | |
7 | -spl_autoload_register(function ($className) { |
|
7 | +spl_autoload_register( function( $className ) { |
|
8 | 8 | $namespaces = [ |
9 | 9 | 'GeminiLabs\\SiteReviews\\' => __DIR__.'/plugin/', |
10 | 10 | 'GeminiLabs\\SiteReviews\\Tests\\' => __DIR__.'/tests/', |
@@ -12,13 +12,13 @@ discard block |
||
12 | 12 | 'GeminiLabs\\Sinergi\\BrowserDetector\\' => __DIR__.'/vendors/sinergi/browser-detector/', |
13 | 13 | 'GeminiLabs\\Vectorface\\Whip\\' => __DIR__.'/vendors/vectorface/whip/', |
14 | 14 | ]; |
15 | - foreach ($namespaces as $prefix => $baseDir) { |
|
16 | - $len = strlen($prefix); |
|
17 | - if (0 !== strncmp($prefix, $className, $len)) { |
|
15 | + foreach( $namespaces as $prefix => $baseDir ) { |
|
16 | + $len = strlen( $prefix ); |
|
17 | + if( 0 !== strncmp( $prefix, $className, $len ) ) { |
|
18 | 18 | continue; |
19 | 19 | } |
20 | - $file = $baseDir.str_replace('\\', '/', substr($className, $len)).'.php'; |
|
21 | - if (!file_exists($file)) { |
|
20 | + $file = $baseDir.str_replace( '\\', '/', substr( $className, $len ) ).'.php'; |
|
21 | + if( !file_exists( $file ) ) { |
|
22 | 22 | continue; |
23 | 23 | } |
24 | 24 | require $file; |
@@ -8,10 +8,10 @@ discard block |
||
8 | 8 | * @see https://www.elegantthemes.com/gallery/divi/ |
9 | 9 | */ |
10 | 10 | add_action('site-reviews/customize/divi', function ($instance) { |
11 | - if ('label' != $instance->tag || 'checkbox' != $instance->args['type']) { |
|
12 | - return; |
|
13 | - } |
|
14 | - $instance->args['text'] = '<i></i>'.$instance->args['text']; |
|
11 | + if ('label' != $instance->tag || 'checkbox' != $instance->args['type']) { |
|
12 | + return; |
|
13 | + } |
|
14 | + $instance->args['text'] = '<i></i>'.$instance->args['text']; |
|
15 | 15 | }); |
16 | 16 | |
17 | 17 | /* |
@@ -22,14 +22,14 @@ discard block |
||
22 | 22 | * @see https://wordpress.org/plugins/wp-super-cache/ |
23 | 23 | */ |
24 | 24 | add_action('site-reviews/review/created', function ($review, $request) { |
25 | - if (!function_exists('wp_cache_post_change')) { |
|
26 | - return; |
|
27 | - } |
|
28 | - wp_cache_post_change($request->post_id); |
|
29 | - if (empty($review->assigned_to) || $review->assigned_to == $request->post_id) { |
|
30 | - return; |
|
31 | - } |
|
32 | - wp_cache_post_change($review->assigned_to); |
|
25 | + if (!function_exists('wp_cache_post_change')) { |
|
26 | + return; |
|
27 | + } |
|
28 | + wp_cache_post_change($request->post_id); |
|
29 | + if (empty($review->assigned_to) || $review->assigned_to == $request->post_id) { |
|
30 | + return; |
|
31 | + } |
|
32 | + wp_cache_post_change($review->assigned_to); |
|
33 | 33 | }, 10, 2); |
34 | 34 | |
35 | 35 | /* |
@@ -38,8 +38,8 @@ discard block |
||
38 | 38 | * @see https://wordpress.org/plugins/speed-booster-pack/ |
39 | 39 | */ |
40 | 40 | add_filter('sbp_exclude_defer_scripts', function ($scriptHandles) { |
41 | - $scriptHandles[] = 'site-reviews/google-recaptcha'; |
|
42 | - return array_keys(array_flip($scriptHandles)); |
|
41 | + $scriptHandles[] = 'site-reviews/google-recaptcha'; |
|
42 | + return array_keys(array_flip($scriptHandles)); |
|
43 | 43 | }); |
44 | 44 | |
45 | 45 | /* |
@@ -49,13 +49,13 @@ discard block |
||
49 | 49 | * @see https://searchandfilter.com/ |
50 | 50 | */ |
51 | 51 | add_filter('sf_edit_query_args', function ($query) { |
52 | - if (!empty($query['meta_key']) && '_glsr_ranking' == $query['meta_key']) { |
|
53 | - unset($query['meta_key']); |
|
54 | - $query['meta_query'] = [ |
|
55 | - 'relation' => 'OR', |
|
56 | - ['key' => '_glsr_ranking', 'compare' => 'NOT EXISTS'], // this comes first! |
|
57 | - ['key' => '_glsr_ranking', 'compare' => 'EXISTS'], |
|
58 | - ]; |
|
59 | - } |
|
60 | - return $query; |
|
52 | + if (!empty($query['meta_key']) && '_glsr_ranking' == $query['meta_key']) { |
|
53 | + unset($query['meta_key']); |
|
54 | + $query['meta_query'] = [ |
|
55 | + 'relation' => 'OR', |
|
56 | + ['key' => '_glsr_ranking', 'compare' => 'NOT EXISTS'], // this comes first! |
|
57 | + ['key' => '_glsr_ranking', 'compare' => 'EXISTS'], |
|
58 | + ]; |
|
59 | + } |
|
60 | + return $query; |
|
61 | 61 | }, 20); |
@@ -1,14 +1,14 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -defined('WPINC') || die; |
|
3 | +defined( 'WPINC' ) || die; |
|
4 | 4 | |
5 | 5 | /* |
6 | 6 | * @param \GeminiLabs\SiteReviews\Modules\Html\Builder $instance |
7 | 7 | * @return void |
8 | 8 | * @see https://www.elegantthemes.com/gallery/divi/ |
9 | 9 | */ |
10 | -add_action('site-reviews/customize/divi', function ($instance) { |
|
11 | - if ('label' != $instance->tag || 'checkbox' != $instance->args['type']) { |
|
10 | +add_action( 'site-reviews/customize/divi', function( $instance ) { |
|
11 | + if( 'label' != $instance->tag || 'checkbox' != $instance->args['type'] ) { |
|
12 | 12 | return; |
13 | 13 | } |
14 | 14 | $instance->args['text'] = '<i></i>'.$instance->args['text']; |
@@ -21,25 +21,25 @@ discard block |
||
21 | 21 | * @return void |
22 | 22 | * @see https://wordpress.org/plugins/wp-super-cache/ |
23 | 23 | */ |
24 | -add_action('site-reviews/review/created', function ($review, $request) { |
|
25 | - if (!function_exists('wp_cache_post_change')) { |
|
24 | +add_action( 'site-reviews/review/created', function( $review, $request ) { |
|
25 | + if( !function_exists( 'wp_cache_post_change' ) ) { |
|
26 | 26 | return; |
27 | 27 | } |
28 | - wp_cache_post_change($request->post_id); |
|
29 | - if (empty($review->assigned_to) || $review->assigned_to == $request->post_id) { |
|
28 | + wp_cache_post_change( $request->post_id ); |
|
29 | + if( empty($review->assigned_to) || $review->assigned_to == $request->post_id ) { |
|
30 | 30 | return; |
31 | 31 | } |
32 | - wp_cache_post_change($review->assigned_to); |
|
33 | -}, 10, 2); |
|
32 | + wp_cache_post_change( $review->assigned_to ); |
|
33 | +}, 10, 2 ); |
|
34 | 34 | |
35 | 35 | /* |
36 | 36 | * @param array $scriptHandles |
37 | 37 | * @return array |
38 | 38 | * @see https://wordpress.org/plugins/speed-booster-pack/ |
39 | 39 | */ |
40 | -add_filter('sbp_exclude_defer_scripts', function ($scriptHandles) { |
|
40 | +add_filter( 'sbp_exclude_defer_scripts', function( $scriptHandles ) { |
|
41 | 41 | $scriptHandles[] = 'site-reviews/google-recaptcha'; |
42 | - return array_keys(array_flip($scriptHandles)); |
|
42 | + return array_keys( array_flip( $scriptHandles ) ); |
|
43 | 43 | }); |
44 | 44 | |
45 | 45 | /* |
@@ -48,8 +48,8 @@ discard block |
||
48 | 48 | * @return array |
49 | 49 | * @see https://searchandfilter.com/ |
50 | 50 | */ |
51 | -add_filter('sf_edit_query_args', function ($query) { |
|
52 | - if (!empty($query['meta_key']) && '_glsr_ranking' == $query['meta_key']) { |
|
51 | +add_filter( 'sf_edit_query_args', function( $query ) { |
|
52 | + if( !empty($query['meta_key']) && '_glsr_ranking' == $query['meta_key'] ) { |
|
53 | 53 | unset($query['meta_key']); |
54 | 54 | $query['meta_query'] = [ |
55 | 55 | 'relation' => 'OR', |
@@ -58,4 +58,4 @@ discard block |
||
58 | 58 | ]; |
59 | 59 | } |
60 | 60 | return $query; |
61 | -}, 20); |
|
61 | +}, 20 ); |
@@ -100,7 +100,8 @@ |
||
100 | 100 | if (1 == count($vars)) { |
101 | 101 | $value = htmlspecialchars(print_r($vars[0], true), ENT_QUOTES, 'UTF-8'); |
102 | 102 | printf('<div class="glsr-debug"><pre>%s</pre></div>', $value); |
103 | - } else { |
|
103 | + } |
|
104 | + else { |
|
104 | 105 | echo '<div class="glsr-debug-group">'; |
105 | 106 | foreach ($vars as $var) { |
106 | 107 | glsr_debug($var); |
@@ -9,24 +9,24 @@ discard block |
||
9 | 9 | * @return mixed |
10 | 10 | */ |
11 | 11 | add_filter('plugins_loaded', function () { |
12 | - $hooks = array( |
|
13 | - 'glsr_calculate_ratings' => 1, |
|
14 | - 'glsr_create_review' => 2, |
|
15 | - 'glsr_debug' => 10, |
|
16 | - 'glsr_get_option' => 4, |
|
17 | - 'glsr_get_options' => 1, |
|
18 | - 'glsr_get_review' => 2, |
|
19 | - 'glsr_get_reviews' => 2, |
|
20 | - 'glsr_log' => 3, |
|
21 | - 'glsr_star_rating' => 2, |
|
22 | - ); |
|
23 | - foreach ($hooks as $function => $acceptedArgs) { |
|
24 | - add_filter($function, function () use ($function) { |
|
25 | - $args = func_get_args(); |
|
26 | - array_shift($args); // remove the fallback value |
|
27 | - return call_user_func_array($function, $args); |
|
28 | - }, 10, $acceptedArgs); |
|
29 | - } |
|
12 | + $hooks = array( |
|
13 | + 'glsr_calculate_ratings' => 1, |
|
14 | + 'glsr_create_review' => 2, |
|
15 | + 'glsr_debug' => 10, |
|
16 | + 'glsr_get_option' => 4, |
|
17 | + 'glsr_get_options' => 1, |
|
18 | + 'glsr_get_review' => 2, |
|
19 | + 'glsr_get_reviews' => 2, |
|
20 | + 'glsr_log' => 3, |
|
21 | + 'glsr_star_rating' => 2, |
|
22 | + ); |
|
23 | + foreach ($hooks as $function => $acceptedArgs) { |
|
24 | + add_filter($function, function () use ($function) { |
|
25 | + $args = func_get_args(); |
|
26 | + array_shift($args); // remove the fallback value |
|
27 | + return call_user_func_array($function, $args); |
|
28 | + }, 10, $acceptedArgs); |
|
29 | + } |
|
30 | 30 | }); |
31 | 31 | |
32 | 32 | /** |
@@ -34,10 +34,10 @@ discard block |
||
34 | 34 | */ |
35 | 35 | function glsr($alias = null) |
36 | 36 | { |
37 | - $app = \GeminiLabs\SiteReviews\Application::load(); |
|
38 | - return !empty($alias) |
|
39 | - ? $app->make($alias) |
|
40 | - : $app; |
|
37 | + $app = \GeminiLabs\SiteReviews\Application::load(); |
|
38 | + return !empty($alias) |
|
39 | + ? $app->make($alias) |
|
40 | + : $app; |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
@@ -47,15 +47,15 @@ discard block |
||
47 | 47 | */ |
48 | 48 | function glsr_array_column(array $array, $column) |
49 | 49 | { |
50 | - $result = array(); |
|
51 | - foreach ($array as $subarray) { |
|
52 | - $subarray = (array) $subarray; |
|
53 | - if (!isset($subarray[$column])) { |
|
54 | - continue; |
|
55 | - } |
|
56 | - $result[] = $subarray[$column]; |
|
57 | - } |
|
58 | - return $result; |
|
50 | + $result = array(); |
|
51 | + foreach ($array as $subarray) { |
|
52 | + $subarray = (array) $subarray; |
|
53 | + if (!isset($subarray[$column])) { |
|
54 | + continue; |
|
55 | + } |
|
56 | + $result[] = $subarray[$column]; |
|
57 | + } |
|
58 | + return $result; |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -63,8 +63,8 @@ discard block |
||
63 | 63 | */ |
64 | 64 | function glsr_calculate_ratings() |
65 | 65 | { |
66 | - glsr('Controllers\AdminController')->routerCountReviews(false); |
|
67 | - glsr_log()->notice(__('Recalculated rating counts.', 'site-reviews')); |
|
66 | + glsr('Controllers\AdminController')->routerCountReviews(false); |
|
67 | + glsr_log()->notice(__('Recalculated rating counts.', 'site-reviews')); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
@@ -72,10 +72,10 @@ discard block |
||
72 | 72 | */ |
73 | 73 | function glsr_create_review($reviewValues = array()) |
74 | 74 | { |
75 | - $review = new \GeminiLabs\SiteReviews\Commands\CreateReview( |
|
76 | - glsr('Helper')->consolidateArray($reviewValues) |
|
77 | - ); |
|
78 | - return glsr('Database\ReviewManager')->create($review); |
|
75 | + $review = new \GeminiLabs\SiteReviews\Commands\CreateReview( |
|
76 | + glsr('Helper')->consolidateArray($reviewValues) |
|
77 | + ); |
|
78 | + return glsr('Database\ReviewManager')->create($review); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
@@ -83,12 +83,12 @@ discard block |
||
83 | 83 | */ |
84 | 84 | function glsr_current_screen() |
85 | 85 | { |
86 | - if (function_exists('get_current_screen')) { |
|
87 | - $screen = get_current_screen(); |
|
88 | - } |
|
89 | - return empty($screen) |
|
90 | - ? (object) array_fill_keys(['base', 'id', 'post_type'], null) |
|
91 | - : $screen; |
|
86 | + if (function_exists('get_current_screen')) { |
|
87 | + $screen = get_current_screen(); |
|
88 | + } |
|
89 | + return empty($screen) |
|
90 | + ? (object) array_fill_keys(['base', 'id', 'post_type'], null) |
|
91 | + : $screen; |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
@@ -97,16 +97,16 @@ discard block |
||
97 | 97 | */ |
98 | 98 | function glsr_debug(...$vars) |
99 | 99 | { |
100 | - if (1 == count($vars)) { |
|
101 | - $value = htmlspecialchars(print_r($vars[0], true), ENT_QUOTES, 'UTF-8'); |
|
102 | - printf('<div class="glsr-debug"><pre>%s</pre></div>', $value); |
|
103 | - } else { |
|
104 | - echo '<div class="glsr-debug-group">'; |
|
105 | - foreach ($vars as $var) { |
|
106 | - glsr_debug($var); |
|
107 | - } |
|
108 | - echo '</div>'; |
|
109 | - } |
|
100 | + if (1 == count($vars)) { |
|
101 | + $value = htmlspecialchars(print_r($vars[0], true), ENT_QUOTES, 'UTF-8'); |
|
102 | + printf('<div class="glsr-debug"><pre>%s</pre></div>', $value); |
|
103 | + } else { |
|
104 | + echo '<div class="glsr-debug-group">'; |
|
105 | + foreach ($vars as $var) { |
|
106 | + glsr_debug($var); |
|
107 | + } |
|
108 | + echo '</div>'; |
|
109 | + } |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | /** |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | */ |
118 | 118 | function glsr_get($array, $path = '', $fallback = '') |
119 | 119 | { |
120 | - return glsr('Helper')->dataGet($array, $path, $fallback); |
|
120 | + return glsr('Helper')->dataGet($array, $path, $fallback); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -128,9 +128,9 @@ discard block |
||
128 | 128 | */ |
129 | 129 | function glsr_get_option($path = '', $fallback = '', $cast = '') |
130 | 130 | { |
131 | - return is_string($path) |
|
132 | - ? glsr('Database\OptionManager')->get('settings.'.$path, $fallback, $cast) |
|
133 | - : $fallback; |
|
131 | + return is_string($path) |
|
132 | + ? glsr('Database\OptionManager')->get('settings.'.$path, $fallback, $cast) |
|
133 | + : $fallback; |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | */ |
139 | 139 | function glsr_get_options() |
140 | 140 | { |
141 | - return glsr('Database\OptionManager')->get('settings'); |
|
141 | + return glsr('Database\OptionManager')->get('settings'); |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | /** |
@@ -147,13 +147,13 @@ discard block |
||
147 | 147 | */ |
148 | 148 | function glsr_get_review($post) |
149 | 149 | { |
150 | - if (is_numeric($post)) { |
|
151 | - $post = get_post($post); |
|
152 | - } |
|
153 | - if (!($post instanceof WP_Post)) { |
|
154 | - $post = new WP_Post((object) []); |
|
155 | - } |
|
156 | - return glsr('Database\ReviewManager')->single($post); |
|
150 | + if (is_numeric($post)) { |
|
151 | + $post = get_post($post); |
|
152 | + } |
|
153 | + if (!($post instanceof WP_Post)) { |
|
154 | + $post = new WP_Post((object) []); |
|
155 | + } |
|
156 | + return glsr('Database\ReviewManager')->single($post); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | */ |
162 | 162 | function glsr_get_reviews($args = array()) |
163 | 163 | { |
164 | - return glsr('Database\ReviewManager')->get(glsr('Helper')->consolidateArray($args)); |
|
164 | + return glsr('Database\ReviewManager')->get(glsr('Helper')->consolidateArray($args)); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | /** |
@@ -169,12 +169,12 @@ discard block |
||
169 | 169 | */ |
170 | 170 | function glsr_log() |
171 | 171 | { |
172 | - $args = func_get_args(); |
|
173 | - $console = glsr('Modules\Console'); |
|
174 | - if ($value = glsr_get($args, '0')) { |
|
175 | - return $console->debug($value, glsr_get($args, '1', [])); |
|
176 | - } |
|
177 | - return $console; |
|
172 | + $args = func_get_args(); |
|
173 | + $console = glsr('Modules\Console'); |
|
174 | + if ($value = glsr_get($args, '0')) { |
|
175 | + return $console->debug($value, glsr_get($args, '1', [])); |
|
176 | + } |
|
177 | + return $console; |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | /** |
@@ -182,5 +182,5 @@ discard block |
||
182 | 182 | */ |
183 | 183 | function glsr_star_rating($rating) |
184 | 184 | { |
185 | - return glsr('Modules\Html\Partial')->build('star-rating', ['rating' => $rating]); |
|
185 | + return glsr('Modules\Html\Partial')->build('star-rating', ['rating' => $rating]); |
|
186 | 186 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -defined('WPINC') || die; |
|
3 | +defined( 'WPINC' ) || die; |
|
4 | 4 | |
5 | 5 | /* |
6 | 6 | * Alternate method of using the functions without having to use `function_exists()` |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @param mixed ... |
9 | 9 | * @return mixed |
10 | 10 | */ |
11 | -add_filter('plugins_loaded', function () { |
|
11 | +add_filter( 'plugins_loaded', function() { |
|
12 | 12 | $hooks = array( |
13 | 13 | 'glsr_calculate_ratings' => 1, |
14 | 14 | 'glsr_create_review' => 2, |
@@ -20,23 +20,23 @@ discard block |
||
20 | 20 | 'glsr_log' => 3, |
21 | 21 | 'glsr_star_rating' => 2, |
22 | 22 | ); |
23 | - foreach ($hooks as $function => $acceptedArgs) { |
|
24 | - add_filter($function, function () use ($function) { |
|
23 | + foreach( $hooks as $function => $acceptedArgs ) { |
|
24 | + add_filter( $function, function() use ($function) { |
|
25 | 25 | $args = func_get_args(); |
26 | - array_shift($args); // remove the fallback value |
|
27 | - return call_user_func_array($function, $args); |
|
28 | - }, 10, $acceptedArgs); |
|
26 | + array_shift( $args ); // remove the fallback value |
|
27 | + return call_user_func_array( $function, $args ); |
|
28 | + }, 10, $acceptedArgs ); |
|
29 | 29 | } |
30 | 30 | }); |
31 | 31 | |
32 | 32 | /** |
33 | 33 | * @return mixed |
34 | 34 | */ |
35 | -function glsr($alias = null) |
|
35 | +function glsr( $alias = null ) |
|
36 | 36 | { |
37 | 37 | $app = \GeminiLabs\SiteReviews\Application::load(); |
38 | 38 | return !empty($alias) |
39 | - ? $app->make($alias) |
|
39 | + ? $app->make( $alias ) |
|
40 | 40 | : $app; |
41 | 41 | } |
42 | 42 | |
@@ -45,12 +45,12 @@ discard block |
||
45 | 45 | * @param $column string |
46 | 46 | * @return array |
47 | 47 | */ |
48 | -function glsr_array_column(array $array, $column) |
|
48 | +function glsr_array_column( array $array, $column ) |
|
49 | 49 | { |
50 | 50 | $result = array(); |
51 | - foreach ($array as $subarray) { |
|
52 | - $subarray = (array) $subarray; |
|
53 | - if (!isset($subarray[$column])) { |
|
51 | + foreach( $array as $subarray ) { |
|
52 | + $subarray = (array)$subarray; |
|
53 | + if( !isset($subarray[$column]) ) { |
|
54 | 54 | continue; |
55 | 55 | } |
56 | 56 | $result[] = $subarray[$column]; |
@@ -63,19 +63,19 @@ discard block |
||
63 | 63 | */ |
64 | 64 | function glsr_calculate_ratings() |
65 | 65 | { |
66 | - glsr('Controllers\AdminController')->routerCountReviews(false); |
|
67 | - glsr_log()->notice(__('Recalculated rating counts.', 'site-reviews')); |
|
66 | + glsr( 'Controllers\AdminController' )->routerCountReviews( false ); |
|
67 | + glsr_log()->notice( __( 'Recalculated rating counts.', 'site-reviews' ) ); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
71 | 71 | * @return \GeminiLabs\SiteReviews\Review|false |
72 | 72 | */ |
73 | -function glsr_create_review($reviewValues = array()) |
|
73 | +function glsr_create_review( $reviewValues = array() ) |
|
74 | 74 | { |
75 | 75 | $review = new \GeminiLabs\SiteReviews\Commands\CreateReview( |
76 | - glsr('Helper')->consolidateArray($reviewValues) |
|
76 | + glsr( 'Helper' )->consolidateArray( $reviewValues ) |
|
77 | 77 | ); |
78 | - return glsr('Database\ReviewManager')->create($review); |
|
78 | + return glsr( 'Database\ReviewManager' )->create( $review ); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
@@ -83,11 +83,11 @@ discard block |
||
83 | 83 | */ |
84 | 84 | function glsr_current_screen() |
85 | 85 | { |
86 | - if (function_exists('get_current_screen')) { |
|
86 | + if( function_exists( 'get_current_screen' ) ) { |
|
87 | 87 | $screen = get_current_screen(); |
88 | 88 | } |
89 | 89 | return empty($screen) |
90 | - ? (object) array_fill_keys(['base', 'id', 'post_type'], null) |
|
90 | + ? (object)array_fill_keys( ['base', 'id', 'post_type'], null ) |
|
91 | 91 | : $screen; |
92 | 92 | } |
93 | 93 | |
@@ -95,15 +95,15 @@ discard block |
||
95 | 95 | * @param mixed ...$vars |
96 | 96 | * @return void |
97 | 97 | */ |
98 | -function glsr_debug(...$vars) |
|
98 | +function glsr_debug( ...$vars ) |
|
99 | 99 | { |
100 | - if (1 == count($vars)) { |
|
101 | - $value = htmlspecialchars(print_r($vars[0], true), ENT_QUOTES, 'UTF-8'); |
|
102 | - printf('<div class="glsr-debug"><pre>%s</pre></div>', $value); |
|
100 | + if( 1 == count( $vars ) ) { |
|
101 | + $value = htmlspecialchars( print_r( $vars[0], true ), ENT_QUOTES, 'UTF-8' ); |
|
102 | + printf( '<div class="glsr-debug"><pre>%s</pre></div>', $value ); |
|
103 | 103 | } else { |
104 | 104 | echo '<div class="glsr-debug-group">'; |
105 | - foreach ($vars as $var) { |
|
106 | - glsr_debug($var); |
|
105 | + foreach( $vars as $var ) { |
|
106 | + glsr_debug( $var ); |
|
107 | 107 | } |
108 | 108 | echo '</div>'; |
109 | 109 | } |
@@ -115,9 +115,9 @@ discard block |
||
115 | 115 | * @param mixed $fallback |
116 | 116 | * @return mixed |
117 | 117 | */ |
118 | -function glsr_get($array, $path = '', $fallback = '') |
|
118 | +function glsr_get( $array, $path = '', $fallback = '' ) |
|
119 | 119 | { |
120 | - return glsr('Helper')->dataGet($array, $path, $fallback); |
|
120 | + return glsr( 'Helper' )->dataGet( $array, $path, $fallback ); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -126,10 +126,10 @@ discard block |
||
126 | 126 | * @param string $cast |
127 | 127 | * @return string|array |
128 | 128 | */ |
129 | -function glsr_get_option($path = '', $fallback = '', $cast = '') |
|
129 | +function glsr_get_option( $path = '', $fallback = '', $cast = '' ) |
|
130 | 130 | { |
131 | - return is_string($path) |
|
132 | - ? glsr('Database\OptionManager')->get('settings.'.$path, $fallback, $cast) |
|
131 | + return is_string( $path ) |
|
132 | + ? glsr( 'Database\OptionManager' )->get( 'settings.'.$path, $fallback, $cast ) |
|
133 | 133 | : $fallback; |
134 | 134 | } |
135 | 135 | |
@@ -138,30 +138,30 @@ discard block |
||
138 | 138 | */ |
139 | 139 | function glsr_get_options() |
140 | 140 | { |
141 | - return glsr('Database\OptionManager')->get('settings'); |
|
141 | + return glsr( 'Database\OptionManager' )->get( 'settings' ); |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | /** |
145 | 145 | * @param \WP_Post|int $post |
146 | 146 | * @return \GeminiLabs\SiteReviews\Review |
147 | 147 | */ |
148 | -function glsr_get_review($post) |
|
148 | +function glsr_get_review( $post ) |
|
149 | 149 | { |
150 | - if (is_numeric($post)) { |
|
151 | - $post = get_post($post); |
|
150 | + if( is_numeric( $post ) ) { |
|
151 | + $post = get_post( $post ); |
|
152 | 152 | } |
153 | - if (!($post instanceof WP_Post)) { |
|
154 | - $post = new WP_Post((object) []); |
|
153 | + if( !($post instanceof WP_Post) ) { |
|
154 | + $post = new WP_Post( (object)[] ); |
|
155 | 155 | } |
156 | - return glsr('Database\ReviewManager')->single($post); |
|
156 | + return glsr( 'Database\ReviewManager' )->single( $post ); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
160 | 160 | * @return array |
161 | 161 | */ |
162 | -function glsr_get_reviews($args = array()) |
|
162 | +function glsr_get_reviews( $args = array() ) |
|
163 | 163 | { |
164 | - return glsr('Database\ReviewManager')->get(glsr('Helper')->consolidateArray($args)); |
|
164 | + return glsr( 'Database\ReviewManager' )->get( glsr( 'Helper' )->consolidateArray( $args ) ); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | /** |
@@ -170,9 +170,9 @@ discard block |
||
170 | 170 | function glsr_log() |
171 | 171 | { |
172 | 172 | $args = func_get_args(); |
173 | - $console = glsr('Modules\Console'); |
|
174 | - if ($value = glsr_get($args, '0')) { |
|
175 | - return $console->debug($value, glsr_get($args, '1', [])); |
|
173 | + $console = glsr( 'Modules\Console' ); |
|
174 | + if( $value = glsr_get( $args, '0' ) ) { |
|
175 | + return $console->debug( $value, glsr_get( $args, '1', [] ) ); |
|
176 | 176 | } |
177 | 177 | return $console; |
178 | 178 | } |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | /** |
181 | 181 | * @return string |
182 | 182 | */ |
183 | -function glsr_star_rating($rating) |
|
183 | +function glsr_star_rating( $rating ) |
|
184 | 184 | { |
185 | - return glsr('Modules\Html\Partial')->build('star-rating', ['rating' => $rating]); |
|
185 | + return glsr( 'Modules\Html\Partial' )->build( 'star-rating', ['rating' => $rating] ); |
|
186 | 186 | } |
@@ -12,154 +12,154 @@ |
||
12 | 12 | |
13 | 13 | class AjaxController extends Controller |
14 | 14 | { |
15 | - /** |
|
16 | - * @return void |
|
17 | - */ |
|
18 | - public function routerChangeStatus(array $request) |
|
19 | - { |
|
20 | - wp_send_json_success($this->execute(new ChangeStatus($request))); |
|
21 | - } |
|
15 | + /** |
|
16 | + * @return void |
|
17 | + */ |
|
18 | + public function routerChangeStatus(array $request) |
|
19 | + { |
|
20 | + wp_send_json_success($this->execute(new ChangeStatus($request))); |
|
21 | + } |
|
22 | 22 | |
23 | - /** |
|
24 | - * @return void |
|
25 | - */ |
|
26 | - public function routerClearConsole() |
|
27 | - { |
|
28 | - glsr(AdminController::class)->routerClearConsole(); |
|
29 | - wp_send_json_success([ |
|
30 | - 'console' => glsr(Console::class)->get(), |
|
31 | - 'notices' => glsr(Notice::class)->get(), |
|
32 | - ]); |
|
33 | - } |
|
23 | + /** |
|
24 | + * @return void |
|
25 | + */ |
|
26 | + public function routerClearConsole() |
|
27 | + { |
|
28 | + glsr(AdminController::class)->routerClearConsole(); |
|
29 | + wp_send_json_success([ |
|
30 | + 'console' => glsr(Console::class)->get(), |
|
31 | + 'notices' => glsr(Notice::class)->get(), |
|
32 | + ]); |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * @return void |
|
37 | - */ |
|
38 | - public function routerCountReviews() |
|
39 | - { |
|
40 | - glsr(AdminController::class)->routerCountReviews(); |
|
41 | - wp_send_json_success([ |
|
42 | - 'notices' => glsr(Notice::class)->get(), |
|
43 | - ]); |
|
44 | - } |
|
35 | + /** |
|
36 | + * @return void |
|
37 | + */ |
|
38 | + public function routerCountReviews() |
|
39 | + { |
|
40 | + glsr(AdminController::class)->routerCountReviews(); |
|
41 | + wp_send_json_success([ |
|
42 | + 'notices' => glsr(Notice::class)->get(), |
|
43 | + ]); |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * @return void |
|
48 | - */ |
|
49 | - public function routerMceShortcode(array $request) |
|
50 | - { |
|
51 | - $shortcode = $request['shortcode']; |
|
52 | - $response = false; |
|
53 | - if (array_key_exists($shortcode, glsr()->mceShortcodes)) { |
|
54 | - $data = glsr()->mceShortcodes[$shortcode]; |
|
55 | - if (!empty($data['errors'])) { |
|
56 | - $data['btn_okay'] = [esc_html__('Okay', 'site-reviews')]; |
|
57 | - } |
|
58 | - $response = [ |
|
59 | - 'body' => $data['fields'], |
|
60 | - 'close' => $data['btn_close'], |
|
61 | - 'ok' => $data['btn_okay'], |
|
62 | - 'shortcode' => $shortcode, |
|
63 | - 'title' => $data['title'], |
|
64 | - ]; |
|
65 | - } |
|
66 | - wp_send_json_success($response); |
|
67 | - } |
|
46 | + /** |
|
47 | + * @return void |
|
48 | + */ |
|
49 | + public function routerMceShortcode(array $request) |
|
50 | + { |
|
51 | + $shortcode = $request['shortcode']; |
|
52 | + $response = false; |
|
53 | + if (array_key_exists($shortcode, glsr()->mceShortcodes)) { |
|
54 | + $data = glsr()->mceShortcodes[$shortcode]; |
|
55 | + if (!empty($data['errors'])) { |
|
56 | + $data['btn_okay'] = [esc_html__('Okay', 'site-reviews')]; |
|
57 | + } |
|
58 | + $response = [ |
|
59 | + 'body' => $data['fields'], |
|
60 | + 'close' => $data['btn_close'], |
|
61 | + 'ok' => $data['btn_okay'], |
|
62 | + 'shortcode' => $shortcode, |
|
63 | + 'title' => $data['title'], |
|
64 | + ]; |
|
65 | + } |
|
66 | + wp_send_json_success($response); |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * @return void |
|
71 | - */ |
|
72 | - public function routerFetchConsole() |
|
73 | - { |
|
74 | - glsr(AdminController::class)->routerFetchConsole(); |
|
75 | - wp_send_json_success([ |
|
76 | - 'console' => glsr(Console::class)->get(), |
|
77 | - 'notices' => glsr(Notice::class)->get(), |
|
78 | - ]); |
|
79 | - } |
|
69 | + /** |
|
70 | + * @return void |
|
71 | + */ |
|
72 | + public function routerFetchConsole() |
|
73 | + { |
|
74 | + glsr(AdminController::class)->routerFetchConsole(); |
|
75 | + wp_send_json_success([ |
|
76 | + 'console' => glsr(Console::class)->get(), |
|
77 | + 'notices' => glsr(Notice::class)->get(), |
|
78 | + ]); |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * @return void |
|
83 | - */ |
|
84 | - public function routerSearchPosts(array $request) |
|
85 | - { |
|
86 | - $results = glsr(Database::class)->searchPosts($request['search']); |
|
87 | - wp_send_json_success([ |
|
88 | - 'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>', |
|
89 | - 'items' => $results, |
|
90 | - ]); |
|
91 | - } |
|
81 | + /** |
|
82 | + * @return void |
|
83 | + */ |
|
84 | + public function routerSearchPosts(array $request) |
|
85 | + { |
|
86 | + $results = glsr(Database::class)->searchPosts($request['search']); |
|
87 | + wp_send_json_success([ |
|
88 | + 'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>', |
|
89 | + 'items' => $results, |
|
90 | + ]); |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * @return void |
|
95 | - */ |
|
96 | - public function routerSearchTranslations(array $request) |
|
97 | - { |
|
98 | - if (empty($request['exclude'])) { |
|
99 | - $request['exclude'] = []; |
|
100 | - } |
|
101 | - $results = glsr(Translation::class) |
|
102 | - ->search($request['search']) |
|
103 | - ->exclude() |
|
104 | - ->exclude($request['exclude']) |
|
105 | - ->renderResults(); |
|
106 | - wp_send_json_success([ |
|
107 | - 'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>', |
|
108 | - 'items' => $results, |
|
109 | - ]); |
|
110 | - } |
|
93 | + /** |
|
94 | + * @return void |
|
95 | + */ |
|
96 | + public function routerSearchTranslations(array $request) |
|
97 | + { |
|
98 | + if (empty($request['exclude'])) { |
|
99 | + $request['exclude'] = []; |
|
100 | + } |
|
101 | + $results = glsr(Translation::class) |
|
102 | + ->search($request['search']) |
|
103 | + ->exclude() |
|
104 | + ->exclude($request['exclude']) |
|
105 | + ->renderResults(); |
|
106 | + wp_send_json_success([ |
|
107 | + 'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>', |
|
108 | + 'items' => $results, |
|
109 | + ]); |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * @return void |
|
114 | - */ |
|
115 | - public function routerSubmitReview(array $request) |
|
116 | - { |
|
117 | - $command = glsr(PublicController::class)->routerSubmitReview($request); |
|
118 | - $redirect = trim(strval(get_post_meta($command->post_id, 'redirect_to', true))); |
|
119 | - $redirect = apply_filters('site-reviews/review/redirect', $redirect, $command); |
|
120 | - $data = [ |
|
121 | - 'errors' => glsr()->sessionGet($command->form_id.'errors', false), |
|
122 | - 'message' => glsr()->sessionGet($command->form_id.'message', ''), |
|
123 | - 'recaptcha' => glsr()->sessionGet($command->form_id.'recaptcha', false), |
|
124 | - 'redirect' => $redirect, |
|
125 | - ]; |
|
126 | - if (false === $data['errors']) { |
|
127 | - glsr()->sessionClear(); |
|
128 | - wp_send_json_success($data); |
|
129 | - } |
|
130 | - wp_send_json_error($data); |
|
131 | - } |
|
112 | + /** |
|
113 | + * @return void |
|
114 | + */ |
|
115 | + public function routerSubmitReview(array $request) |
|
116 | + { |
|
117 | + $command = glsr(PublicController::class)->routerSubmitReview($request); |
|
118 | + $redirect = trim(strval(get_post_meta($command->post_id, 'redirect_to', true))); |
|
119 | + $redirect = apply_filters('site-reviews/review/redirect', $redirect, $command); |
|
120 | + $data = [ |
|
121 | + 'errors' => glsr()->sessionGet($command->form_id.'errors', false), |
|
122 | + 'message' => glsr()->sessionGet($command->form_id.'message', ''), |
|
123 | + 'recaptcha' => glsr()->sessionGet($command->form_id.'recaptcha', false), |
|
124 | + 'redirect' => $redirect, |
|
125 | + ]; |
|
126 | + if (false === $data['errors']) { |
|
127 | + glsr()->sessionClear(); |
|
128 | + wp_send_json_success($data); |
|
129 | + } |
|
130 | + wp_send_json_error($data); |
|
131 | + } |
|
132 | 132 | |
133 | - /** |
|
134 | - * @return void |
|
135 | - */ |
|
136 | - public function routerFetchPagedReviews(array $request) |
|
137 | - { |
|
138 | - $urlQuery = []; |
|
139 | - parse_str(parse_url(glsr_get($request, 'url'), PHP_URL_QUERY), $urlQuery); |
|
140 | - $args = [ |
|
141 | - 'paged' => glsr_get($urlQuery, glsr()->constant('PAGED_QUERY_VAR'), 1), |
|
142 | - 'pagedUrl' => home_url(parse_url(glsr_get($request, 'url'), PHP_URL_PATH)), |
|
143 | - 'pagination' => 'ajax', |
|
144 | - 'schema' => false, |
|
145 | - ]; |
|
146 | - $atts = (array) json_decode(glsr_get($request, 'atts')); |
|
147 | - $html = glsr(SiteReviews::class)->build(wp_parse_args($args, $atts)); |
|
148 | - return wp_send_json_success([ |
|
149 | - 'pagination' => $html->getPagination(), |
|
150 | - 'reviews' => $html->getReviews(), |
|
151 | - ]); |
|
152 | - } |
|
133 | + /** |
|
134 | + * @return void |
|
135 | + */ |
|
136 | + public function routerFetchPagedReviews(array $request) |
|
137 | + { |
|
138 | + $urlQuery = []; |
|
139 | + parse_str(parse_url(glsr_get($request, 'url'), PHP_URL_QUERY), $urlQuery); |
|
140 | + $args = [ |
|
141 | + 'paged' => glsr_get($urlQuery, glsr()->constant('PAGED_QUERY_VAR'), 1), |
|
142 | + 'pagedUrl' => home_url(parse_url(glsr_get($request, 'url'), PHP_URL_PATH)), |
|
143 | + 'pagination' => 'ajax', |
|
144 | + 'schema' => false, |
|
145 | + ]; |
|
146 | + $atts = (array) json_decode(glsr_get($request, 'atts')); |
|
147 | + $html = glsr(SiteReviews::class)->build(wp_parse_args($args, $atts)); |
|
148 | + return wp_send_json_success([ |
|
149 | + 'pagination' => $html->getPagination(), |
|
150 | + 'reviews' => $html->getReviews(), |
|
151 | + ]); |
|
152 | + } |
|
153 | 153 | |
154 | - /** |
|
155 | - * @return void |
|
156 | - */ |
|
157 | - public function routerTogglePinned(array $request) |
|
158 | - { |
|
159 | - $isPinned = $this->execute(new TogglePinned($request)); |
|
160 | - wp_send_json_success([ |
|
161 | - 'notices' => glsr(Notice::class)->get(), |
|
162 | - 'pinned' => $isPinned, |
|
163 | - ]); |
|
164 | - } |
|
154 | + /** |
|
155 | + * @return void |
|
156 | + */ |
|
157 | + public function routerTogglePinned(array $request) |
|
158 | + { |
|
159 | + $isPinned = $this->execute(new TogglePinned($request)); |
|
160 | + wp_send_json_success([ |
|
161 | + 'notices' => glsr(Notice::class)->get(), |
|
162 | + 'pinned' => $isPinned, |
|
163 | + ]); |
|
164 | + } |
|
165 | 165 | } |
@@ -15,9 +15,9 @@ discard block |
||
15 | 15 | /** |
16 | 16 | * @return void |
17 | 17 | */ |
18 | - public function routerChangeStatus(array $request) |
|
18 | + public function routerChangeStatus( array $request ) |
|
19 | 19 | { |
20 | - wp_send_json_success($this->execute(new ChangeStatus($request))); |
|
20 | + wp_send_json_success( $this->execute( new ChangeStatus( $request ) ) ); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | /** |
@@ -25,11 +25,11 @@ discard block |
||
25 | 25 | */ |
26 | 26 | public function routerClearConsole() |
27 | 27 | { |
28 | - glsr(AdminController::class)->routerClearConsole(); |
|
29 | - wp_send_json_success([ |
|
30 | - 'console' => glsr(Console::class)->get(), |
|
31 | - 'notices' => glsr(Notice::class)->get(), |
|
32 | - ]); |
|
28 | + glsr( AdminController::class )->routerClearConsole(); |
|
29 | + wp_send_json_success( [ |
|
30 | + 'console' => glsr( Console::class )->get(), |
|
31 | + 'notices' => glsr( Notice::class )->get(), |
|
32 | + ] ); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
@@ -37,23 +37,23 @@ discard block |
||
37 | 37 | */ |
38 | 38 | public function routerCountReviews() |
39 | 39 | { |
40 | - glsr(AdminController::class)->routerCountReviews(); |
|
41 | - wp_send_json_success([ |
|
42 | - 'notices' => glsr(Notice::class)->get(), |
|
43 | - ]); |
|
40 | + glsr( AdminController::class )->routerCountReviews(); |
|
41 | + wp_send_json_success( [ |
|
42 | + 'notices' => glsr( Notice::class )->get(), |
|
43 | + ] ); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
47 | 47 | * @return void |
48 | 48 | */ |
49 | - public function routerMceShortcode(array $request) |
|
49 | + public function routerMceShortcode( array $request ) |
|
50 | 50 | { |
51 | 51 | $shortcode = $request['shortcode']; |
52 | 52 | $response = false; |
53 | - if (array_key_exists($shortcode, glsr()->mceShortcodes)) { |
|
53 | + if( array_key_exists( $shortcode, glsr()->mceShortcodes ) ) { |
|
54 | 54 | $data = glsr()->mceShortcodes[$shortcode]; |
55 | - if (!empty($data['errors'])) { |
|
56 | - $data['btn_okay'] = [esc_html__('Okay', 'site-reviews')]; |
|
55 | + if( !empty($data['errors']) ) { |
|
56 | + $data['btn_okay'] = [esc_html__( 'Okay', 'site-reviews' )]; |
|
57 | 57 | } |
58 | 58 | $response = [ |
59 | 59 | 'body' => $data['fields'], |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | 'title' => $data['title'], |
64 | 64 | ]; |
65 | 65 | } |
66 | - wp_send_json_success($response); |
|
66 | + wp_send_json_success( $response ); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -71,95 +71,95 @@ discard block |
||
71 | 71 | */ |
72 | 72 | public function routerFetchConsole() |
73 | 73 | { |
74 | - glsr(AdminController::class)->routerFetchConsole(); |
|
75 | - wp_send_json_success([ |
|
76 | - 'console' => glsr(Console::class)->get(), |
|
77 | - 'notices' => glsr(Notice::class)->get(), |
|
78 | - ]); |
|
74 | + glsr( AdminController::class )->routerFetchConsole(); |
|
75 | + wp_send_json_success( [ |
|
76 | + 'console' => glsr( Console::class )->get(), |
|
77 | + 'notices' => glsr( Notice::class )->get(), |
|
78 | + ] ); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
82 | 82 | * @return void |
83 | 83 | */ |
84 | - public function routerSearchPosts(array $request) |
|
84 | + public function routerSearchPosts( array $request ) |
|
85 | 85 | { |
86 | - $results = glsr(Database::class)->searchPosts($request['search']); |
|
87 | - wp_send_json_success([ |
|
88 | - 'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>', |
|
86 | + $results = glsr( Database::class )->searchPosts( $request['search'] ); |
|
87 | + wp_send_json_success( [ |
|
88 | + 'empty' => '<div>'.__( 'Nothing found.', 'site-reviews' ).'</div>', |
|
89 | 89 | 'items' => $results, |
90 | - ]); |
|
90 | + ] ); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
94 | 94 | * @return void |
95 | 95 | */ |
96 | - public function routerSearchTranslations(array $request) |
|
96 | + public function routerSearchTranslations( array $request ) |
|
97 | 97 | { |
98 | - if (empty($request['exclude'])) { |
|
98 | + if( empty($request['exclude']) ) { |
|
99 | 99 | $request['exclude'] = []; |
100 | 100 | } |
101 | - $results = glsr(Translation::class) |
|
102 | - ->search($request['search']) |
|
101 | + $results = glsr( Translation::class ) |
|
102 | + ->search( $request['search'] ) |
|
103 | 103 | ->exclude() |
104 | - ->exclude($request['exclude']) |
|
104 | + ->exclude( $request['exclude'] ) |
|
105 | 105 | ->renderResults(); |
106 | - wp_send_json_success([ |
|
107 | - 'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>', |
|
106 | + wp_send_json_success( [ |
|
107 | + 'empty' => '<div>'.__( 'Nothing found.', 'site-reviews' ).'</div>', |
|
108 | 108 | 'items' => $results, |
109 | - ]); |
|
109 | + ] ); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | /** |
113 | 113 | * @return void |
114 | 114 | */ |
115 | - public function routerSubmitReview(array $request) |
|
115 | + public function routerSubmitReview( array $request ) |
|
116 | 116 | { |
117 | - $command = glsr(PublicController::class)->routerSubmitReview($request); |
|
118 | - $redirect = trim(strval(get_post_meta($command->post_id, 'redirect_to', true))); |
|
119 | - $redirect = apply_filters('site-reviews/review/redirect', $redirect, $command); |
|
117 | + $command = glsr( PublicController::class )->routerSubmitReview( $request ); |
|
118 | + $redirect = trim( strval( get_post_meta( $command->post_id, 'redirect_to', true ) ) ); |
|
119 | + $redirect = apply_filters( 'site-reviews/review/redirect', $redirect, $command ); |
|
120 | 120 | $data = [ |
121 | - 'errors' => glsr()->sessionGet($command->form_id.'errors', false), |
|
122 | - 'message' => glsr()->sessionGet($command->form_id.'message', ''), |
|
123 | - 'recaptcha' => glsr()->sessionGet($command->form_id.'recaptcha', false), |
|
121 | + 'errors' => glsr()->sessionGet( $command->form_id.'errors', false ), |
|
122 | + 'message' => glsr()->sessionGet( $command->form_id.'message', '' ), |
|
123 | + 'recaptcha' => glsr()->sessionGet( $command->form_id.'recaptcha', false ), |
|
124 | 124 | 'redirect' => $redirect, |
125 | 125 | ]; |
126 | - if (false === $data['errors']) { |
|
126 | + if( false === $data['errors'] ) { |
|
127 | 127 | glsr()->sessionClear(); |
128 | - wp_send_json_success($data); |
|
128 | + wp_send_json_success( $data ); |
|
129 | 129 | } |
130 | - wp_send_json_error($data); |
|
130 | + wp_send_json_error( $data ); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | /** |
134 | 134 | * @return void |
135 | 135 | */ |
136 | - public function routerFetchPagedReviews(array $request) |
|
136 | + public function routerFetchPagedReviews( array $request ) |
|
137 | 137 | { |
138 | 138 | $urlQuery = []; |
139 | - parse_str(parse_url(glsr_get($request, 'url'), PHP_URL_QUERY), $urlQuery); |
|
139 | + parse_str( parse_url( glsr_get( $request, 'url' ), PHP_URL_QUERY ), $urlQuery ); |
|
140 | 140 | $args = [ |
141 | - 'paged' => glsr_get($urlQuery, glsr()->constant('PAGED_QUERY_VAR'), 1), |
|
142 | - 'pagedUrl' => home_url(parse_url(glsr_get($request, 'url'), PHP_URL_PATH)), |
|
141 | + 'paged' => glsr_get( $urlQuery, glsr()->constant( 'PAGED_QUERY_VAR' ), 1 ), |
|
142 | + 'pagedUrl' => home_url( parse_url( glsr_get( $request, 'url' ), PHP_URL_PATH ) ), |
|
143 | 143 | 'pagination' => 'ajax', |
144 | 144 | 'schema' => false, |
145 | 145 | ]; |
146 | - $atts = (array) json_decode(glsr_get($request, 'atts')); |
|
147 | - $html = glsr(SiteReviews::class)->build(wp_parse_args($args, $atts)); |
|
148 | - return wp_send_json_success([ |
|
146 | + $atts = (array)json_decode( glsr_get( $request, 'atts' ) ); |
|
147 | + $html = glsr( SiteReviews::class )->build( wp_parse_args( $args, $atts ) ); |
|
148 | + return wp_send_json_success( [ |
|
149 | 149 | 'pagination' => $html->getPagination(), |
150 | 150 | 'reviews' => $html->getReviews(), |
151 | - ]); |
|
151 | + ] ); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | /** |
155 | 155 | * @return void |
156 | 156 | */ |
157 | - public function routerTogglePinned(array $request) |
|
157 | + public function routerTogglePinned( array $request ) |
|
158 | 158 | { |
159 | - $isPinned = $this->execute(new TogglePinned($request)); |
|
160 | - wp_send_json_success([ |
|
161 | - 'notices' => glsr(Notice::class)->get(), |
|
159 | + $isPinned = $this->execute( new TogglePinned( $request ) ); |
|
160 | + wp_send_json_success( [ |
|
161 | + 'notices' => glsr( Notice::class )->get(), |
|
162 | 162 | 'pinned' => $isPinned, |
163 | - ]); |
|
163 | + ] ); |
|
164 | 164 | } |
165 | 165 | } |
@@ -7,76 +7,76 @@ |
||
7 | 7 | |
8 | 8 | class Upgrader |
9 | 9 | { |
10 | - /** |
|
11 | - * @return string |
|
12 | - */ |
|
13 | - public $currentVersion; |
|
10 | + /** |
|
11 | + * @return string |
|
12 | + */ |
|
13 | + public $currentVersion; |
|
14 | 14 | |
15 | - /** |
|
16 | - * @return void |
|
17 | - */ |
|
18 | - public function run() |
|
19 | - { |
|
20 | - $filenames = []; |
|
21 | - $iterator = new DirectoryIterator(dirname(__FILE__).'/Upgrader'); |
|
22 | - foreach ($iterator as $fileinfo) { |
|
23 | - if (!$fileinfo->isFile()) { |
|
24 | - continue; |
|
25 | - } |
|
26 | - $filenames[] = $fileinfo->getFilename(); |
|
27 | - } |
|
28 | - natsort($filenames); |
|
29 | - $this->currentVersion = $this->currentVersion(); |
|
30 | - array_walk($filenames, function ($file) { |
|
31 | - $className = str_replace('.php', '', $file); |
|
32 | - $version = str_replace(['Upgrade_', '_'], ['', '.'], $className); |
|
33 | - $versionSuffix = preg_replace('/[\d.]+(.+)?/', '${1}', glsr()->version); // allow alpha/beta versions |
|
34 | - if ($this->currentVersion == '0.0.0' |
|
35 | - || version_compare($this->currentVersion, $version.$versionSuffix, '>=')) { |
|
36 | - return; |
|
37 | - } |
|
38 | - glsr('Modules\\Upgrader\\'.$className); |
|
39 | - glsr_log()->notice('Completed Upgrade for v'.$version.$versionSuffix); |
|
40 | - }); |
|
41 | - $this->finish(); |
|
42 | - } |
|
15 | + /** |
|
16 | + * @return void |
|
17 | + */ |
|
18 | + public function run() |
|
19 | + { |
|
20 | + $filenames = []; |
|
21 | + $iterator = new DirectoryIterator(dirname(__FILE__).'/Upgrader'); |
|
22 | + foreach ($iterator as $fileinfo) { |
|
23 | + if (!$fileinfo->isFile()) { |
|
24 | + continue; |
|
25 | + } |
|
26 | + $filenames[] = $fileinfo->getFilename(); |
|
27 | + } |
|
28 | + natsort($filenames); |
|
29 | + $this->currentVersion = $this->currentVersion(); |
|
30 | + array_walk($filenames, function ($file) { |
|
31 | + $className = str_replace('.php', '', $file); |
|
32 | + $version = str_replace(['Upgrade_', '_'], ['', '.'], $className); |
|
33 | + $versionSuffix = preg_replace('/[\d.]+(.+)?/', '${1}', glsr()->version); // allow alpha/beta versions |
|
34 | + if ($this->currentVersion == '0.0.0' |
|
35 | + || version_compare($this->currentVersion, $version.$versionSuffix, '>=')) { |
|
36 | + return; |
|
37 | + } |
|
38 | + glsr('Modules\\Upgrader\\'.$className); |
|
39 | + glsr_log()->notice('Completed Upgrade for v'.$version.$versionSuffix); |
|
40 | + }); |
|
41 | + $this->finish(); |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * @return void |
|
46 | - */ |
|
47 | - public function finish() |
|
48 | - { |
|
49 | - if ($this->currentVersion !== glsr()->version) { |
|
50 | - $this->setReviewCounts(); |
|
51 | - $this->updateVersionFrom($this->currentVersion); |
|
52 | - } elseif (!glsr(OptionManager::class)->get('last_review_count', false)) { |
|
53 | - $this->setReviewCounts(); |
|
54 | - } |
|
55 | - } |
|
44 | + /** |
|
45 | + * @return void |
|
46 | + */ |
|
47 | + public function finish() |
|
48 | + { |
|
49 | + if ($this->currentVersion !== glsr()->version) { |
|
50 | + $this->setReviewCounts(); |
|
51 | + $this->updateVersionFrom($this->currentVersion); |
|
52 | + } elseif (!glsr(OptionManager::class)->get('last_review_count', false)) { |
|
53 | + $this->setReviewCounts(); |
|
54 | + } |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * @return string |
|
59 | - */ |
|
60 | - protected function currentVersion() |
|
61 | - { |
|
62 | - return glsr(OptionManager::class)->get('version', '0.0.0'); |
|
63 | - } |
|
57 | + /** |
|
58 | + * @return string |
|
59 | + */ |
|
60 | + protected function currentVersion() |
|
61 | + { |
|
62 | + return glsr(OptionManager::class)->get('version', '0.0.0'); |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * @return void |
|
67 | - */ |
|
68 | - protected function setReviewCounts() |
|
69 | - { |
|
70 | - add_action('admin_init', 'glsr_calculate_ratings'); |
|
71 | - } |
|
65 | + /** |
|
66 | + * @return void |
|
67 | + */ |
|
68 | + protected function setReviewCounts() |
|
69 | + { |
|
70 | + add_action('admin_init', 'glsr_calculate_ratings'); |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * @param string $previousVersion |
|
75 | - * @return void |
|
76 | - */ |
|
77 | - protected function updateVersionFrom($previousVersion) |
|
78 | - { |
|
79 | - glsr(OptionManager::class)->set('version', glsr()->version); |
|
80 | - glsr(OptionManager::class)->set('version_upgraded_from', $previousVersion); |
|
81 | - } |
|
73 | + /** |
|
74 | + * @param string $previousVersion |
|
75 | + * @return void |
|
76 | + */ |
|
77 | + protected function updateVersionFrom($previousVersion) |
|
78 | + { |
|
79 | + glsr(OptionManager::class)->set('version', glsr()->version); |
|
80 | + glsr(OptionManager::class)->set('version_upgraded_from', $previousVersion); |
|
81 | + } |
|
82 | 82 | } |
@@ -18,25 +18,25 @@ discard block |
||
18 | 18 | public function run() |
19 | 19 | { |
20 | 20 | $filenames = []; |
21 | - $iterator = new DirectoryIterator(dirname(__FILE__).'/Upgrader'); |
|
22 | - foreach ($iterator as $fileinfo) { |
|
23 | - if (!$fileinfo->isFile()) { |
|
21 | + $iterator = new DirectoryIterator( dirname( __FILE__ ).'/Upgrader' ); |
|
22 | + foreach( $iterator as $fileinfo ) { |
|
23 | + if( !$fileinfo->isFile() ) { |
|
24 | 24 | continue; |
25 | 25 | } |
26 | 26 | $filenames[] = $fileinfo->getFilename(); |
27 | 27 | } |
28 | - natsort($filenames); |
|
28 | + natsort( $filenames ); |
|
29 | 29 | $this->currentVersion = $this->currentVersion(); |
30 | - array_walk($filenames, function ($file) { |
|
31 | - $className = str_replace('.php', '', $file); |
|
32 | - $version = str_replace(['Upgrade_', '_'], ['', '.'], $className); |
|
33 | - $versionSuffix = preg_replace('/[\d.]+(.+)?/', '${1}', glsr()->version); // allow alpha/beta versions |
|
34 | - if ($this->currentVersion == '0.0.0' |
|
35 | - || version_compare($this->currentVersion, $version.$versionSuffix, '>=')) { |
|
30 | + array_walk( $filenames, function( $file ) { |
|
31 | + $className = str_replace( '.php', '', $file ); |
|
32 | + $version = str_replace( ['Upgrade_', '_'], ['', '.'], $className ); |
|
33 | + $versionSuffix = preg_replace( '/[\d.]+(.+)?/', '${1}', glsr()->version ); // allow alpha/beta versions |
|
34 | + if( $this->currentVersion == '0.0.0' |
|
35 | + || version_compare( $this->currentVersion, $version.$versionSuffix, '>=' ) ) { |
|
36 | 36 | return; |
37 | 37 | } |
38 | - glsr('Modules\\Upgrader\\'.$className); |
|
39 | - glsr_log()->notice('Completed Upgrade for v'.$version.$versionSuffix); |
|
38 | + glsr( 'Modules\\Upgrader\\'.$className ); |
|
39 | + glsr_log()->notice( 'Completed Upgrade for v'.$version.$versionSuffix ); |
|
40 | 40 | }); |
41 | 41 | $this->finish(); |
42 | 42 | } |
@@ -46,10 +46,10 @@ discard block |
||
46 | 46 | */ |
47 | 47 | public function finish() |
48 | 48 | { |
49 | - if ($this->currentVersion !== glsr()->version) { |
|
49 | + if( $this->currentVersion !== glsr()->version ) { |
|
50 | 50 | $this->setReviewCounts(); |
51 | - $this->updateVersionFrom($this->currentVersion); |
|
52 | - } elseif (!glsr(OptionManager::class)->get('last_review_count', false)) { |
|
51 | + $this->updateVersionFrom( $this->currentVersion ); |
|
52 | + } elseif( !glsr( OptionManager::class )->get( 'last_review_count', false ) ) { |
|
53 | 53 | $this->setReviewCounts(); |
54 | 54 | } |
55 | 55 | } |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | */ |
60 | 60 | protected function currentVersion() |
61 | 61 | { |
62 | - return glsr(OptionManager::class)->get('version', '0.0.0'); |
|
62 | + return glsr( OptionManager::class )->get( 'version', '0.0.0' ); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
@@ -67,16 +67,16 @@ discard block |
||
67 | 67 | */ |
68 | 68 | protected function setReviewCounts() |
69 | 69 | { |
70 | - add_action('admin_init', 'glsr_calculate_ratings'); |
|
70 | + add_action( 'admin_init', 'glsr_calculate_ratings' ); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
74 | 74 | * @param string $previousVersion |
75 | 75 | * @return void |
76 | 76 | */ |
77 | - protected function updateVersionFrom($previousVersion) |
|
77 | + protected function updateVersionFrom( $previousVersion ) |
|
78 | 78 | { |
79 | - glsr(OptionManager::class)->set('version', glsr()->version); |
|
80 | - glsr(OptionManager::class)->set('version_upgraded_from', $previousVersion); |
|
79 | + glsr( OptionManager::class )->set( 'version', glsr()->version ); |
|
80 | + glsr( OptionManager::class )->set( 'version_upgraded_from', $previousVersion ); |
|
81 | 81 | } |
82 | 82 | } |
@@ -49,7 +49,8 @@ |
||
49 | 49 | if ($this->currentVersion !== glsr()->version) { |
50 | 50 | $this->setReviewCounts(); |
51 | 51 | $this->updateVersionFrom($this->currentVersion); |
52 | - } elseif (!glsr(OptionManager::class)->get('last_review_count', false)) { |
|
52 | + } |
|
53 | + elseif (!glsr(OptionManager::class)->get('last_review_count', false)) { |
|
53 | 54 | $this->setReviewCounts(); |
54 | 55 | } |
55 | 56 | } |
@@ -11,265 +11,265 @@ |
||
11 | 11 | |
12 | 12 | class ValidateReview |
13 | 13 | { |
14 | - const RECAPTCHA_ENDPOINT = 'https://www.google.com/recaptcha/api/siteverify'; |
|
14 | + const RECAPTCHA_ENDPOINT = 'https://www.google.com/recaptcha/api/siteverify'; |
|
15 | 15 | |
16 | - const RECAPTCHA_DISABLED = 0; |
|
17 | - const RECAPTCHA_EMPTY = 1; |
|
18 | - const RECAPTCHA_FAILED = 2; |
|
19 | - const RECAPTCHA_INVALID = 3; |
|
20 | - const RECAPTCHA_VALID = 4; |
|
16 | + const RECAPTCHA_DISABLED = 0; |
|
17 | + const RECAPTCHA_EMPTY = 1; |
|
18 | + const RECAPTCHA_FAILED = 2; |
|
19 | + const RECAPTCHA_INVALID = 3; |
|
20 | + const RECAPTCHA_VALID = 4; |
|
21 | 21 | |
22 | - const VALIDATION_RULES = [ |
|
23 | - 'content' => 'required', |
|
24 | - 'email' => 'required|email', |
|
25 | - 'name' => 'required', |
|
26 | - 'rating' => 'required|number|between:1,5', |
|
27 | - 'terms' => 'accepted', |
|
28 | - 'title' => 'required', |
|
29 | - ]; |
|
22 | + const VALIDATION_RULES = [ |
|
23 | + 'content' => 'required', |
|
24 | + 'email' => 'required|email', |
|
25 | + 'name' => 'required', |
|
26 | + 'rating' => 'required|number|between:1,5', |
|
27 | + 'terms' => 'accepted', |
|
28 | + 'title' => 'required', |
|
29 | + ]; |
|
30 | 30 | |
31 | - /** |
|
32 | - * @var string|void |
|
33 | - */ |
|
34 | - public $error; |
|
31 | + /** |
|
32 | + * @var string|void |
|
33 | + */ |
|
34 | + public $error; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @var string |
|
38 | - */ |
|
39 | - public $form_id; |
|
36 | + /** |
|
37 | + * @var string |
|
38 | + */ |
|
39 | + public $form_id; |
|
40 | 40 | |
41 | - /** |
|
42 | - * @var bool |
|
43 | - */ |
|
44 | - public $recaptchaIsUnset = false; |
|
41 | + /** |
|
42 | + * @var bool |
|
43 | + */ |
|
44 | + public $recaptchaIsUnset = false; |
|
45 | 45 | |
46 | - /** |
|
47 | - * @var array |
|
48 | - */ |
|
49 | - public $request; |
|
46 | + /** |
|
47 | + * @var array |
|
48 | + */ |
|
49 | + public $request; |
|
50 | 50 | |
51 | - /** |
|
52 | - * @var array |
|
53 | - */ |
|
54 | - protected $options; |
|
51 | + /** |
|
52 | + * @var array |
|
53 | + */ |
|
54 | + protected $options; |
|
55 | 55 | |
56 | - /** |
|
57 | - * @return static |
|
58 | - */ |
|
59 | - public function validate(array $request) |
|
60 | - { |
|
61 | - $this->form_id = $request['form_id']; |
|
62 | - $this->options = glsr(OptionManager::class)->all(); |
|
63 | - $this->request = $this->validateRequest($request); |
|
64 | - $this->validateCustom(); |
|
65 | - $this->validateHoneyPot(); |
|
66 | - $this->validateBlacklist(); |
|
67 | - $this->validateAkismet(); |
|
68 | - $this->validateRecaptcha(); |
|
69 | - if (!empty($this->error)) { |
|
70 | - $this->setSessionValues('message', $this->error); |
|
71 | - } |
|
72 | - return $this; |
|
73 | - } |
|
56 | + /** |
|
57 | + * @return static |
|
58 | + */ |
|
59 | + public function validate(array $request) |
|
60 | + { |
|
61 | + $this->form_id = $request['form_id']; |
|
62 | + $this->options = glsr(OptionManager::class)->all(); |
|
63 | + $this->request = $this->validateRequest($request); |
|
64 | + $this->validateCustom(); |
|
65 | + $this->validateHoneyPot(); |
|
66 | + $this->validateBlacklist(); |
|
67 | + $this->validateAkismet(); |
|
68 | + $this->validateRecaptcha(); |
|
69 | + if (!empty($this->error)) { |
|
70 | + $this->setSessionValues('message', $this->error); |
|
71 | + } |
|
72 | + return $this; |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * @param string $path |
|
77 | - * @param mixed $fallback |
|
78 | - * @return mixed |
|
79 | - */ |
|
80 | - protected function getOption($path, $fallback = '') |
|
81 | - { |
|
82 | - return glsr(Helper::class)->dataGet($this->options, $path, $fallback); |
|
83 | - } |
|
75 | + /** |
|
76 | + * @param string $path |
|
77 | + * @param mixed $fallback |
|
78 | + * @return mixed |
|
79 | + */ |
|
80 | + protected function getOption($path, $fallback = '') |
|
81 | + { |
|
82 | + return glsr(Helper::class)->dataGet($this->options, $path, $fallback); |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * @return int |
|
87 | - */ |
|
88 | - protected function getRecaptchaStatus() |
|
89 | - { |
|
90 | - if (!glsr(OptionManager::class)->isRecaptchaEnabled()) { |
|
91 | - return static::RECAPTCHA_DISABLED; |
|
92 | - } |
|
93 | - if (empty($this->request['_recaptcha-token'])) { |
|
94 | - return $this->request['_counter'] < intval(apply_filters('site-reviews/recaptcha/timeout', 5)) |
|
95 | - ? static::RECAPTCHA_EMPTY |
|
96 | - : static::RECAPTCHA_FAILED; |
|
97 | - } |
|
98 | - return $this->getRecaptchaTokenStatus(); |
|
99 | - } |
|
85 | + /** |
|
86 | + * @return int |
|
87 | + */ |
|
88 | + protected function getRecaptchaStatus() |
|
89 | + { |
|
90 | + if (!glsr(OptionManager::class)->isRecaptchaEnabled()) { |
|
91 | + return static::RECAPTCHA_DISABLED; |
|
92 | + } |
|
93 | + if (empty($this->request['_recaptcha-token'])) { |
|
94 | + return $this->request['_counter'] < intval(apply_filters('site-reviews/recaptcha/timeout', 5)) |
|
95 | + ? static::RECAPTCHA_EMPTY |
|
96 | + : static::RECAPTCHA_FAILED; |
|
97 | + } |
|
98 | + return $this->getRecaptchaTokenStatus(); |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * @return int |
|
103 | - */ |
|
104 | - protected function getRecaptchaTokenStatus() |
|
105 | - { |
|
106 | - $endpoint = add_query_arg([ |
|
107 | - 'remoteip' => glsr(Helper::class)->getIpAddress(), |
|
108 | - 'response' => $this->request['_recaptcha-token'], |
|
109 | - 'secret' => $this->getOption('settings.submissions.recaptcha.secret'), |
|
110 | - ], static::RECAPTCHA_ENDPOINT); |
|
111 | - if (is_wp_error($response = wp_remote_get($endpoint))) { |
|
112 | - glsr_log()->error($response->get_error_message()); |
|
113 | - return static::RECAPTCHA_FAILED; |
|
114 | - } |
|
115 | - $response = json_decode(wp_remote_retrieve_body($response)); |
|
116 | - if (!empty($response->success)) { |
|
117 | - return boolval($response->success) |
|
118 | - ? static::RECAPTCHA_VALID |
|
119 | - : static::RECAPTCHA_INVALID; |
|
120 | - } |
|
121 | - foreach ($response->{'error-codes'} as $error) { |
|
122 | - glsr_log()->error('reCAPTCHA error: '.$error); |
|
123 | - } |
|
124 | - return static::RECAPTCHA_INVALID; |
|
125 | - } |
|
101 | + /** |
|
102 | + * @return int |
|
103 | + */ |
|
104 | + protected function getRecaptchaTokenStatus() |
|
105 | + { |
|
106 | + $endpoint = add_query_arg([ |
|
107 | + 'remoteip' => glsr(Helper::class)->getIpAddress(), |
|
108 | + 'response' => $this->request['_recaptcha-token'], |
|
109 | + 'secret' => $this->getOption('settings.submissions.recaptcha.secret'), |
|
110 | + ], static::RECAPTCHA_ENDPOINT); |
|
111 | + if (is_wp_error($response = wp_remote_get($endpoint))) { |
|
112 | + glsr_log()->error($response->get_error_message()); |
|
113 | + return static::RECAPTCHA_FAILED; |
|
114 | + } |
|
115 | + $response = json_decode(wp_remote_retrieve_body($response)); |
|
116 | + if (!empty($response->success)) { |
|
117 | + return boolval($response->success) |
|
118 | + ? static::RECAPTCHA_VALID |
|
119 | + : static::RECAPTCHA_INVALID; |
|
120 | + } |
|
121 | + foreach ($response->{'error-codes'} as $error) { |
|
122 | + glsr_log()->error('reCAPTCHA error: '.$error); |
|
123 | + } |
|
124 | + return static::RECAPTCHA_INVALID; |
|
125 | + } |
|
126 | 126 | |
127 | - /** |
|
128 | - * @return array |
|
129 | - */ |
|
130 | - protected function getValidationRules(array $request) |
|
131 | - { |
|
132 | - $rules = array_intersect_key( |
|
133 | - apply_filters('site-reviews/validation/rules', static::VALIDATION_RULES, $request), |
|
134 | - array_flip($this->getOption('settings.submissions.required', [])) |
|
135 | - ); |
|
136 | - $excluded = explode(',', glsr_get($request, 'excluded')); |
|
137 | - return array_diff_key($rules, array_flip($excluded)); |
|
138 | - } |
|
127 | + /** |
|
128 | + * @return array |
|
129 | + */ |
|
130 | + protected function getValidationRules(array $request) |
|
131 | + { |
|
132 | + $rules = array_intersect_key( |
|
133 | + apply_filters('site-reviews/validation/rules', static::VALIDATION_RULES, $request), |
|
134 | + array_flip($this->getOption('settings.submissions.required', [])) |
|
135 | + ); |
|
136 | + $excluded = explode(',', glsr_get($request, 'excluded')); |
|
137 | + return array_diff_key($rules, array_flip($excluded)); |
|
138 | + } |
|
139 | 139 | |
140 | - /** |
|
141 | - * @return bool |
|
142 | - */ |
|
143 | - protected function isRequestValid(array $request) |
|
144 | - { |
|
145 | - $rules = $this->getValidationRules($request); |
|
146 | - $errors = glsr(Validator::class)->validate($request, $rules); |
|
147 | - if (empty($errors)) { |
|
148 | - return true; |
|
149 | - } |
|
150 | - $this->setSessionValues('errors', $errors); |
|
151 | - $this->setSessionValues('values', $request); |
|
152 | - return false; |
|
153 | - } |
|
140 | + /** |
|
141 | + * @return bool |
|
142 | + */ |
|
143 | + protected function isRequestValid(array $request) |
|
144 | + { |
|
145 | + $rules = $this->getValidationRules($request); |
|
146 | + $errors = glsr(Validator::class)->validate($request, $rules); |
|
147 | + if (empty($errors)) { |
|
148 | + return true; |
|
149 | + } |
|
150 | + $this->setSessionValues('errors', $errors); |
|
151 | + $this->setSessionValues('values', $request); |
|
152 | + return false; |
|
153 | + } |
|
154 | 154 | |
155 | - /** |
|
156 | - * @param string $type |
|
157 | - * @param mixed $value |
|
158 | - * @param string $loggedMessage |
|
159 | - * @return void |
|
160 | - */ |
|
161 | - protected function setSessionValues($type, $value, $loggedMessage = '') |
|
162 | - { |
|
163 | - glsr()->sessionSet($this->form_id.$type, $value); |
|
164 | - if (!empty($loggedMessage)) { |
|
165 | - glsr_log()->warning($loggedMessage)->debug($this->request); |
|
166 | - } |
|
167 | - } |
|
155 | + /** |
|
156 | + * @param string $type |
|
157 | + * @param mixed $value |
|
158 | + * @param string $loggedMessage |
|
159 | + * @return void |
|
160 | + */ |
|
161 | + protected function setSessionValues($type, $value, $loggedMessage = '') |
|
162 | + { |
|
163 | + glsr()->sessionSet($this->form_id.$type, $value); |
|
164 | + if (!empty($loggedMessage)) { |
|
165 | + glsr_log()->warning($loggedMessage)->debug($this->request); |
|
166 | + } |
|
167 | + } |
|
168 | 168 | |
169 | - /** |
|
170 | - * @return void |
|
171 | - */ |
|
172 | - protected function validateAkismet() |
|
173 | - { |
|
174 | - if (!empty($this->error)) { |
|
175 | - return; |
|
176 | - } |
|
177 | - if (!glsr(Akismet::class)->isSpam($this->request)) { |
|
178 | - return; |
|
179 | - } |
|
180 | - $this->setSessionValues('errors', [], 'Akismet caught a spam submission (consider adding the IP address to the blacklist):'); |
|
181 | - $this->error = __('This review has been flagged as possible spam and cannot be submitted.', 'site-reviews'); |
|
182 | - } |
|
169 | + /** |
|
170 | + * @return void |
|
171 | + */ |
|
172 | + protected function validateAkismet() |
|
173 | + { |
|
174 | + if (!empty($this->error)) { |
|
175 | + return; |
|
176 | + } |
|
177 | + if (!glsr(Akismet::class)->isSpam($this->request)) { |
|
178 | + return; |
|
179 | + } |
|
180 | + $this->setSessionValues('errors', [], 'Akismet caught a spam submission (consider adding the IP address to the blacklist):'); |
|
181 | + $this->error = __('This review has been flagged as possible spam and cannot be submitted.', 'site-reviews'); |
|
182 | + } |
|
183 | 183 | |
184 | - /** |
|
185 | - * @return void |
|
186 | - */ |
|
187 | - protected function validateBlacklist() |
|
188 | - { |
|
189 | - if (!empty($this->error)) { |
|
190 | - return; |
|
191 | - } |
|
192 | - if (!glsr(Blacklist::class)->isBlacklisted($this->request)) { |
|
193 | - return; |
|
194 | - } |
|
195 | - $blacklistAction = $this->getOption('settings.submissions.blacklist.action'); |
|
196 | - if ('reject' == $blacklistAction) { |
|
197 | - $this->setSessionValues('errors', [], 'Blacklisted submission detected:'); |
|
198 | - $this->error = __('Your review cannot be submitted at this time.', 'site-reviews'); |
|
199 | - return; |
|
200 | - } |
|
201 | - $this->request['blacklisted'] = true; |
|
202 | - } |
|
184 | + /** |
|
185 | + * @return void |
|
186 | + */ |
|
187 | + protected function validateBlacklist() |
|
188 | + { |
|
189 | + if (!empty($this->error)) { |
|
190 | + return; |
|
191 | + } |
|
192 | + if (!glsr(Blacklist::class)->isBlacklisted($this->request)) { |
|
193 | + return; |
|
194 | + } |
|
195 | + $blacklistAction = $this->getOption('settings.submissions.blacklist.action'); |
|
196 | + if ('reject' == $blacklistAction) { |
|
197 | + $this->setSessionValues('errors', [], 'Blacklisted submission detected:'); |
|
198 | + $this->error = __('Your review cannot be submitted at this time.', 'site-reviews'); |
|
199 | + return; |
|
200 | + } |
|
201 | + $this->request['blacklisted'] = true; |
|
202 | + } |
|
203 | 203 | |
204 | - /** |
|
205 | - * @return void |
|
206 | - */ |
|
207 | - protected function validateCustom() |
|
208 | - { |
|
209 | - if (!empty($this->error)) { |
|
210 | - return; |
|
211 | - } |
|
212 | - $validated = apply_filters('site-reviews/validate/custom', true, $this->request); |
|
213 | - if (true === $validated) { |
|
214 | - return; |
|
215 | - } |
|
216 | - $this->setSessionValues('errors', []); |
|
217 | - $this->setSessionValues('values', $this->request); |
|
218 | - $this->error = is_string($validated) |
|
219 | - ? $validated |
|
220 | - : __('The review submission failed. Please notify the site administrator.', 'site-reviews'); |
|
221 | - } |
|
204 | + /** |
|
205 | + * @return void |
|
206 | + */ |
|
207 | + protected function validateCustom() |
|
208 | + { |
|
209 | + if (!empty($this->error)) { |
|
210 | + return; |
|
211 | + } |
|
212 | + $validated = apply_filters('site-reviews/validate/custom', true, $this->request); |
|
213 | + if (true === $validated) { |
|
214 | + return; |
|
215 | + } |
|
216 | + $this->setSessionValues('errors', []); |
|
217 | + $this->setSessionValues('values', $this->request); |
|
218 | + $this->error = is_string($validated) |
|
219 | + ? $validated |
|
220 | + : __('The review submission failed. Please notify the site administrator.', 'site-reviews'); |
|
221 | + } |
|
222 | 222 | |
223 | - /** |
|
224 | - * @return void |
|
225 | - */ |
|
226 | - protected function validateHoneyPot() |
|
227 | - { |
|
228 | - if (!empty($this->error)) { |
|
229 | - return; |
|
230 | - } |
|
231 | - if (empty($this->request['gotcha'])) { |
|
232 | - return; |
|
233 | - } |
|
234 | - $this->setSessionValues('errors', [], 'The Honeypot caught a bad submission:'); |
|
235 | - $this->error = __('The review submission failed. Please notify the site administrator.', 'site-reviews'); |
|
236 | - } |
|
223 | + /** |
|
224 | + * @return void |
|
225 | + */ |
|
226 | + protected function validateHoneyPot() |
|
227 | + { |
|
228 | + if (!empty($this->error)) { |
|
229 | + return; |
|
230 | + } |
|
231 | + if (empty($this->request['gotcha'])) { |
|
232 | + return; |
|
233 | + } |
|
234 | + $this->setSessionValues('errors', [], 'The Honeypot caught a bad submission:'); |
|
235 | + $this->error = __('The review submission failed. Please notify the site administrator.', 'site-reviews'); |
|
236 | + } |
|
237 | 237 | |
238 | - /** |
|
239 | - * @return void |
|
240 | - */ |
|
241 | - protected function validateRecaptcha() |
|
242 | - { |
|
243 | - if (!empty($this->error)) { |
|
244 | - return; |
|
245 | - } |
|
246 | - $status = $this->getRecaptchaStatus(); |
|
247 | - if (in_array($status, [static::RECAPTCHA_DISABLED, static::RECAPTCHA_VALID])) { |
|
248 | - return; |
|
249 | - } |
|
250 | - if ($status == static::RECAPTCHA_EMPTY) { |
|
251 | - $this->setSessionValues('recaptcha', 'unset'); |
|
252 | - $this->recaptchaIsUnset = true; |
|
253 | - return; |
|
254 | - } |
|
255 | - $this->setSessionValues('errors', []); |
|
256 | - $this->setSessionValues('recaptcha', 'reset'); |
|
257 | - $errors = [ |
|
258 | - static::RECAPTCHA_FAILED => __('The reCAPTCHA failed to load, please refresh the page and try again.', 'site-reviews'), |
|
259 | - static::RECAPTCHA_INVALID => __('The reCAPTCHA verification failed, please try again.', 'site-reviews'), |
|
260 | - ]; |
|
261 | - $this->error = $errors[$status]; |
|
262 | - } |
|
238 | + /** |
|
239 | + * @return void |
|
240 | + */ |
|
241 | + protected function validateRecaptcha() |
|
242 | + { |
|
243 | + if (!empty($this->error)) { |
|
244 | + return; |
|
245 | + } |
|
246 | + $status = $this->getRecaptchaStatus(); |
|
247 | + if (in_array($status, [static::RECAPTCHA_DISABLED, static::RECAPTCHA_VALID])) { |
|
248 | + return; |
|
249 | + } |
|
250 | + if ($status == static::RECAPTCHA_EMPTY) { |
|
251 | + $this->setSessionValues('recaptcha', 'unset'); |
|
252 | + $this->recaptchaIsUnset = true; |
|
253 | + return; |
|
254 | + } |
|
255 | + $this->setSessionValues('errors', []); |
|
256 | + $this->setSessionValues('recaptcha', 'reset'); |
|
257 | + $errors = [ |
|
258 | + static::RECAPTCHA_FAILED => __('The reCAPTCHA failed to load, please refresh the page and try again.', 'site-reviews'), |
|
259 | + static::RECAPTCHA_INVALID => __('The reCAPTCHA verification failed, please try again.', 'site-reviews'), |
|
260 | + ]; |
|
261 | + $this->error = $errors[$status]; |
|
262 | + } |
|
263 | 263 | |
264 | - /** |
|
265 | - * @return array |
|
266 | - */ |
|
267 | - protected function validateRequest(array $request) |
|
268 | - { |
|
269 | - if (!$this->isRequestValid($request)) { |
|
270 | - $this->error = __('Please fix the submission errors.', 'site-reviews'); |
|
271 | - return $request; |
|
272 | - } |
|
273 | - return array_merge(glsr(ValidateReviewDefaults::class)->defaults(), $request); |
|
274 | - } |
|
264 | + /** |
|
265 | + * @return array |
|
266 | + */ |
|
267 | + protected function validateRequest(array $request) |
|
268 | + { |
|
269 | + if (!$this->isRequestValid($request)) { |
|
270 | + $this->error = __('Please fix the submission errors.', 'site-reviews'); |
|
271 | + return $request; |
|
272 | + } |
|
273 | + return array_merge(glsr(ValidateReviewDefaults::class)->defaults(), $request); |
|
274 | + } |
|
275 | 275 | } |
@@ -56,18 +56,18 @@ discard block |
||
56 | 56 | /** |
57 | 57 | * @return static |
58 | 58 | */ |
59 | - public function validate(array $request) |
|
59 | + public function validate( array $request ) |
|
60 | 60 | { |
61 | 61 | $this->form_id = $request['form_id']; |
62 | - $this->options = glsr(OptionManager::class)->all(); |
|
63 | - $this->request = $this->validateRequest($request); |
|
62 | + $this->options = glsr( OptionManager::class )->all(); |
|
63 | + $this->request = $this->validateRequest( $request ); |
|
64 | 64 | $this->validateCustom(); |
65 | 65 | $this->validateHoneyPot(); |
66 | 66 | $this->validateBlacklist(); |
67 | 67 | $this->validateAkismet(); |
68 | 68 | $this->validateRecaptcha(); |
69 | - if (!empty($this->error)) { |
|
70 | - $this->setSessionValues('message', $this->error); |
|
69 | + if( !empty($this->error) ) { |
|
70 | + $this->setSessionValues( 'message', $this->error ); |
|
71 | 71 | } |
72 | 72 | return $this; |
73 | 73 | } |
@@ -77,9 +77,9 @@ discard block |
||
77 | 77 | * @param mixed $fallback |
78 | 78 | * @return mixed |
79 | 79 | */ |
80 | - protected function getOption($path, $fallback = '') |
|
80 | + protected function getOption( $path, $fallback = '' ) |
|
81 | 81 | { |
82 | - return glsr(Helper::class)->dataGet($this->options, $path, $fallback); |
|
82 | + return glsr( Helper::class )->dataGet( $this->options, $path, $fallback ); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
@@ -87,11 +87,11 @@ discard block |
||
87 | 87 | */ |
88 | 88 | protected function getRecaptchaStatus() |
89 | 89 | { |
90 | - if (!glsr(OptionManager::class)->isRecaptchaEnabled()) { |
|
90 | + if( !glsr( OptionManager::class )->isRecaptchaEnabled() ) { |
|
91 | 91 | return static::RECAPTCHA_DISABLED; |
92 | 92 | } |
93 | - if (empty($this->request['_recaptcha-token'])) { |
|
94 | - return $this->request['_counter'] < intval(apply_filters('site-reviews/recaptcha/timeout', 5)) |
|
93 | + if( empty($this->request['_recaptcha-token']) ) { |
|
94 | + return $this->request['_counter'] < intval( apply_filters( 'site-reviews/recaptcha/timeout', 5 ) ) |
|
95 | 95 | ? static::RECAPTCHA_EMPTY |
96 | 96 | : static::RECAPTCHA_FAILED; |
97 | 97 | } |
@@ -103,23 +103,23 @@ discard block |
||
103 | 103 | */ |
104 | 104 | protected function getRecaptchaTokenStatus() |
105 | 105 | { |
106 | - $endpoint = add_query_arg([ |
|
107 | - 'remoteip' => glsr(Helper::class)->getIpAddress(), |
|
106 | + $endpoint = add_query_arg( [ |
|
107 | + 'remoteip' => glsr( Helper::class )->getIpAddress(), |
|
108 | 108 | 'response' => $this->request['_recaptcha-token'], |
109 | - 'secret' => $this->getOption('settings.submissions.recaptcha.secret'), |
|
110 | - ], static::RECAPTCHA_ENDPOINT); |
|
111 | - if (is_wp_error($response = wp_remote_get($endpoint))) { |
|
112 | - glsr_log()->error($response->get_error_message()); |
|
109 | + 'secret' => $this->getOption( 'settings.submissions.recaptcha.secret' ), |
|
110 | + ], static::RECAPTCHA_ENDPOINT ); |
|
111 | + if( is_wp_error( $response = wp_remote_get( $endpoint ) ) ) { |
|
112 | + glsr_log()->error( $response->get_error_message() ); |
|
113 | 113 | return static::RECAPTCHA_FAILED; |
114 | 114 | } |
115 | - $response = json_decode(wp_remote_retrieve_body($response)); |
|
116 | - if (!empty($response->success)) { |
|
117 | - return boolval($response->success) |
|
115 | + $response = json_decode( wp_remote_retrieve_body( $response ) ); |
|
116 | + if( !empty($response->success) ) { |
|
117 | + return boolval( $response->success ) |
|
118 | 118 | ? static::RECAPTCHA_VALID |
119 | 119 | : static::RECAPTCHA_INVALID; |
120 | 120 | } |
121 | - foreach ($response->{'error-codes'} as $error) { |
|
122 | - glsr_log()->error('reCAPTCHA error: '.$error); |
|
121 | + foreach( $response->{'error-codes'} as $error ) { |
|
122 | + glsr_log()->error( 'reCAPTCHA error: '.$error ); |
|
123 | 123 | } |
124 | 124 | return static::RECAPTCHA_INVALID; |
125 | 125 | } |
@@ -127,28 +127,28 @@ discard block |
||
127 | 127 | /** |
128 | 128 | * @return array |
129 | 129 | */ |
130 | - protected function getValidationRules(array $request) |
|
130 | + protected function getValidationRules( array $request ) |
|
131 | 131 | { |
132 | 132 | $rules = array_intersect_key( |
133 | - apply_filters('site-reviews/validation/rules', static::VALIDATION_RULES, $request), |
|
134 | - array_flip($this->getOption('settings.submissions.required', [])) |
|
133 | + apply_filters( 'site-reviews/validation/rules', static::VALIDATION_RULES, $request ), |
|
134 | + array_flip( $this->getOption( 'settings.submissions.required', [] ) ) |
|
135 | 135 | ); |
136 | - $excluded = explode(',', glsr_get($request, 'excluded')); |
|
137 | - return array_diff_key($rules, array_flip($excluded)); |
|
136 | + $excluded = explode( ',', glsr_get( $request, 'excluded' ) ); |
|
137 | + return array_diff_key( $rules, array_flip( $excluded ) ); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
141 | 141 | * @return bool |
142 | 142 | */ |
143 | - protected function isRequestValid(array $request) |
|
143 | + protected function isRequestValid( array $request ) |
|
144 | 144 | { |
145 | - $rules = $this->getValidationRules($request); |
|
146 | - $errors = glsr(Validator::class)->validate($request, $rules); |
|
147 | - if (empty($errors)) { |
|
145 | + $rules = $this->getValidationRules( $request ); |
|
146 | + $errors = glsr( Validator::class )->validate( $request, $rules ); |
|
147 | + if( empty($errors) ) { |
|
148 | 148 | return true; |
149 | 149 | } |
150 | - $this->setSessionValues('errors', $errors); |
|
151 | - $this->setSessionValues('values', $request); |
|
150 | + $this->setSessionValues( 'errors', $errors ); |
|
151 | + $this->setSessionValues( 'values', $request ); |
|
152 | 152 | return false; |
153 | 153 | } |
154 | 154 | |
@@ -158,11 +158,11 @@ discard block |
||
158 | 158 | * @param string $loggedMessage |
159 | 159 | * @return void |
160 | 160 | */ |
161 | - protected function setSessionValues($type, $value, $loggedMessage = '') |
|
161 | + protected function setSessionValues( $type, $value, $loggedMessage = '' ) |
|
162 | 162 | { |
163 | - glsr()->sessionSet($this->form_id.$type, $value); |
|
164 | - if (!empty($loggedMessage)) { |
|
165 | - glsr_log()->warning($loggedMessage)->debug($this->request); |
|
163 | + glsr()->sessionSet( $this->form_id.$type, $value ); |
|
164 | + if( !empty($loggedMessage) ) { |
|
165 | + glsr_log()->warning( $loggedMessage )->debug( $this->request ); |
|
166 | 166 | } |
167 | 167 | } |
168 | 168 | |
@@ -171,14 +171,14 @@ discard block |
||
171 | 171 | */ |
172 | 172 | protected function validateAkismet() |
173 | 173 | { |
174 | - if (!empty($this->error)) { |
|
174 | + if( !empty($this->error) ) { |
|
175 | 175 | return; |
176 | 176 | } |
177 | - if (!glsr(Akismet::class)->isSpam($this->request)) { |
|
177 | + if( !glsr( Akismet::class )->isSpam( $this->request ) ) { |
|
178 | 178 | return; |
179 | 179 | } |
180 | - $this->setSessionValues('errors', [], 'Akismet caught a spam submission (consider adding the IP address to the blacklist):'); |
|
181 | - $this->error = __('This review has been flagged as possible spam and cannot be submitted.', 'site-reviews'); |
|
180 | + $this->setSessionValues( 'errors', [], 'Akismet caught a spam submission (consider adding the IP address to the blacklist):' ); |
|
181 | + $this->error = __( 'This review has been flagged as possible spam and cannot be submitted.', 'site-reviews' ); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
@@ -186,16 +186,16 @@ discard block |
||
186 | 186 | */ |
187 | 187 | protected function validateBlacklist() |
188 | 188 | { |
189 | - if (!empty($this->error)) { |
|
189 | + if( !empty($this->error) ) { |
|
190 | 190 | return; |
191 | 191 | } |
192 | - if (!glsr(Blacklist::class)->isBlacklisted($this->request)) { |
|
192 | + if( !glsr( Blacklist::class )->isBlacklisted( $this->request ) ) { |
|
193 | 193 | return; |
194 | 194 | } |
195 | - $blacklistAction = $this->getOption('settings.submissions.blacklist.action'); |
|
196 | - if ('reject' == $blacklistAction) { |
|
197 | - $this->setSessionValues('errors', [], 'Blacklisted submission detected:'); |
|
198 | - $this->error = __('Your review cannot be submitted at this time.', 'site-reviews'); |
|
195 | + $blacklistAction = $this->getOption( 'settings.submissions.blacklist.action' ); |
|
196 | + if( 'reject' == $blacklistAction ) { |
|
197 | + $this->setSessionValues( 'errors', [], 'Blacklisted submission detected:' ); |
|
198 | + $this->error = __( 'Your review cannot be submitted at this time.', 'site-reviews' ); |
|
199 | 199 | return; |
200 | 200 | } |
201 | 201 | $this->request['blacklisted'] = true; |
@@ -206,18 +206,18 @@ discard block |
||
206 | 206 | */ |
207 | 207 | protected function validateCustom() |
208 | 208 | { |
209 | - if (!empty($this->error)) { |
|
209 | + if( !empty($this->error) ) { |
|
210 | 210 | return; |
211 | 211 | } |
212 | - $validated = apply_filters('site-reviews/validate/custom', true, $this->request); |
|
213 | - if (true === $validated) { |
|
212 | + $validated = apply_filters( 'site-reviews/validate/custom', true, $this->request ); |
|
213 | + if( true === $validated ) { |
|
214 | 214 | return; |
215 | 215 | } |
216 | - $this->setSessionValues('errors', []); |
|
217 | - $this->setSessionValues('values', $this->request); |
|
218 | - $this->error = is_string($validated) |
|
216 | + $this->setSessionValues( 'errors', [] ); |
|
217 | + $this->setSessionValues( 'values', $this->request ); |
|
218 | + $this->error = is_string( $validated ) |
|
219 | 219 | ? $validated |
220 | - : __('The review submission failed. Please notify the site administrator.', 'site-reviews'); |
|
220 | + : __( 'The review submission failed. Please notify the site administrator.', 'site-reviews' ); |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | /** |
@@ -225,14 +225,14 @@ discard block |
||
225 | 225 | */ |
226 | 226 | protected function validateHoneyPot() |
227 | 227 | { |
228 | - if (!empty($this->error)) { |
|
228 | + if( !empty($this->error) ) { |
|
229 | 229 | return; |
230 | 230 | } |
231 | - if (empty($this->request['gotcha'])) { |
|
231 | + if( empty($this->request['gotcha']) ) { |
|
232 | 232 | return; |
233 | 233 | } |
234 | - $this->setSessionValues('errors', [], 'The Honeypot caught a bad submission:'); |
|
235 | - $this->error = __('The review submission failed. Please notify the site administrator.', 'site-reviews'); |
|
234 | + $this->setSessionValues( 'errors', [], 'The Honeypot caught a bad submission:' ); |
|
235 | + $this->error = __( 'The review submission failed. Please notify the site administrator.', 'site-reviews' ); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | /** |
@@ -240,23 +240,23 @@ discard block |
||
240 | 240 | */ |
241 | 241 | protected function validateRecaptcha() |
242 | 242 | { |
243 | - if (!empty($this->error)) { |
|
243 | + if( !empty($this->error) ) { |
|
244 | 244 | return; |
245 | 245 | } |
246 | 246 | $status = $this->getRecaptchaStatus(); |
247 | - if (in_array($status, [static::RECAPTCHA_DISABLED, static::RECAPTCHA_VALID])) { |
|
247 | + if( in_array( $status, [static::RECAPTCHA_DISABLED, static::RECAPTCHA_VALID] ) ) { |
|
248 | 248 | return; |
249 | 249 | } |
250 | - if ($status == static::RECAPTCHA_EMPTY) { |
|
251 | - $this->setSessionValues('recaptcha', 'unset'); |
|
250 | + if( $status == static::RECAPTCHA_EMPTY ) { |
|
251 | + $this->setSessionValues( 'recaptcha', 'unset' ); |
|
252 | 252 | $this->recaptchaIsUnset = true; |
253 | 253 | return; |
254 | 254 | } |
255 | - $this->setSessionValues('errors', []); |
|
256 | - $this->setSessionValues('recaptcha', 'reset'); |
|
255 | + $this->setSessionValues( 'errors', [] ); |
|
256 | + $this->setSessionValues( 'recaptcha', 'reset' ); |
|
257 | 257 | $errors = [ |
258 | - static::RECAPTCHA_FAILED => __('The reCAPTCHA failed to load, please refresh the page and try again.', 'site-reviews'), |
|
259 | - static::RECAPTCHA_INVALID => __('The reCAPTCHA verification failed, please try again.', 'site-reviews'), |
|
258 | + static::RECAPTCHA_FAILED => __( 'The reCAPTCHA failed to load, please refresh the page and try again.', 'site-reviews' ), |
|
259 | + static::RECAPTCHA_INVALID => __( 'The reCAPTCHA verification failed, please try again.', 'site-reviews' ), |
|
260 | 260 | ]; |
261 | 261 | $this->error = $errors[$status]; |
262 | 262 | } |
@@ -264,12 +264,12 @@ discard block |
||
264 | 264 | /** |
265 | 265 | * @return array |
266 | 266 | */ |
267 | - protected function validateRequest(array $request) |
|
267 | + protected function validateRequest( array $request ) |
|
268 | 268 | { |
269 | - if (!$this->isRequestValid($request)) { |
|
270 | - $this->error = __('Please fix the submission errors.', 'site-reviews'); |
|
269 | + if( !$this->isRequestValid( $request ) ) { |
|
270 | + $this->error = __( 'Please fix the submission errors.', 'site-reviews' ); |
|
271 | 271 | return $request; |
272 | 272 | } |
273 | - return array_merge(glsr(ValidateReviewDefaults::class)->defaults(), $request); |
|
273 | + return array_merge( glsr( ValidateReviewDefaults::class )->defaults(), $request ); |
|
274 | 274 | } |
275 | 275 | } |
@@ -10,17 +10,17 @@ |
||
10 | 10 | |
11 | 11 | class Provider implements ProviderContract |
12 | 12 | { |
13 | - /** |
|
14 | - * @return void |
|
15 | - */ |
|
16 | - public function register(Application $app) |
|
17 | - { |
|
18 | - $app->bind(Application::class, $app); |
|
19 | - $app->singleton(Actions::class, Actions::class); |
|
20 | - $app->singleton(Filters::class, Filters::class); |
|
21 | - $app->singleton(OptionManager::class, OptionManager::class); |
|
22 | - $app->singleton(Translator::class, Translator::class); |
|
23 | - $app->singleton(Translation::class, Translation::class); |
|
24 | - $app->singleton(MainController::class, MainController::class); // this goes last |
|
25 | - } |
|
13 | + /** |
|
14 | + * @return void |
|
15 | + */ |
|
16 | + public function register(Application $app) |
|
17 | + { |
|
18 | + $app->bind(Application::class, $app); |
|
19 | + $app->singleton(Actions::class, Actions::class); |
|
20 | + $app->singleton(Filters::class, Filters::class); |
|
21 | + $app->singleton(OptionManager::class, OptionManager::class); |
|
22 | + $app->singleton(Translator::class, Translator::class); |
|
23 | + $app->singleton(Translation::class, Translation::class); |
|
24 | + $app->singleton(MainController::class, MainController::class); // this goes last |
|
25 | + } |
|
26 | 26 | } |
@@ -13,14 +13,14 @@ |
||
13 | 13 | /** |
14 | 14 | * @return void |
15 | 15 | */ |
16 | - public function register(Application $app) |
|
16 | + public function register( Application $app ) |
|
17 | 17 | { |
18 | - $app->bind(Application::class, $app); |
|
19 | - $app->singleton(Actions::class, Actions::class); |
|
20 | - $app->singleton(Filters::class, Filters::class); |
|
21 | - $app->singleton(OptionManager::class, OptionManager::class); |
|
22 | - $app->singleton(Translator::class, Translator::class); |
|
23 | - $app->singleton(Translation::class, Translation::class); |
|
24 | - $app->singleton(MainController::class, MainController::class); // this goes last |
|
18 | + $app->bind( Application::class, $app ); |
|
19 | + $app->singleton( Actions::class, Actions::class ); |
|
20 | + $app->singleton( Filters::class, Filters::class ); |
|
21 | + $app->singleton( OptionManager::class, OptionManager::class ); |
|
22 | + $app->singleton( Translator::class, Translator::class ); |
|
23 | + $app->singleton( Translation::class, Translation::class ); |
|
24 | + $app->singleton( MainController::class, MainController::class ); // this goes last |
|
25 | 25 | } |
26 | 26 | } |