@@ -9,65 +9,65 @@ |
||
9 | 9 | |
10 | 10 | class Reviews extends ArrayObject |
11 | 11 | { |
12 | - /** |
|
13 | - * @var array |
|
14 | - */ |
|
15 | - public $args; |
|
12 | + /** |
|
13 | + * @var array |
|
14 | + */ |
|
15 | + public $args; |
|
16 | 16 | |
17 | - /** |
|
18 | - * @var int |
|
19 | - */ |
|
20 | - public $max_num_pages; |
|
17 | + /** |
|
18 | + * @var int |
|
19 | + */ |
|
20 | + public $max_num_pages; |
|
21 | 21 | |
22 | - /** |
|
23 | - * @var array |
|
24 | - */ |
|
25 | - public $reviews; |
|
22 | + /** |
|
23 | + * @var array |
|
24 | + */ |
|
25 | + public $reviews; |
|
26 | 26 | |
27 | - public function __construct(array $reviews, $maxPageCount, array $args) |
|
28 | - { |
|
29 | - $this->args = $args; |
|
30 | - $this->max_num_pages = $maxPageCount; |
|
31 | - $this->reviews = $reviews; |
|
32 | - parent::__construct($reviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS); |
|
33 | - } |
|
27 | + public function __construct(array $reviews, $maxPageCount, array $args) |
|
28 | + { |
|
29 | + $this->args = $args; |
|
30 | + $this->max_num_pages = $maxPageCount; |
|
31 | + $this->reviews = $reviews; |
|
32 | + parent::__construct($reviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS); |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * @return string |
|
37 | - */ |
|
38 | - public function __toString() |
|
39 | - { |
|
40 | - return (string) $this->build(); |
|
41 | - } |
|
35 | + /** |
|
36 | + * @return string |
|
37 | + */ |
|
38 | + public function __toString() |
|
39 | + { |
|
40 | + return (string) $this->build(); |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @return ReviewsHtml |
|
45 | - */ |
|
46 | - public function build() |
|
47 | - { |
|
48 | - $args = glsr(SiteReviewsDefaults::class)->merge($this->args); |
|
49 | - return glsr(SiteReviewsPartial::class)->build($args, $this); |
|
50 | - } |
|
43 | + /** |
|
44 | + * @return ReviewsHtml |
|
45 | + */ |
|
46 | + public function build() |
|
47 | + { |
|
48 | + $args = glsr(SiteReviewsDefaults::class)->merge($this->args); |
|
49 | + return glsr(SiteReviewsPartial::class)->build($args, $this); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * @param mixed $key |
|
54 | - * @return mixed |
|
55 | - */ |
|
56 | - public function offsetGet($key) |
|
57 | - { |
|
58 | - if (array_key_exists($key, $this->reviews)) { |
|
59 | - return $this->reviews[$key]; |
|
60 | - } |
|
61 | - return property_exists($this, $key) |
|
62 | - ? $this->$key |
|
63 | - : null; |
|
64 | - } |
|
52 | + /** |
|
53 | + * @param mixed $key |
|
54 | + * @return mixed |
|
55 | + */ |
|
56 | + public function offsetGet($key) |
|
57 | + { |
|
58 | + if (array_key_exists($key, $this->reviews)) { |
|
59 | + return $this->reviews[$key]; |
|
60 | + } |
|
61 | + return property_exists($this, $key) |
|
62 | + ? $this->$key |
|
63 | + : null; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @return void |
|
68 | - */ |
|
69 | - public function render() |
|
70 | - { |
|
71 | - echo $this->build(); |
|
72 | - } |
|
66 | + /** |
|
67 | + * @return void |
|
68 | + */ |
|
69 | + public function render() |
|
70 | + { |
|
71 | + echo $this->build(); |
|
72 | + } |
|
73 | 73 | } |
@@ -24,12 +24,12 @@ discard block |
||
24 | 24 | */ |
25 | 25 | public $reviews; |
26 | 26 | |
27 | - public function __construct(array $reviews, $maxPageCount, array $args) |
|
27 | + public function __construct( array $reviews, $maxPageCount, array $args ) |
|
28 | 28 | { |
29 | 29 | $this->args = $args; |
30 | 30 | $this->max_num_pages = $maxPageCount; |
31 | 31 | $this->reviews = $reviews; |
32 | - parent::__construct($reviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS); |
|
32 | + parent::__construct( $reviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS ); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | */ |
38 | 38 | public function __toString() |
39 | 39 | { |
40 | - return (string) $this->build(); |
|
40 | + return (string)$this->build(); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
@@ -45,20 +45,20 @@ discard block |
||
45 | 45 | */ |
46 | 46 | public function build() |
47 | 47 | { |
48 | - $args = glsr(SiteReviewsDefaults::class)->merge($this->args); |
|
49 | - return glsr(SiteReviewsPartial::class)->build($args, $this); |
|
48 | + $args = glsr( SiteReviewsDefaults::class )->merge( $this->args ); |
|
49 | + return glsr( SiteReviewsPartial::class )->build( $args, $this ); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
53 | 53 | * @param mixed $key |
54 | 54 | * @return mixed |
55 | 55 | */ |
56 | - public function offsetGet($key) |
|
56 | + public function offsetGet( $key ) |
|
57 | 57 | { |
58 | - if (array_key_exists($key, $this->reviews)) { |
|
58 | + if( array_key_exists( $key, $this->reviews ) ) { |
|
59 | 59 | return $this->reviews[$key]; |
60 | 60 | } |
61 | - return property_exists($this, $key) |
|
61 | + return property_exists( $this, $key ) |
|
62 | 62 | ? $this->$key |
63 | 63 | : null; |
64 | 64 | } |
@@ -207,7 +207,8 @@ |
||
207 | 207 | $this->bind($id, $addon); |
208 | 208 | $addon->init(); |
209 | 209 | } |
210 | - } catch(\ReflectionException $e) { |
|
210 | + } |
|
211 | + catch(\ReflectionException $e) { |
|
211 | 212 | glsr_log()->error('Attempted to register an invalid addon.'); |
212 | 213 | } |
213 | 214 | } |
@@ -18,357 +18,357 @@ |
||
18 | 18 | */ |
19 | 19 | final class Application extends Container |
20 | 20 | { |
21 | - const CAPABILITY = 'edit_others_posts'; |
|
22 | - const CRON_EVENT = 'site-reviews/schedule/session/purge'; |
|
23 | - const ID = 'site-reviews'; |
|
24 | - const PAGED_QUERY_VAR = 'reviews-page'; |
|
25 | - const POST_TYPE = 'site-review'; |
|
26 | - const PREFIX = 'glsr_'; |
|
27 | - const TAXONOMY = 'site-review-category'; |
|
21 | + const CAPABILITY = 'edit_others_posts'; |
|
22 | + const CRON_EVENT = 'site-reviews/schedule/session/purge'; |
|
23 | + const ID = 'site-reviews'; |
|
24 | + const PAGED_QUERY_VAR = 'reviews-page'; |
|
25 | + const POST_TYPE = 'site-review'; |
|
26 | + const PREFIX = 'glsr_'; |
|
27 | + const TAXONOMY = 'site-review-category'; |
|
28 | 28 | |
29 | - public $addons = []; |
|
30 | - public $defaults; |
|
31 | - public $deprecated = []; |
|
32 | - public $file; |
|
33 | - public $languages; |
|
34 | - public $mceShortcodes = []; //defined elsewhere |
|
35 | - public $name; |
|
36 | - public $postTypeColumns = []; // defined elsewhere |
|
37 | - public $reviewTypes; |
|
38 | - public $schemas = []; //defined elsewhere |
|
39 | - public $version; |
|
29 | + public $addons = []; |
|
30 | + public $defaults; |
|
31 | + public $deprecated = []; |
|
32 | + public $file; |
|
33 | + public $languages; |
|
34 | + public $mceShortcodes = []; //defined elsewhere |
|
35 | + public $name; |
|
36 | + public $postTypeColumns = []; // defined elsewhere |
|
37 | + public $reviewTypes; |
|
38 | + public $schemas = []; //defined elsewhere |
|
39 | + public $version; |
|
40 | 40 | |
41 | - public function __construct() |
|
42 | - { |
|
43 | - static::$instance = $this; |
|
44 | - $this->file = str_replace('plugin/Application', static::ID, (new ReflectionClass($this))->getFileName()); |
|
45 | - $plugin = get_file_data($this->file, [ |
|
46 | - 'languages' => 'Domain Path', |
|
47 | - 'name' => 'Plugin Name', |
|
48 | - 'version' => 'Version', |
|
49 | - ], 'plugin'); |
|
50 | - array_walk($plugin, function ($value, $key) { |
|
51 | - $this->$key = $value; |
|
52 | - }); |
|
53 | - } |
|
41 | + public function __construct() |
|
42 | + { |
|
43 | + static::$instance = $this; |
|
44 | + $this->file = str_replace('plugin/Application', static::ID, (new ReflectionClass($this))->getFileName()); |
|
45 | + $plugin = get_file_data($this->file, [ |
|
46 | + 'languages' => 'Domain Path', |
|
47 | + 'name' => 'Plugin Name', |
|
48 | + 'version' => 'Version', |
|
49 | + ], 'plugin'); |
|
50 | + array_walk($plugin, function ($value, $key) { |
|
51 | + $this->$key = $value; |
|
52 | + }); |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * @return void |
|
57 | - */ |
|
58 | - public function activate() |
|
59 | - { |
|
60 | - $this->scheduleCronJob(); |
|
61 | - add_option(static::ID.'activated', true); |
|
62 | - } |
|
55 | + /** |
|
56 | + * @return void |
|
57 | + */ |
|
58 | + public function activate() |
|
59 | + { |
|
60 | + $this->scheduleCronJob(); |
|
61 | + add_option(static::ID.'activated', true); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @param string $view |
|
66 | - * @return string |
|
67 | - */ |
|
68 | - public function build($view, array $data = []) |
|
69 | - { |
|
70 | - ob_start(); |
|
71 | - $this->render($view, $data); |
|
72 | - return ob_get_clean(); |
|
73 | - } |
|
64 | + /** |
|
65 | + * @param string $view |
|
66 | + * @return string |
|
67 | + */ |
|
68 | + public function build($view, array $data = []) |
|
69 | + { |
|
70 | + ob_start(); |
|
71 | + $this->render($view, $data); |
|
72 | + return ob_get_clean(); |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * @param string $capability |
|
77 | - * @return bool |
|
78 | - */ |
|
79 | - public function can($capability) |
|
80 | - { |
|
81 | - return $this->make(Role::class)->can($capability); |
|
82 | - } |
|
75 | + /** |
|
76 | + * @param string $capability |
|
77 | + * @return bool |
|
78 | + */ |
|
79 | + public function can($capability) |
|
80 | + { |
|
81 | + return $this->make(Role::class)->can($capability); |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * @return void |
|
86 | - */ |
|
87 | - public function catchFatalError() |
|
88 | - { |
|
89 | - $error = error_get_last(); |
|
90 | - if (E_ERROR !== $error['type'] || !Str::contains($error['message'], $this->path())) { |
|
91 | - return; |
|
92 | - } |
|
93 | - glsr_log()->error($error['message']); |
|
94 | - } |
|
84 | + /** |
|
85 | + * @return void |
|
86 | + */ |
|
87 | + public function catchFatalError() |
|
88 | + { |
|
89 | + $error = error_get_last(); |
|
90 | + if (E_ERROR !== $error['type'] || !Str::contains($error['message'], $this->path())) { |
|
91 | + return; |
|
92 | + } |
|
93 | + glsr_log()->error($error['message']); |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * @param string $name |
|
98 | - * @return array |
|
99 | - */ |
|
100 | - public function config($name) |
|
101 | - { |
|
102 | - $path = apply_filters('site-reviews/config', 'config/'.$name.'.php'); |
|
103 | - $configFile = $this->path($path); |
|
104 | - $config = file_exists($configFile) |
|
105 | - ? include $configFile |
|
106 | - : []; |
|
107 | - return apply_filters('site-reviews/config/'.$name, $config); |
|
108 | - } |
|
96 | + /** |
|
97 | + * @param string $name |
|
98 | + * @return array |
|
99 | + */ |
|
100 | + public function config($name) |
|
101 | + { |
|
102 | + $path = apply_filters('site-reviews/config', 'config/'.$name.'.php'); |
|
103 | + $configFile = $this->path($path); |
|
104 | + $config = file_exists($configFile) |
|
105 | + ? include $configFile |
|
106 | + : []; |
|
107 | + return apply_filters('site-reviews/config/'.$name, $config); |
|
108 | + } |
|
109 | 109 | |
110 | - /** |
|
111 | - * @param string $property |
|
112 | - * @return string |
|
113 | - */ |
|
114 | - public function constant($property, $className = 'static') |
|
115 | - { |
|
116 | - $constant = $className.'::'.$property; |
|
117 | - return defined($constant) |
|
118 | - ? apply_filters('site-reviews/const/'.$property, constant($constant)) |
|
119 | - : ''; |
|
120 | - } |
|
110 | + /** |
|
111 | + * @param string $property |
|
112 | + * @return string |
|
113 | + */ |
|
114 | + public function constant($property, $className = 'static') |
|
115 | + { |
|
116 | + $constant = $className.'::'.$property; |
|
117 | + return defined($constant) |
|
118 | + ? apply_filters('site-reviews/const/'.$property, constant($constant)) |
|
119 | + : ''; |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * @return void |
|
124 | - */ |
|
125 | - public function deactivate() |
|
126 | - { |
|
127 | - $this->unscheduleCronJob(); |
|
128 | - } |
|
122 | + /** |
|
123 | + * @return void |
|
124 | + */ |
|
125 | + public function deactivate() |
|
126 | + { |
|
127 | + $this->unscheduleCronJob(); |
|
128 | + } |
|
129 | 129 | |
130 | - /** |
|
131 | - * @param string $view |
|
132 | - * @return void|string |
|
133 | - */ |
|
134 | - public function file($view) |
|
135 | - { |
|
136 | - $view.= '.php'; |
|
137 | - $filePaths = []; |
|
138 | - if (Str::startsWith('templates/', $view)) { |
|
139 | - $filePaths[] = $this->themePath(Str::removePrefix('templates/', $view)); |
|
140 | - } |
|
141 | - $filePaths[] = $this->path($view); |
|
142 | - $filePaths[] = $this->path('views/'.$view); |
|
143 | - foreach ($filePaths as $file) { |
|
144 | - if (!file_exists($file)) { |
|
145 | - continue; |
|
146 | - } |
|
147 | - return $file; |
|
148 | - } |
|
149 | - } |
|
130 | + /** |
|
131 | + * @param string $view |
|
132 | + * @return void|string |
|
133 | + */ |
|
134 | + public function file($view) |
|
135 | + { |
|
136 | + $view.= '.php'; |
|
137 | + $filePaths = []; |
|
138 | + if (Str::startsWith('templates/', $view)) { |
|
139 | + $filePaths[] = $this->themePath(Str::removePrefix('templates/', $view)); |
|
140 | + } |
|
141 | + $filePaths[] = $this->path($view); |
|
142 | + $filePaths[] = $this->path('views/'.$view); |
|
143 | + foreach ($filePaths as $file) { |
|
144 | + if (!file_exists($file)) { |
|
145 | + continue; |
|
146 | + } |
|
147 | + return $file; |
|
148 | + } |
|
149 | + } |
|
150 | 150 | |
151 | - /** |
|
152 | - * @return array |
|
153 | - */ |
|
154 | - public function getDefaults() |
|
155 | - { |
|
156 | - if (empty($this->defaults)) { |
|
157 | - $this->defaults = $this->make(DefaultsManager::class)->get(); |
|
158 | - } |
|
159 | - return apply_filters('site-reviews/get/defaults', $this->defaults); |
|
160 | - } |
|
151 | + /** |
|
152 | + * @return array |
|
153 | + */ |
|
154 | + public function getDefaults() |
|
155 | + { |
|
156 | + if (empty($this->defaults)) { |
|
157 | + $this->defaults = $this->make(DefaultsManager::class)->get(); |
|
158 | + } |
|
159 | + return apply_filters('site-reviews/get/defaults', $this->defaults); |
|
160 | + } |
|
161 | 161 | |
162 | - /** |
|
163 | - * @param string $page |
|
164 | - * @param string $tab |
|
165 | - * @return string |
|
166 | - */ |
|
167 | - public function getPermission($page = '', $tab = 'index') |
|
168 | - { |
|
169 | - $fallback = 'edit_posts'; |
|
170 | - $permissions = [ |
|
171 | - 'addons' => 'install_plugins', |
|
172 | - 'documentation' => [ |
|
173 | - 'faq' => 'edit_others_posts', |
|
174 | - 'functions' => 'manage_options', |
|
175 | - 'hooks' => 'edit_others_posts', |
|
176 | - 'index' => 'edit_posts', |
|
177 | - 'support' => 'edit_others_posts', |
|
178 | - ], |
|
179 | - 'settings' => 'manage_options', |
|
180 | - 'tools' => [ |
|
181 | - 'console' => 'edit_others_posts', |
|
182 | - 'general' => 'edit_others_posts', |
|
183 | - 'index' => 'edit_others_posts', |
|
184 | - 'sync' => 'manage_options', |
|
185 | - 'system-info' => 'edit_others_posts', |
|
186 | - ] |
|
187 | - ]; |
|
188 | - $permission = Arr::get($permissions, $page, $fallback); |
|
189 | - if (is_array($permission)) { |
|
190 | - $permission = Arr::get($permission, $tab, $fallback); |
|
191 | - } |
|
192 | - return empty($permission) || !is_string($permission) |
|
193 | - ? $fallback |
|
194 | - : $permission; |
|
195 | - } |
|
162 | + /** |
|
163 | + * @param string $page |
|
164 | + * @param string $tab |
|
165 | + * @return string |
|
166 | + */ |
|
167 | + public function getPermission($page = '', $tab = 'index') |
|
168 | + { |
|
169 | + $fallback = 'edit_posts'; |
|
170 | + $permissions = [ |
|
171 | + 'addons' => 'install_plugins', |
|
172 | + 'documentation' => [ |
|
173 | + 'faq' => 'edit_others_posts', |
|
174 | + 'functions' => 'manage_options', |
|
175 | + 'hooks' => 'edit_others_posts', |
|
176 | + 'index' => 'edit_posts', |
|
177 | + 'support' => 'edit_others_posts', |
|
178 | + ], |
|
179 | + 'settings' => 'manage_options', |
|
180 | + 'tools' => [ |
|
181 | + 'console' => 'edit_others_posts', |
|
182 | + 'general' => 'edit_others_posts', |
|
183 | + 'index' => 'edit_others_posts', |
|
184 | + 'sync' => 'manage_options', |
|
185 | + 'system-info' => 'edit_others_posts', |
|
186 | + ] |
|
187 | + ]; |
|
188 | + $permission = Arr::get($permissions, $page, $fallback); |
|
189 | + if (is_array($permission)) { |
|
190 | + $permission = Arr::get($permission, $tab, $fallback); |
|
191 | + } |
|
192 | + return empty($permission) || !is_string($permission) |
|
193 | + ? $fallback |
|
194 | + : $permission; |
|
195 | + } |
|
196 | 196 | |
197 | - /** |
|
198 | - * @param string $page |
|
199 | - * @param string $tab |
|
200 | - * @return bool |
|
201 | - */ |
|
202 | - public function hasPermission($page = '', $tab = 'index') |
|
203 | - { |
|
204 | - $isAdmin = $this->isAdmin(); |
|
205 | - return !$isAdmin || ($isAdmin && $this->can($this->getPermission($page, $tab))); |
|
206 | - } |
|
197 | + /** |
|
198 | + * @param string $page |
|
199 | + * @param string $tab |
|
200 | + * @return bool |
|
201 | + */ |
|
202 | + public function hasPermission($page = '', $tab = 'index') |
|
203 | + { |
|
204 | + $isAdmin = $this->isAdmin(); |
|
205 | + return !$isAdmin || ($isAdmin && $this->can($this->getPermission($page, $tab))); |
|
206 | + } |
|
207 | 207 | |
208 | - /** |
|
209 | - * @return void |
|
210 | - */ |
|
211 | - public function init() |
|
212 | - { |
|
213 | - $this->make(Actions::class)->run(); |
|
214 | - $this->make(Filters::class)->run(); |
|
215 | - } |
|
208 | + /** |
|
209 | + * @return void |
|
210 | + */ |
|
211 | + public function init() |
|
212 | + { |
|
213 | + $this->make(Actions::class)->run(); |
|
214 | + $this->make(Filters::class)->run(); |
|
215 | + } |
|
216 | 216 | |
217 | - /** |
|
218 | - * @return bool |
|
219 | - */ |
|
220 | - public function isAdmin() |
|
221 | - { |
|
222 | - return is_admin() && !wp_doing_ajax(); |
|
223 | - } |
|
217 | + /** |
|
218 | + * @return bool |
|
219 | + */ |
|
220 | + public function isAdmin() |
|
221 | + { |
|
222 | + return is_admin() && !wp_doing_ajax(); |
|
223 | + } |
|
224 | 224 | |
225 | - /** |
|
226 | - * @param string $file |
|
227 | - * @return string |
|
228 | - */ |
|
229 | - public function path($file = '', $realpath = true) |
|
230 | - { |
|
231 | - $path = plugin_dir_path($this->file); |
|
232 | - if (!$realpath) { |
|
233 | - $path = trailingslashit(WP_PLUGIN_DIR).basename(dirname($this->file)); |
|
234 | - } |
|
235 | - $path = trailingslashit($path).ltrim(trim($file), '/'); |
|
236 | - return apply_filters('site-reviews/path', $path, $file); |
|
237 | - } |
|
225 | + /** |
|
226 | + * @param string $file |
|
227 | + * @return string |
|
228 | + */ |
|
229 | + public function path($file = '', $realpath = true) |
|
230 | + { |
|
231 | + $path = plugin_dir_path($this->file); |
|
232 | + if (!$realpath) { |
|
233 | + $path = trailingslashit(WP_PLUGIN_DIR).basename(dirname($this->file)); |
|
234 | + } |
|
235 | + $path = trailingslashit($path).ltrim(trim($file), '/'); |
|
236 | + return apply_filters('site-reviews/path', $path, $file); |
|
237 | + } |
|
238 | 238 | |
239 | - /** |
|
240 | - * @param object $addon |
|
241 | - * @return void |
|
242 | - */ |
|
243 | - public function register($addon) |
|
244 | - { |
|
245 | - try { |
|
246 | - $reflection = new \ReflectionClass($addon); |
|
247 | - if ($id = $reflection->getConstant('ID')) { |
|
248 | - $this->addons[] = $id; |
|
249 | - $this->bind($id, $addon); |
|
250 | - $addon->init(); |
|
251 | - } |
|
252 | - } catch(\ReflectionException $e) { |
|
253 | - glsr_log()->error('Attempted to register an invalid addon.'); |
|
254 | - } |
|
255 | - } |
|
239 | + /** |
|
240 | + * @param object $addon |
|
241 | + * @return void |
|
242 | + */ |
|
243 | + public function register($addon) |
|
244 | + { |
|
245 | + try { |
|
246 | + $reflection = new \ReflectionClass($addon); |
|
247 | + if ($id = $reflection->getConstant('ID')) { |
|
248 | + $this->addons[] = $id; |
|
249 | + $this->bind($id, $addon); |
|
250 | + $addon->init(); |
|
251 | + } |
|
252 | + } catch(\ReflectionException $e) { |
|
253 | + glsr_log()->error('Attempted to register an invalid addon.'); |
|
254 | + } |
|
255 | + } |
|
256 | 256 | |
257 | - /** |
|
258 | - * @return void |
|
259 | - */ |
|
260 | - public function registerAddons() |
|
261 | - { |
|
262 | - do_action('site-reviews/addon/register', $this); |
|
263 | - } |
|
257 | + /** |
|
258 | + * @return void |
|
259 | + */ |
|
260 | + public function registerAddons() |
|
261 | + { |
|
262 | + do_action('site-reviews/addon/register', $this); |
|
263 | + } |
|
264 | 264 | |
265 | - /** |
|
266 | - * @return void |
|
267 | - */ |
|
268 | - public function registerLanguages() |
|
269 | - { |
|
270 | - load_plugin_textdomain(static::ID, false, |
|
271 | - trailingslashit(plugin_basename($this->path()).'/'.$this->languages) |
|
272 | - ); |
|
273 | - } |
|
265 | + /** |
|
266 | + * @return void |
|
267 | + */ |
|
268 | + public function registerLanguages() |
|
269 | + { |
|
270 | + load_plugin_textdomain(static::ID, false, |
|
271 | + trailingslashit(plugin_basename($this->path()).'/'.$this->languages) |
|
272 | + ); |
|
273 | + } |
|
274 | 274 | |
275 | - /** |
|
276 | - * @return void |
|
277 | - */ |
|
278 | - public function registerReviewTypes() |
|
279 | - { |
|
280 | - $types = apply_filters('site-reviews/addon/types', []); |
|
281 | - $this->reviewTypes = wp_parse_args($types, [ |
|
282 | - 'local' => __('Local', 'site-reviews'), |
|
283 | - ]); |
|
284 | - } |
|
275 | + /** |
|
276 | + * @return void |
|
277 | + */ |
|
278 | + public function registerReviewTypes() |
|
279 | + { |
|
280 | + $types = apply_filters('site-reviews/addon/types', []); |
|
281 | + $this->reviewTypes = wp_parse_args($types, [ |
|
282 | + 'local' => __('Local', 'site-reviews'), |
|
283 | + ]); |
|
284 | + } |
|
285 | 285 | |
286 | - /** |
|
287 | - * @param string $view |
|
288 | - * @return void |
|
289 | - */ |
|
290 | - public function render($view, array $data = []) |
|
291 | - { |
|
292 | - $view = apply_filters('site-reviews/render/view', $view, $data); |
|
293 | - $file = apply_filters('site-reviews/views/file', $this->file($view), $view, $data); |
|
294 | - if (!file_exists($file)) { |
|
295 | - glsr_log()->error(sprintf('File not found: (%s) %s', $view, $file)); |
|
296 | - return; |
|
297 | - } |
|
298 | - $data = apply_filters('site-reviews/views/data', $data, $view); |
|
299 | - extract($data); |
|
300 | - include $file; |
|
301 | - } |
|
286 | + /** |
|
287 | + * @param string $view |
|
288 | + * @return void |
|
289 | + */ |
|
290 | + public function render($view, array $data = []) |
|
291 | + { |
|
292 | + $view = apply_filters('site-reviews/render/view', $view, $data); |
|
293 | + $file = apply_filters('site-reviews/views/file', $this->file($view), $view, $data); |
|
294 | + if (!file_exists($file)) { |
|
295 | + glsr_log()->error(sprintf('File not found: (%s) %s', $view, $file)); |
|
296 | + return; |
|
297 | + } |
|
298 | + $data = apply_filters('site-reviews/views/data', $data, $view); |
|
299 | + extract($data); |
|
300 | + include $file; |
|
301 | + } |
|
302 | 302 | |
303 | - /** |
|
304 | - * @return void |
|
305 | - */ |
|
306 | - public function scheduleCronJob() |
|
307 | - { |
|
308 | - if (false === wp_next_scheduled(static::CRON_EVENT)) { |
|
309 | - wp_schedule_event(time(), 'twicedaily', static::CRON_EVENT); |
|
310 | - } |
|
311 | - } |
|
303 | + /** |
|
304 | + * @return void |
|
305 | + */ |
|
306 | + public function scheduleCronJob() |
|
307 | + { |
|
308 | + if (false === wp_next_scheduled(static::CRON_EVENT)) { |
|
309 | + wp_schedule_event(time(), 'twicedaily', static::CRON_EVENT); |
|
310 | + } |
|
311 | + } |
|
312 | 312 | |
313 | - /** |
|
314 | - * @return void |
|
315 | - */ |
|
316 | - public function setDefaults() |
|
317 | - { |
|
318 | - if (get_option(static::ID.'activated')) { |
|
319 | - $this->make(DefaultsManager::class)->set(); |
|
320 | - delete_option(static::ID.'activated'); |
|
321 | - } |
|
322 | - } |
|
313 | + /** |
|
314 | + * @return void |
|
315 | + */ |
|
316 | + public function setDefaults() |
|
317 | + { |
|
318 | + if (get_option(static::ID.'activated')) { |
|
319 | + $this->make(DefaultsManager::class)->set(); |
|
320 | + delete_option(static::ID.'activated'); |
|
321 | + } |
|
322 | + } |
|
323 | 323 | |
324 | - /** |
|
325 | - * @param string $file |
|
326 | - * @return string |
|
327 | - */ |
|
328 | - public function themePath($file = '') |
|
329 | - { |
|
330 | - return get_stylesheet_directory().'/'.static::ID.'/'.ltrim(trim($file), '/'); |
|
331 | - } |
|
324 | + /** |
|
325 | + * @param string $file |
|
326 | + * @return string |
|
327 | + */ |
|
328 | + public function themePath($file = '') |
|
329 | + { |
|
330 | + return get_stylesheet_directory().'/'.static::ID.'/'.ltrim(trim($file), '/'); |
|
331 | + } |
|
332 | 332 | |
333 | - /** |
|
334 | - * @return void |
|
335 | - */ |
|
336 | - public function unscheduleCronJob() |
|
337 | - { |
|
338 | - wp_unschedule_event(intval(wp_next_scheduled(static::CRON_EVENT)), static::CRON_EVENT); |
|
339 | - } |
|
333 | + /** |
|
334 | + * @return void |
|
335 | + */ |
|
336 | + public function unscheduleCronJob() |
|
337 | + { |
|
338 | + wp_unschedule_event(intval(wp_next_scheduled(static::CRON_EVENT)), static::CRON_EVENT); |
|
339 | + } |
|
340 | 340 | |
341 | - /** |
|
342 | - * @param string $path |
|
343 | - * @return string |
|
344 | - */ |
|
345 | - public function url($path = '') |
|
346 | - { |
|
347 | - $url = esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/')); |
|
348 | - return apply_filters('site-reviews/url', $url, $path); |
|
349 | - } |
|
341 | + /** |
|
342 | + * @param string $path |
|
343 | + * @return string |
|
344 | + */ |
|
345 | + public function url($path = '') |
|
346 | + { |
|
347 | + $url = esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/')); |
|
348 | + return apply_filters('site-reviews/url', $url, $path); |
|
349 | + } |
|
350 | 350 | |
351 | - /** |
|
352 | - * @param string $versionLevel |
|
353 | - * @return string |
|
354 | - */ |
|
355 | - public function version($versionLevel = '') |
|
356 | - { |
|
357 | - $pattern = '/^v?(\d{1,5})(\.\d++)?(\.\d++)?(.+)?$/i'; |
|
358 | - preg_match($pattern, $this->version, $matches); |
|
359 | - switch ($versionLevel) { |
|
360 | - case 'major': |
|
361 | - $version = Arr::get($matches, 1); |
|
362 | - break; |
|
363 | - case 'minor': |
|
364 | - $version = Arr::get($matches, 1).Arr::get($matches, 2); |
|
365 | - break; |
|
366 | - case 'patch': |
|
367 | - $version = Arr::get($matches, 1).Arr::get($matches, 2).Arr::get($matches, 3); |
|
368 | - break; |
|
369 | - } |
|
370 | - return empty($version) |
|
371 | - ? $this->version |
|
372 | - : $version; |
|
373 | - } |
|
351 | + /** |
|
352 | + * @param string $versionLevel |
|
353 | + * @return string |
|
354 | + */ |
|
355 | + public function version($versionLevel = '') |
|
356 | + { |
|
357 | + $pattern = '/^v?(\d{1,5})(\.\d++)?(\.\d++)?(.+)?$/i'; |
|
358 | + preg_match($pattern, $this->version, $matches); |
|
359 | + switch ($versionLevel) { |
|
360 | + case 'major': |
|
361 | + $version = Arr::get($matches, 1); |
|
362 | + break; |
|
363 | + case 'minor': |
|
364 | + $version = Arr::get($matches, 1).Arr::get($matches, 2); |
|
365 | + break; |
|
366 | + case 'patch': |
|
367 | + $version = Arr::get($matches, 1).Arr::get($matches, 2).Arr::get($matches, 3); |
|
368 | + break; |
|
369 | + } |
|
370 | + return empty($version) |
|
371 | + ? $this->version |
|
372 | + : $version; |
|
373 | + } |
|
374 | 374 | } |
@@ -41,13 +41,13 @@ discard block |
||
41 | 41 | public function __construct() |
42 | 42 | { |
43 | 43 | static::$instance = $this; |
44 | - $this->file = str_replace('plugin/Application', static::ID, (new ReflectionClass($this))->getFileName()); |
|
45 | - $plugin = get_file_data($this->file, [ |
|
44 | + $this->file = str_replace( 'plugin/Application', static::ID, (new ReflectionClass( $this ))->getFileName() ); |
|
45 | + $plugin = get_file_data( $this->file, [ |
|
46 | 46 | 'languages' => 'Domain Path', |
47 | 47 | 'name' => 'Plugin Name', |
48 | 48 | 'version' => 'Version', |
49 | - ], 'plugin'); |
|
50 | - array_walk($plugin, function ($value, $key) { |
|
49 | + ], 'plugin' ); |
|
50 | + array_walk( $plugin, function( $value, $key ) { |
|
51 | 51 | $this->$key = $value; |
52 | 52 | }); |
53 | 53 | } |
@@ -58,17 +58,17 @@ discard block |
||
58 | 58 | public function activate() |
59 | 59 | { |
60 | 60 | $this->scheduleCronJob(); |
61 | - add_option(static::ID.'activated', true); |
|
61 | + add_option( static::ID.'activated', true ); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
65 | 65 | * @param string $view |
66 | 66 | * @return string |
67 | 67 | */ |
68 | - public function build($view, array $data = []) |
|
68 | + public function build( $view, array $data = [] ) |
|
69 | 69 | { |
70 | 70 | ob_start(); |
71 | - $this->render($view, $data); |
|
71 | + $this->render( $view, $data ); |
|
72 | 72 | return ob_get_clean(); |
73 | 73 | } |
74 | 74 | |
@@ -76,9 +76,9 @@ discard block |
||
76 | 76 | * @param string $capability |
77 | 77 | * @return bool |
78 | 78 | */ |
79 | - public function can($capability) |
|
79 | + public function can( $capability ) |
|
80 | 80 | { |
81 | - return $this->make(Role::class)->can($capability); |
|
81 | + return $this->make( Role::class )->can( $capability ); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
@@ -87,35 +87,35 @@ discard block |
||
87 | 87 | public function catchFatalError() |
88 | 88 | { |
89 | 89 | $error = error_get_last(); |
90 | - if (E_ERROR !== $error['type'] || !Str::contains($error['message'], $this->path())) { |
|
90 | + if( E_ERROR !== $error['type'] || !Str::contains( $error['message'], $this->path() ) ) { |
|
91 | 91 | return; |
92 | 92 | } |
93 | - glsr_log()->error($error['message']); |
|
93 | + glsr_log()->error( $error['message'] ); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
97 | 97 | * @param string $name |
98 | 98 | * @return array |
99 | 99 | */ |
100 | - public function config($name) |
|
100 | + public function config( $name ) |
|
101 | 101 | { |
102 | - $path = apply_filters('site-reviews/config', 'config/'.$name.'.php'); |
|
103 | - $configFile = $this->path($path); |
|
104 | - $config = file_exists($configFile) |
|
102 | + $path = apply_filters( 'site-reviews/config', 'config/'.$name.'.php' ); |
|
103 | + $configFile = $this->path( $path ); |
|
104 | + $config = file_exists( $configFile ) |
|
105 | 105 | ? include $configFile |
106 | 106 | : []; |
107 | - return apply_filters('site-reviews/config/'.$name, $config); |
|
107 | + return apply_filters( 'site-reviews/config/'.$name, $config ); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
111 | 111 | * @param string $property |
112 | 112 | * @return string |
113 | 113 | */ |
114 | - public function constant($property, $className = 'static') |
|
114 | + public function constant( $property, $className = 'static' ) |
|
115 | 115 | { |
116 | 116 | $constant = $className.'::'.$property; |
117 | - return defined($constant) |
|
118 | - ? apply_filters('site-reviews/const/'.$property, constant($constant)) |
|
117 | + return defined( $constant ) |
|
118 | + ? apply_filters( 'site-reviews/const/'.$property, constant( $constant ) ) |
|
119 | 119 | : ''; |
120 | 120 | } |
121 | 121 | |
@@ -131,17 +131,17 @@ discard block |
||
131 | 131 | * @param string $view |
132 | 132 | * @return void|string |
133 | 133 | */ |
134 | - public function file($view) |
|
134 | + public function file( $view ) |
|
135 | 135 | { |
136 | - $view.= '.php'; |
|
136 | + $view .= '.php'; |
|
137 | 137 | $filePaths = []; |
138 | - if (Str::startsWith('templates/', $view)) { |
|
139 | - $filePaths[] = $this->themePath(Str::removePrefix('templates/', $view)); |
|
138 | + if( Str::startsWith( 'templates/', $view ) ) { |
|
139 | + $filePaths[] = $this->themePath( Str::removePrefix( 'templates/', $view ) ); |
|
140 | 140 | } |
141 | - $filePaths[] = $this->path($view); |
|
142 | - $filePaths[] = $this->path('views/'.$view); |
|
143 | - foreach ($filePaths as $file) { |
|
144 | - if (!file_exists($file)) { |
|
141 | + $filePaths[] = $this->path( $view ); |
|
142 | + $filePaths[] = $this->path( 'views/'.$view ); |
|
143 | + foreach( $filePaths as $file ) { |
|
144 | + if( !file_exists( $file ) ) { |
|
145 | 145 | continue; |
146 | 146 | } |
147 | 147 | return $file; |
@@ -153,10 +153,10 @@ discard block |
||
153 | 153 | */ |
154 | 154 | public function getDefaults() |
155 | 155 | { |
156 | - if (empty($this->defaults)) { |
|
157 | - $this->defaults = $this->make(DefaultsManager::class)->get(); |
|
156 | + if( empty($this->defaults) ) { |
|
157 | + $this->defaults = $this->make( DefaultsManager::class )->get(); |
|
158 | 158 | } |
159 | - return apply_filters('site-reviews/get/defaults', $this->defaults); |
|
159 | + return apply_filters( 'site-reviews/get/defaults', $this->defaults ); |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | /** |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | * @param string $tab |
165 | 165 | * @return string |
166 | 166 | */ |
167 | - public function getPermission($page = '', $tab = 'index') |
|
167 | + public function getPermission( $page = '', $tab = 'index' ) |
|
168 | 168 | { |
169 | 169 | $fallback = 'edit_posts'; |
170 | 170 | $permissions = [ |
@@ -185,11 +185,11 @@ discard block |
||
185 | 185 | 'system-info' => 'edit_others_posts', |
186 | 186 | ] |
187 | 187 | ]; |
188 | - $permission = Arr::get($permissions, $page, $fallback); |
|
189 | - if (is_array($permission)) { |
|
190 | - $permission = Arr::get($permission, $tab, $fallback); |
|
188 | + $permission = Arr::get( $permissions, $page, $fallback ); |
|
189 | + if( is_array( $permission ) ) { |
|
190 | + $permission = Arr::get( $permission, $tab, $fallback ); |
|
191 | 191 | } |
192 | - return empty($permission) || !is_string($permission) |
|
192 | + return empty($permission) || !is_string( $permission ) |
|
193 | 193 | ? $fallback |
194 | 194 | : $permission; |
195 | 195 | } |
@@ -199,10 +199,10 @@ discard block |
||
199 | 199 | * @param string $tab |
200 | 200 | * @return bool |
201 | 201 | */ |
202 | - public function hasPermission($page = '', $tab = 'index') |
|
202 | + public function hasPermission( $page = '', $tab = 'index' ) |
|
203 | 203 | { |
204 | 204 | $isAdmin = $this->isAdmin(); |
205 | - return !$isAdmin || ($isAdmin && $this->can($this->getPermission($page, $tab))); |
|
205 | + return !$isAdmin || ($isAdmin && $this->can( $this->getPermission( $page, $tab ) )); |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | /** |
@@ -210,8 +210,8 @@ discard block |
||
210 | 210 | */ |
211 | 211 | public function init() |
212 | 212 | { |
213 | - $this->make(Actions::class)->run(); |
|
214 | - $this->make(Filters::class)->run(); |
|
213 | + $this->make( Actions::class )->run(); |
|
214 | + $this->make( Filters::class )->run(); |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | /** |
@@ -226,31 +226,31 @@ discard block |
||
226 | 226 | * @param string $file |
227 | 227 | * @return string |
228 | 228 | */ |
229 | - public function path($file = '', $realpath = true) |
|
229 | + public function path( $file = '', $realpath = true ) |
|
230 | 230 | { |
231 | - $path = plugin_dir_path($this->file); |
|
232 | - if (!$realpath) { |
|
233 | - $path = trailingslashit(WP_PLUGIN_DIR).basename(dirname($this->file)); |
|
231 | + $path = plugin_dir_path( $this->file ); |
|
232 | + if( !$realpath ) { |
|
233 | + $path = trailingslashit( WP_PLUGIN_DIR ).basename( dirname( $this->file ) ); |
|
234 | 234 | } |
235 | - $path = trailingslashit($path).ltrim(trim($file), '/'); |
|
236 | - return apply_filters('site-reviews/path', $path, $file); |
|
235 | + $path = trailingslashit( $path ).ltrim( trim( $file ), '/' ); |
|
236 | + return apply_filters( 'site-reviews/path', $path, $file ); |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | /** |
240 | 240 | * @param object $addon |
241 | 241 | * @return void |
242 | 242 | */ |
243 | - public function register($addon) |
|
243 | + public function register( $addon ) |
|
244 | 244 | { |
245 | 245 | try { |
246 | - $reflection = new \ReflectionClass($addon); |
|
247 | - if ($id = $reflection->getConstant('ID')) { |
|
246 | + $reflection = new \ReflectionClass( $addon ); |
|
247 | + if( $id = $reflection->getConstant( 'ID' ) ) { |
|
248 | 248 | $this->addons[] = $id; |
249 | - $this->bind($id, $addon); |
|
249 | + $this->bind( $id, $addon ); |
|
250 | 250 | $addon->init(); |
251 | 251 | } |
252 | - } catch(\ReflectionException $e) { |
|
253 | - glsr_log()->error('Attempted to register an invalid addon.'); |
|
252 | + } catch( \ReflectionException $e ) { |
|
253 | + glsr_log()->error( 'Attempted to register an invalid addon.' ); |
|
254 | 254 | } |
255 | 255 | } |
256 | 256 | |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | */ |
260 | 260 | public function registerAddons() |
261 | 261 | { |
262 | - do_action('site-reviews/addon/register', $this); |
|
262 | + do_action( 'site-reviews/addon/register', $this ); |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | /** |
@@ -267,8 +267,8 @@ discard block |
||
267 | 267 | */ |
268 | 268 | public function registerLanguages() |
269 | 269 | { |
270 | - load_plugin_textdomain(static::ID, false, |
|
271 | - trailingslashit(plugin_basename($this->path()).'/'.$this->languages) |
|
270 | + load_plugin_textdomain( static::ID, false, |
|
271 | + trailingslashit( plugin_basename( $this->path() ).'/'.$this->languages ) |
|
272 | 272 | ); |
273 | 273 | } |
274 | 274 | |
@@ -277,26 +277,26 @@ discard block |
||
277 | 277 | */ |
278 | 278 | public function registerReviewTypes() |
279 | 279 | { |
280 | - $types = apply_filters('site-reviews/addon/types', []); |
|
281 | - $this->reviewTypes = wp_parse_args($types, [ |
|
282 | - 'local' => __('Local', 'site-reviews'), |
|
283 | - ]); |
|
280 | + $types = apply_filters( 'site-reviews/addon/types', [] ); |
|
281 | + $this->reviewTypes = wp_parse_args( $types, [ |
|
282 | + 'local' => __( 'Local', 'site-reviews' ), |
|
283 | + ] ); |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | /** |
287 | 287 | * @param string $view |
288 | 288 | * @return void |
289 | 289 | */ |
290 | - public function render($view, array $data = []) |
|
290 | + public function render( $view, array $data = [] ) |
|
291 | 291 | { |
292 | - $view = apply_filters('site-reviews/render/view', $view, $data); |
|
293 | - $file = apply_filters('site-reviews/views/file', $this->file($view), $view, $data); |
|
294 | - if (!file_exists($file)) { |
|
295 | - glsr_log()->error(sprintf('File not found: (%s) %s', $view, $file)); |
|
292 | + $view = apply_filters( 'site-reviews/render/view', $view, $data ); |
|
293 | + $file = apply_filters( 'site-reviews/views/file', $this->file( $view ), $view, $data ); |
|
294 | + if( !file_exists( $file ) ) { |
|
295 | + glsr_log()->error( sprintf( 'File not found: (%s) %s', $view, $file ) ); |
|
296 | 296 | return; |
297 | 297 | } |
298 | - $data = apply_filters('site-reviews/views/data', $data, $view); |
|
299 | - extract($data); |
|
298 | + $data = apply_filters( 'site-reviews/views/data', $data, $view ); |
|
299 | + extract( $data ); |
|
300 | 300 | include $file; |
301 | 301 | } |
302 | 302 | |
@@ -305,8 +305,8 @@ discard block |
||
305 | 305 | */ |
306 | 306 | public function scheduleCronJob() |
307 | 307 | { |
308 | - if (false === wp_next_scheduled(static::CRON_EVENT)) { |
|
309 | - wp_schedule_event(time(), 'twicedaily', static::CRON_EVENT); |
|
308 | + if( false === wp_next_scheduled( static::CRON_EVENT ) ) { |
|
309 | + wp_schedule_event( time(), 'twicedaily', static::CRON_EVENT ); |
|
310 | 310 | } |
311 | 311 | } |
312 | 312 | |
@@ -315,9 +315,9 @@ discard block |
||
315 | 315 | */ |
316 | 316 | public function setDefaults() |
317 | 317 | { |
318 | - if (get_option(static::ID.'activated')) { |
|
319 | - $this->make(DefaultsManager::class)->set(); |
|
320 | - delete_option(static::ID.'activated'); |
|
318 | + if( get_option( static::ID.'activated' ) ) { |
|
319 | + $this->make( DefaultsManager::class )->set(); |
|
320 | + delete_option( static::ID.'activated' ); |
|
321 | 321 | } |
322 | 322 | } |
323 | 323 | |
@@ -325,9 +325,9 @@ discard block |
||
325 | 325 | * @param string $file |
326 | 326 | * @return string |
327 | 327 | */ |
328 | - public function themePath($file = '') |
|
328 | + public function themePath( $file = '' ) |
|
329 | 329 | { |
330 | - return get_stylesheet_directory().'/'.static::ID.'/'.ltrim(trim($file), '/'); |
|
330 | + return get_stylesheet_directory().'/'.static::ID.'/'.ltrim( trim( $file ), '/' ); |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | /** |
@@ -335,36 +335,36 @@ discard block |
||
335 | 335 | */ |
336 | 336 | public function unscheduleCronJob() |
337 | 337 | { |
338 | - wp_unschedule_event(intval(wp_next_scheduled(static::CRON_EVENT)), static::CRON_EVENT); |
|
338 | + wp_unschedule_event( intval( wp_next_scheduled( static::CRON_EVENT ) ), static::CRON_EVENT ); |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | /** |
342 | 342 | * @param string $path |
343 | 343 | * @return string |
344 | 344 | */ |
345 | - public function url($path = '') |
|
345 | + public function url( $path = '' ) |
|
346 | 346 | { |
347 | - $url = esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/')); |
|
348 | - return apply_filters('site-reviews/url', $url, $path); |
|
347 | + $url = esc_url( plugin_dir_url( $this->file ).ltrim( trim( $path ), '/' ) ); |
|
348 | + return apply_filters( 'site-reviews/url', $url, $path ); |
|
349 | 349 | } |
350 | 350 | |
351 | 351 | /** |
352 | 352 | * @param string $versionLevel |
353 | 353 | * @return string |
354 | 354 | */ |
355 | - public function version($versionLevel = '') |
|
355 | + public function version( $versionLevel = '' ) |
|
356 | 356 | { |
357 | 357 | $pattern = '/^v?(\d{1,5})(\.\d++)?(\.\d++)?(.+)?$/i'; |
358 | - preg_match($pattern, $this->version, $matches); |
|
359 | - switch ($versionLevel) { |
|
358 | + preg_match( $pattern, $this->version, $matches ); |
|
359 | + switch( $versionLevel ) { |
|
360 | 360 | case 'major': |
361 | - $version = Arr::get($matches, 1); |
|
361 | + $version = Arr::get( $matches, 1 ); |
|
362 | 362 | break; |
363 | 363 | case 'minor': |
364 | - $version = Arr::get($matches, 1).Arr::get($matches, 2); |
|
364 | + $version = Arr::get( $matches, 1 ).Arr::get( $matches, 2 ); |
|
365 | 365 | break; |
366 | 366 | case 'patch': |
367 | - $version = Arr::get($matches, 1).Arr::get($matches, 2).Arr::get($matches, 3); |
|
367 | + $version = Arr::get( $matches, 1 ).Arr::get( $matches, 2 ).Arr::get( $matches, 3 ); |
|
368 | 368 | break; |
369 | 369 | } |
370 | 370 | return empty($version) |
@@ -7,48 +7,48 @@ |
||
7 | 7 | |
8 | 8 | class ReviewHtml extends ArrayObject |
9 | 9 | { |
10 | - /** |
|
11 | - * @var Review |
|
12 | - */ |
|
13 | - public $review; |
|
10 | + /** |
|
11 | + * @var Review |
|
12 | + */ |
|
13 | + public $review; |
|
14 | 14 | |
15 | - /** |
|
16 | - * @var array |
|
17 | - */ |
|
18 | - public $values; |
|
15 | + /** |
|
16 | + * @var array |
|
17 | + */ |
|
18 | + public $values; |
|
19 | 19 | |
20 | - public function __construct(Review $review, array $values = []) |
|
21 | - { |
|
22 | - $this->review = $review; |
|
23 | - $this->values = $values; |
|
24 | - parent::__construct($values, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS); |
|
25 | - } |
|
20 | + public function __construct(Review $review, array $values = []) |
|
21 | + { |
|
22 | + $this->review = $review; |
|
23 | + $this->values = $values; |
|
24 | + parent::__construct($values, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS); |
|
25 | + } |
|
26 | 26 | |
27 | - /** |
|
28 | - * @return string|void |
|
29 | - */ |
|
30 | - public function __toString() |
|
31 | - { |
|
32 | - if (empty($this->values)) { |
|
33 | - return; |
|
34 | - } |
|
35 | - return glsr(Template::class)->build('templates/review', [ |
|
36 | - 'context' => $this->values, |
|
37 | - 'review' => $this->review, |
|
38 | - ]); |
|
39 | - } |
|
27 | + /** |
|
28 | + * @return string|void |
|
29 | + */ |
|
30 | + public function __toString() |
|
31 | + { |
|
32 | + if (empty($this->values)) { |
|
33 | + return; |
|
34 | + } |
|
35 | + return glsr(Template::class)->build('templates/review', [ |
|
36 | + 'context' => $this->values, |
|
37 | + 'review' => $this->review, |
|
38 | + ]); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * @param mixed $key |
|
43 | - * @return mixed |
|
44 | - */ |
|
45 | - public function offsetGet($key) |
|
46 | - { |
|
47 | - if (array_key_exists($key, $this->values)) { |
|
48 | - return $this->values[$key]; |
|
49 | - } |
|
50 | - return property_exists($this, $key) |
|
51 | - ? $this->$key |
|
52 | - : null; |
|
53 | - } |
|
41 | + /** |
|
42 | + * @param mixed $key |
|
43 | + * @return mixed |
|
44 | + */ |
|
45 | + public function offsetGet($key) |
|
46 | + { |
|
47 | + if (array_key_exists($key, $this->values)) { |
|
48 | + return $this->values[$key]; |
|
49 | + } |
|
50 | + return property_exists($this, $key) |
|
51 | + ? $this->$key |
|
52 | + : null; |
|
53 | + } |
|
54 | 54 | } |
@@ -17,11 +17,11 @@ discard block |
||
17 | 17 | */ |
18 | 18 | public $values; |
19 | 19 | |
20 | - public function __construct(Review $review, array $values = []) |
|
20 | + public function __construct( Review $review, array $values = [] ) |
|
21 | 21 | { |
22 | 22 | $this->review = $review; |
23 | 23 | $this->values = $values; |
24 | - parent::__construct($values, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS); |
|
24 | + parent::__construct( $values, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS ); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | /** |
@@ -29,25 +29,25 @@ discard block |
||
29 | 29 | */ |
30 | 30 | public function __toString() |
31 | 31 | { |
32 | - if (empty($this->values)) { |
|
32 | + if( empty($this->values) ) { |
|
33 | 33 | return; |
34 | 34 | } |
35 | - return glsr(Template::class)->build('templates/review', [ |
|
35 | + return glsr( Template::class )->build( 'templates/review', [ |
|
36 | 36 | 'context' => $this->values, |
37 | 37 | 'review' => $this->review, |
38 | - ]); |
|
38 | + ] ); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
42 | 42 | * @param mixed $key |
43 | 43 | * @return mixed |
44 | 44 | */ |
45 | - public function offsetGet($key) |
|
45 | + public function offsetGet( $key ) |
|
46 | 46 | { |
47 | - if (array_key_exists($key, $this->values)) { |
|
47 | + if( array_key_exists( $key, $this->values ) ) { |
|
48 | 48 | return $this->values[$key]; |
49 | 49 | } |
50 | - return property_exists($this, $key) |
|
50 | + return property_exists( $this, $key ) |
|
51 | 51 | ? $this->$key |
52 | 52 | : null; |
53 | 53 | } |
@@ -4,8 +4,8 @@ |
||
4 | 4 | |
5 | 5 | interface PartialContract |
6 | 6 | { |
7 | - /** |
|
8 | - * @return string |
|
9 | - */ |
|
10 | - public function build(array $args = []); |
|
7 | + /** |
|
8 | + * @return string |
|
9 | + */ |
|
10 | + public function build(array $args = []); |
|
11 | 11 | } |
@@ -7,5 +7,5 @@ |
||
7 | 7 | /** |
8 | 8 | * @return string |
9 | 9 | */ |
10 | - public function build(array $args = []); |
|
10 | + public function build( array $args = [] ); |
|
11 | 11 | } |
@@ -6,7 +6,7 @@ |
||
6 | 6 | require_once $file; |
7 | 7 | |
8 | 8 | if (!(new GL_Plugin_Check_v4($file))->isValid()) { |
9 | - return; |
|
9 | + return; |
|
10 | 10 | } |
11 | 11 | delete_option(GeminiLabs\SiteReviews\Database\OptionManager::databaseKey(3)); |
12 | 12 | delete_option(GeminiLabs\SiteReviews\Database\OptionManager::databaseKey(4)); |
@@ -1,23 +1,23 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -defined('WP_UNINSTALL_PLUGIN') || die; |
|
3 | +defined( 'WP_UNINSTALL_PLUGIN' ) || die; |
|
4 | 4 | |
5 | 5 | $file = __DIR__.'/site-reviews.php'; |
6 | 6 | require_once $file; |
7 | 7 | |
8 | -if (!(new GL_Plugin_Check_v4($file))->isValid()) { |
|
8 | +if( !(new GL_Plugin_Check_v4( $file ))->isValid() ) { |
|
9 | 9 | return; |
10 | 10 | } |
11 | -delete_option(GeminiLabs\SiteReviews\Database\OptionManager::databaseKey(3)); |
|
12 | -delete_option(GeminiLabs\SiteReviews\Database\OptionManager::databaseKey(4)); |
|
13 | -delete_option('_glsr_trustalyze'); |
|
14 | -delete_option('widget_'.glsr()->id.'_site-reviews'); |
|
15 | -delete_option('widget_'.glsr()->id.'_site-reviews-form'); |
|
16 | -delete_option('widget_'.glsr()->id.'_site-reviews-summary'); |
|
17 | -delete_transient(glsr()->id.'_cloudflare_ips'); |
|
18 | -delete_transient(glsr()->id.'_remote_post_test'); |
|
19 | -wp_cache_delete(glsr()->id); |
|
11 | +delete_option( GeminiLabs\SiteReviews\Database\OptionManager::databaseKey( 3 ) ); |
|
12 | +delete_option( GeminiLabs\SiteReviews\Database\OptionManager::databaseKey( 4 ) ); |
|
13 | +delete_option( '_glsr_trustalyze' ); |
|
14 | +delete_option( 'widget_'.glsr()->id.'_site-reviews' ); |
|
15 | +delete_option( 'widget_'.glsr()->id.'_site-reviews-form' ); |
|
16 | +delete_option( 'widget_'.glsr()->id.'_site-reviews-summary' ); |
|
17 | +delete_transient( glsr()->id.'_cloudflare_ips' ); |
|
18 | +delete_transient( glsr()->id.'_remote_post_test' ); |
|
19 | +wp_cache_delete( glsr()->id ); |
|
20 | 20 | |
21 | 21 | global $wpdb; |
22 | 22 | |
23 | -$wpdb->query("DELETE FROM {$wpdb->usermeta} WHERE meta_key = '_glsr_notices'"); |
|
23 | +$wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key = '_glsr_notices'" ); |
@@ -1,4 +1,4 @@ |
||
1 | -<?php defined('WPINC') || die; ?> |
|
1 | +<?php defined( 'WPINC' ) || die; ?> |
|
2 | 2 | |
3 | 3 | <p class="about-description">We hope you love the changes in this new release!</p> |
4 | 4 | <div class="is-fullwidth"> |
@@ -64,7 +64,8 @@ |
||
64 | 64 | $review = glsr_get_review($post); |
65 | 65 | if ('publish' == $post->post_status) { |
66 | 66 | glsr(CountsManager::class)->increaseAll($review); |
67 | - } else { |
|
67 | + } |
|
68 | + else { |
|
68 | 69 | glsr(CountsManager::class)->decreaseAll($review); |
69 | 70 | } |
70 | 71 | } |
@@ -16,159 +16,159 @@ |
||
16 | 16 | |
17 | 17 | class ReviewController extends Controller |
18 | 18 | { |
19 | - /** |
|
20 | - * Triggered when a category is added to a review. |
|
21 | - * |
|
22 | - * @param int $postId |
|
23 | - * @param array $terms |
|
24 | - * @param array $newTTIds |
|
25 | - * @param string $taxonomy |
|
26 | - * @param bool $append |
|
27 | - * @param array $oldTTIds |
|
28 | - * @return void |
|
29 | - * @action set_object_terms |
|
30 | - */ |
|
31 | - public function onAfterChangeCategory($postId, $terms, $newTTIds, $taxonomy, $append, $oldTTIds) |
|
32 | - { |
|
33 | - sort($newTTIds); |
|
34 | - sort($oldTTIds); |
|
35 | - if ($newTTIds === $oldTTIds || !$this->isReviewPostId($postId)) { |
|
36 | - return; |
|
37 | - } |
|
38 | - $review = glsr_get_review($postId); |
|
39 | - if ('publish' !== $review->status) { |
|
40 | - return; |
|
41 | - } |
|
42 | - $ignoredIds = array_intersect($oldTTIds, $newTTIds); |
|
43 | - $decreasedIds = array_diff($oldTTIds, $ignoredIds); |
|
44 | - $increasedIds = array_diff($newTTIds, $ignoredIds); |
|
45 | - if ($review->term_ids = glsr(Database::class)->getTermIds($decreasedIds, 'term_taxonomy_id')) { |
|
46 | - glsr(TermCountsManager::class)->decrease($review); |
|
47 | - } |
|
48 | - if ($review->term_ids = glsr(Database::class)->getTermIds($increasedIds, 'term_taxonomy_id')) { |
|
49 | - glsr(TermCountsManager::class)->increase($review); |
|
50 | - } |
|
51 | - } |
|
19 | + /** |
|
20 | + * Triggered when a category is added to a review. |
|
21 | + * |
|
22 | + * @param int $postId |
|
23 | + * @param array $terms |
|
24 | + * @param array $newTTIds |
|
25 | + * @param string $taxonomy |
|
26 | + * @param bool $append |
|
27 | + * @param array $oldTTIds |
|
28 | + * @return void |
|
29 | + * @action set_object_terms |
|
30 | + */ |
|
31 | + public function onAfterChangeCategory($postId, $terms, $newTTIds, $taxonomy, $append, $oldTTIds) |
|
32 | + { |
|
33 | + sort($newTTIds); |
|
34 | + sort($oldTTIds); |
|
35 | + if ($newTTIds === $oldTTIds || !$this->isReviewPostId($postId)) { |
|
36 | + return; |
|
37 | + } |
|
38 | + $review = glsr_get_review($postId); |
|
39 | + if ('publish' !== $review->status) { |
|
40 | + return; |
|
41 | + } |
|
42 | + $ignoredIds = array_intersect($oldTTIds, $newTTIds); |
|
43 | + $decreasedIds = array_diff($oldTTIds, $ignoredIds); |
|
44 | + $increasedIds = array_diff($newTTIds, $ignoredIds); |
|
45 | + if ($review->term_ids = glsr(Database::class)->getTermIds($decreasedIds, 'term_taxonomy_id')) { |
|
46 | + glsr(TermCountsManager::class)->decrease($review); |
|
47 | + } |
|
48 | + if ($review->term_ids = glsr(Database::class)->getTermIds($increasedIds, 'term_taxonomy_id')) { |
|
49 | + glsr(TermCountsManager::class)->increase($review); |
|
50 | + } |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Triggered when an existing review is approved|unapproved. |
|
55 | - * |
|
56 | - * @param string $oldStatus |
|
57 | - * @param string $newStatus |
|
58 | - * @param \WP_Post $post |
|
59 | - * @return void |
|
60 | - * @action transition_post_status |
|
61 | - */ |
|
62 | - public function onAfterChangeStatus($newStatus, $oldStatus, $post) |
|
63 | - { |
|
64 | - if (Application::POST_TYPE != Arr::get($post, 'post_type') |
|
65 | - || in_array($oldStatus, ['new', $newStatus])) { |
|
66 | - return; |
|
67 | - } |
|
68 | - $review = glsr_get_review($post); |
|
69 | - if ('publish' == $post->post_status) { |
|
70 | - glsr(CountsManager::class)->increaseAll($review); |
|
71 | - } else { |
|
72 | - glsr(CountsManager::class)->decreaseAll($review); |
|
73 | - } |
|
74 | - } |
|
53 | + /** |
|
54 | + * Triggered when an existing review is approved|unapproved. |
|
55 | + * |
|
56 | + * @param string $oldStatus |
|
57 | + * @param string $newStatus |
|
58 | + * @param \WP_Post $post |
|
59 | + * @return void |
|
60 | + * @action transition_post_status |
|
61 | + */ |
|
62 | + public function onAfterChangeStatus($newStatus, $oldStatus, $post) |
|
63 | + { |
|
64 | + if (Application::POST_TYPE != Arr::get($post, 'post_type') |
|
65 | + || in_array($oldStatus, ['new', $newStatus])) { |
|
66 | + return; |
|
67 | + } |
|
68 | + $review = glsr_get_review($post); |
|
69 | + if ('publish' == $post->post_status) { |
|
70 | + glsr(CountsManager::class)->increaseAll($review); |
|
71 | + } else { |
|
72 | + glsr(CountsManager::class)->decreaseAll($review); |
|
73 | + } |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * Triggered when a review is first created. |
|
78 | - * |
|
79 | - * @return void |
|
80 | - * @action site-reviews/review/created |
|
81 | - */ |
|
82 | - public function onAfterCreate(Review $review) |
|
83 | - { |
|
84 | - if ('publish' !== $review->status) { |
|
85 | - return; |
|
86 | - } |
|
87 | - glsr(GlobalCountsManager::class)->increase($review); |
|
88 | - glsr(PostCountsManager::class)->increase($review); |
|
89 | - } |
|
76 | + /** |
|
77 | + * Triggered when a review is first created. |
|
78 | + * |
|
79 | + * @return void |
|
80 | + * @action site-reviews/review/created |
|
81 | + */ |
|
82 | + public function onAfterCreate(Review $review) |
|
83 | + { |
|
84 | + if ('publish' !== $review->status) { |
|
85 | + return; |
|
86 | + } |
|
87 | + glsr(GlobalCountsManager::class)->increase($review); |
|
88 | + glsr(PostCountsManager::class)->increase($review); |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * Triggered when a review is deleted. |
|
93 | - * |
|
94 | - * @param int $postId |
|
95 | - * @return void |
|
96 | - * @action before_delete_post |
|
97 | - */ |
|
98 | - public function onBeforeDelete($postId) |
|
99 | - { |
|
100 | - if (!$this->isReviewPostId($postId)) { |
|
101 | - return; |
|
102 | - } |
|
103 | - $review = glsr_get_review($postId); |
|
104 | - if ('trash' !== $review->status) { // do not run for trashed posts |
|
105 | - glsr(CountsManager::class)->decreaseAll($review); |
|
106 | - } |
|
107 | - } |
|
91 | + /** |
|
92 | + * Triggered when a review is deleted. |
|
93 | + * |
|
94 | + * @param int $postId |
|
95 | + * @return void |
|
96 | + * @action before_delete_post |
|
97 | + */ |
|
98 | + public function onBeforeDelete($postId) |
|
99 | + { |
|
100 | + if (!$this->isReviewPostId($postId)) { |
|
101 | + return; |
|
102 | + } |
|
103 | + $review = glsr_get_review($postId); |
|
104 | + if ('trash' !== $review->status) { // do not run for trashed posts |
|
105 | + glsr(CountsManager::class)->decreaseAll($review); |
|
106 | + } |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * Triggered when a review's rating, assigned_to, or review_type is changed. |
|
111 | - * |
|
112 | - * @param int $metaId |
|
113 | - * @param int $postId |
|
114 | - * @param string $metaKey |
|
115 | - * @param mixed $metaValue |
|
116 | - * @return void |
|
117 | - * @action update_postmeta |
|
118 | - */ |
|
119 | - public function onBeforeUpdate($metaId, $postId, $metaKey, $metaValue) |
|
120 | - { |
|
121 | - if (!$this->isReviewPostId($postId)) { |
|
122 | - return; |
|
123 | - } |
|
124 | - $metaKey = Str::removePrefix('_', $metaKey); |
|
125 | - if (!in_array($metaKey, ['assigned_to', 'rating', 'review_type'])) { |
|
126 | - return; |
|
127 | - } |
|
128 | - $review = glsr_get_review($postId); |
|
129 | - if ($review->$metaKey == $metaValue) { |
|
130 | - return; |
|
131 | - } |
|
132 | - $method = Helper::buildMethodName($metaKey, 'onBeforeChange'); |
|
133 | - call_user_func([$this, $method], $review, $metaValue); |
|
134 | - } |
|
109 | + /** |
|
110 | + * Triggered when a review's rating, assigned_to, or review_type is changed. |
|
111 | + * |
|
112 | + * @param int $metaId |
|
113 | + * @param int $postId |
|
114 | + * @param string $metaKey |
|
115 | + * @param mixed $metaValue |
|
116 | + * @return void |
|
117 | + * @action update_postmeta |
|
118 | + */ |
|
119 | + public function onBeforeUpdate($metaId, $postId, $metaKey, $metaValue) |
|
120 | + { |
|
121 | + if (!$this->isReviewPostId($postId)) { |
|
122 | + return; |
|
123 | + } |
|
124 | + $metaKey = Str::removePrefix('_', $metaKey); |
|
125 | + if (!in_array($metaKey, ['assigned_to', 'rating', 'review_type'])) { |
|
126 | + return; |
|
127 | + } |
|
128 | + $review = glsr_get_review($postId); |
|
129 | + if ($review->$metaKey == $metaValue) { |
|
130 | + return; |
|
131 | + } |
|
132 | + $method = Helper::buildMethodName($metaKey, 'onBeforeChange'); |
|
133 | + call_user_func([$this, $method], $review, $metaValue); |
|
134 | + } |
|
135 | 135 | |
136 | - /** |
|
137 | - * Triggered by the onBeforeUpdate method. |
|
138 | - * |
|
139 | - * @param string|int $assignedTo |
|
140 | - * @return void |
|
141 | - */ |
|
142 | - protected function onBeforeChangeAssignedTo(Review $review, $assignedTo) |
|
143 | - { |
|
144 | - glsr(PostCountsManager::class)->decrease($review); |
|
145 | - $review->assigned_to = $assignedTo; |
|
146 | - glsr(PostCountsManager::class)->increase($review); |
|
147 | - } |
|
136 | + /** |
|
137 | + * Triggered by the onBeforeUpdate method. |
|
138 | + * |
|
139 | + * @param string|int $assignedTo |
|
140 | + * @return void |
|
141 | + */ |
|
142 | + protected function onBeforeChangeAssignedTo(Review $review, $assignedTo) |
|
143 | + { |
|
144 | + glsr(PostCountsManager::class)->decrease($review); |
|
145 | + $review->assigned_to = $assignedTo; |
|
146 | + glsr(PostCountsManager::class)->increase($review); |
|
147 | + } |
|
148 | 148 | |
149 | - /** |
|
150 | - * Triggered by the onBeforeUpdate method. |
|
151 | - * |
|
152 | - * @param string|int $rating |
|
153 | - * @return void |
|
154 | - */ |
|
155 | - protected function onBeforeChangeRating(Review $review, $rating) |
|
156 | - { |
|
157 | - glsr(CountsManager::class)->decreaseAll($review); |
|
158 | - $review->rating = $rating; |
|
159 | - glsr(CountsManager::class)->increaseAll($review); |
|
160 | - } |
|
149 | + /** |
|
150 | + * Triggered by the onBeforeUpdate method. |
|
151 | + * |
|
152 | + * @param string|int $rating |
|
153 | + * @return void |
|
154 | + */ |
|
155 | + protected function onBeforeChangeRating(Review $review, $rating) |
|
156 | + { |
|
157 | + glsr(CountsManager::class)->decreaseAll($review); |
|
158 | + $review->rating = $rating; |
|
159 | + glsr(CountsManager::class)->increaseAll($review); |
|
160 | + } |
|
161 | 161 | |
162 | - /** |
|
163 | - * Triggered by the onBeforeUpdate method. |
|
164 | - * |
|
165 | - * @param string $reviewType |
|
166 | - * @return void |
|
167 | - */ |
|
168 | - protected function onBeforeChangeReviewType(Review $review, $reviewType) |
|
169 | - { |
|
170 | - glsr(CountsManager::class)->decreaseAll($review); |
|
171 | - $review->review_type = $reviewType; |
|
172 | - glsr(CountsManager::class)->increaseAll($review); |
|
173 | - } |
|
162 | + /** |
|
163 | + * Triggered by the onBeforeUpdate method. |
|
164 | + * |
|
165 | + * @param string $reviewType |
|
166 | + * @return void |
|
167 | + */ |
|
168 | + protected function onBeforeChangeReviewType(Review $review, $reviewType) |
|
169 | + { |
|
170 | + glsr(CountsManager::class)->decreaseAll($review); |
|
171 | + $review->review_type = $reviewType; |
|
172 | + glsr(CountsManager::class)->increaseAll($review); |
|
173 | + } |
|
174 | 174 | } |
@@ -28,25 +28,25 @@ discard block |
||
28 | 28 | * @return void |
29 | 29 | * @action set_object_terms |
30 | 30 | */ |
31 | - public function onAfterChangeCategory($postId, $terms, $newTTIds, $taxonomy, $append, $oldTTIds) |
|
31 | + public function onAfterChangeCategory( $postId, $terms, $newTTIds, $taxonomy, $append, $oldTTIds ) |
|
32 | 32 | { |
33 | - sort($newTTIds); |
|
34 | - sort($oldTTIds); |
|
35 | - if ($newTTIds === $oldTTIds || !$this->isReviewPostId($postId)) { |
|
33 | + sort( $newTTIds ); |
|
34 | + sort( $oldTTIds ); |
|
35 | + if( $newTTIds === $oldTTIds || !$this->isReviewPostId( $postId ) ) { |
|
36 | 36 | return; |
37 | 37 | } |
38 | - $review = glsr_get_review($postId); |
|
39 | - if ('publish' !== $review->status) { |
|
38 | + $review = glsr_get_review( $postId ); |
|
39 | + if( 'publish' !== $review->status ) { |
|
40 | 40 | return; |
41 | 41 | } |
42 | - $ignoredIds = array_intersect($oldTTIds, $newTTIds); |
|
43 | - $decreasedIds = array_diff($oldTTIds, $ignoredIds); |
|
44 | - $increasedIds = array_diff($newTTIds, $ignoredIds); |
|
45 | - if ($review->term_ids = glsr(Database::class)->getTermIds($decreasedIds, 'term_taxonomy_id')) { |
|
46 | - glsr(TermCountsManager::class)->decrease($review); |
|
42 | + $ignoredIds = array_intersect( $oldTTIds, $newTTIds ); |
|
43 | + $decreasedIds = array_diff( $oldTTIds, $ignoredIds ); |
|
44 | + $increasedIds = array_diff( $newTTIds, $ignoredIds ); |
|
45 | + if( $review->term_ids = glsr( Database::class )->getTermIds( $decreasedIds, 'term_taxonomy_id' ) ) { |
|
46 | + glsr( TermCountsManager::class )->decrease( $review ); |
|
47 | 47 | } |
48 | - if ($review->term_ids = glsr(Database::class)->getTermIds($increasedIds, 'term_taxonomy_id')) { |
|
49 | - glsr(TermCountsManager::class)->increase($review); |
|
48 | + if( $review->term_ids = glsr( Database::class )->getTermIds( $increasedIds, 'term_taxonomy_id' ) ) { |
|
49 | + glsr( TermCountsManager::class )->increase( $review ); |
|
50 | 50 | } |
51 | 51 | } |
52 | 52 | |
@@ -59,17 +59,17 @@ discard block |
||
59 | 59 | * @return void |
60 | 60 | * @action transition_post_status |
61 | 61 | */ |
62 | - public function onAfterChangeStatus($newStatus, $oldStatus, $post) |
|
62 | + public function onAfterChangeStatus( $newStatus, $oldStatus, $post ) |
|
63 | 63 | { |
64 | - if (Application::POST_TYPE != Arr::get($post, 'post_type') |
|
65 | - || in_array($oldStatus, ['new', $newStatus])) { |
|
64 | + if( Application::POST_TYPE != Arr::get( $post, 'post_type' ) |
|
65 | + || in_array( $oldStatus, ['new', $newStatus] ) ) { |
|
66 | 66 | return; |
67 | 67 | } |
68 | - $review = glsr_get_review($post); |
|
69 | - if ('publish' == $post->post_status) { |
|
70 | - glsr(CountsManager::class)->increaseAll($review); |
|
68 | + $review = glsr_get_review( $post ); |
|
69 | + if( 'publish' == $post->post_status ) { |
|
70 | + glsr( CountsManager::class )->increaseAll( $review ); |
|
71 | 71 | } else { |
72 | - glsr(CountsManager::class)->decreaseAll($review); |
|
72 | + glsr( CountsManager::class )->decreaseAll( $review ); |
|
73 | 73 | } |
74 | 74 | } |
75 | 75 | |
@@ -79,13 +79,13 @@ discard block |
||
79 | 79 | * @return void |
80 | 80 | * @action site-reviews/review/created |
81 | 81 | */ |
82 | - public function onAfterCreate(Review $review) |
|
82 | + public function onAfterCreate( Review $review ) |
|
83 | 83 | { |
84 | - if ('publish' !== $review->status) { |
|
84 | + if( 'publish' !== $review->status ) { |
|
85 | 85 | return; |
86 | 86 | } |
87 | - glsr(GlobalCountsManager::class)->increase($review); |
|
88 | - glsr(PostCountsManager::class)->increase($review); |
|
87 | + glsr( GlobalCountsManager::class )->increase( $review ); |
|
88 | + glsr( PostCountsManager::class )->increase( $review ); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -95,14 +95,14 @@ discard block |
||
95 | 95 | * @return void |
96 | 96 | * @action before_delete_post |
97 | 97 | */ |
98 | - public function onBeforeDelete($postId) |
|
98 | + public function onBeforeDelete( $postId ) |
|
99 | 99 | { |
100 | - if (!$this->isReviewPostId($postId)) { |
|
100 | + if( !$this->isReviewPostId( $postId ) ) { |
|
101 | 101 | return; |
102 | 102 | } |
103 | - $review = glsr_get_review($postId); |
|
104 | - if ('trash' !== $review->status) { // do not run for trashed posts |
|
105 | - glsr(CountsManager::class)->decreaseAll($review); |
|
103 | + $review = glsr_get_review( $postId ); |
|
104 | + if( 'trash' !== $review->status ) { // do not run for trashed posts |
|
105 | + glsr( CountsManager::class )->decreaseAll( $review ); |
|
106 | 106 | } |
107 | 107 | } |
108 | 108 | |
@@ -116,21 +116,21 @@ discard block |
||
116 | 116 | * @return void |
117 | 117 | * @action update_postmeta |
118 | 118 | */ |
119 | - public function onBeforeUpdate($metaId, $postId, $metaKey, $metaValue) |
|
119 | + public function onBeforeUpdate( $metaId, $postId, $metaKey, $metaValue ) |
|
120 | 120 | { |
121 | - if (!$this->isReviewPostId($postId)) { |
|
121 | + if( !$this->isReviewPostId( $postId ) ) { |
|
122 | 122 | return; |
123 | 123 | } |
124 | - $metaKey = Str::removePrefix('_', $metaKey); |
|
125 | - if (!in_array($metaKey, ['assigned_to', 'rating', 'review_type'])) { |
|
124 | + $metaKey = Str::removePrefix( '_', $metaKey ); |
|
125 | + if( !in_array( $metaKey, ['assigned_to', 'rating', 'review_type'] ) ) { |
|
126 | 126 | return; |
127 | 127 | } |
128 | - $review = glsr_get_review($postId); |
|
129 | - if ($review->$metaKey == $metaValue) { |
|
128 | + $review = glsr_get_review( $postId ); |
|
129 | + if( $review->$metaKey == $metaValue ) { |
|
130 | 130 | return; |
131 | 131 | } |
132 | - $method = Helper::buildMethodName($metaKey, 'onBeforeChange'); |
|
133 | - call_user_func([$this, $method], $review, $metaValue); |
|
132 | + $method = Helper::buildMethodName( $metaKey, 'onBeforeChange' ); |
|
133 | + call_user_func( [$this, $method], $review, $metaValue ); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -139,11 +139,11 @@ discard block |
||
139 | 139 | * @param string|int $assignedTo |
140 | 140 | * @return void |
141 | 141 | */ |
142 | - protected function onBeforeChangeAssignedTo(Review $review, $assignedTo) |
|
142 | + protected function onBeforeChangeAssignedTo( Review $review, $assignedTo ) |
|
143 | 143 | { |
144 | - glsr(PostCountsManager::class)->decrease($review); |
|
144 | + glsr( PostCountsManager::class )->decrease( $review ); |
|
145 | 145 | $review->assigned_to = $assignedTo; |
146 | - glsr(PostCountsManager::class)->increase($review); |
|
146 | + glsr( PostCountsManager::class )->increase( $review ); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -152,11 +152,11 @@ discard block |
||
152 | 152 | * @param string|int $rating |
153 | 153 | * @return void |
154 | 154 | */ |
155 | - protected function onBeforeChangeRating(Review $review, $rating) |
|
155 | + protected function onBeforeChangeRating( Review $review, $rating ) |
|
156 | 156 | { |
157 | - glsr(CountsManager::class)->decreaseAll($review); |
|
157 | + glsr( CountsManager::class )->decreaseAll( $review ); |
|
158 | 158 | $review->rating = $rating; |
159 | - glsr(CountsManager::class)->increaseAll($review); |
|
159 | + glsr( CountsManager::class )->increaseAll( $review ); |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | /** |
@@ -165,10 +165,10 @@ discard block |
||
165 | 165 | * @param string $reviewType |
166 | 166 | * @return void |
167 | 167 | */ |
168 | - protected function onBeforeChangeReviewType(Review $review, $reviewType) |
|
168 | + protected function onBeforeChangeReviewType( Review $review, $reviewType ) |
|
169 | 169 | { |
170 | - glsr(CountsManager::class)->decreaseAll($review); |
|
170 | + glsr( CountsManager::class )->decreaseAll( $review ); |
|
171 | 171 | $review->review_type = $reviewType; |
172 | - glsr(CountsManager::class)->increaseAll($review); |
|
172 | + glsr( CountsManager::class )->increaseAll( $review ); |
|
173 | 173 | } |
174 | 174 | } |
@@ -7,73 +7,73 @@ |
||
7 | 7 | |
8 | 8 | class GlobalCountsManager |
9 | 9 | { |
10 | - /** |
|
11 | - * @var CountsManager |
|
12 | - */ |
|
13 | - protected $manager; |
|
10 | + /** |
|
11 | + * @var CountsManager |
|
12 | + */ |
|
13 | + protected $manager; |
|
14 | 14 | |
15 | - public function __construct() |
|
16 | - { |
|
17 | - $this->manager = glsr(CountsManager::class); |
|
18 | - } |
|
15 | + public function __construct() |
|
16 | + { |
|
17 | + $this->manager = glsr(CountsManager::class); |
|
18 | + } |
|
19 | 19 | |
20 | - /** |
|
21 | - * @return array |
|
22 | - */ |
|
23 | - public function build() |
|
24 | - { |
|
25 | - return $this->manager->buildCounts(); |
|
26 | - } |
|
20 | + /** |
|
21 | + * @return array |
|
22 | + */ |
|
23 | + public function build() |
|
24 | + { |
|
25 | + return $this->manager->buildCounts(); |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * @return void |
|
30 | - */ |
|
31 | - public function decrease(Review $review) |
|
32 | - { |
|
33 | - $this->update($this->manager->decreaseRating( |
|
34 | - $this->get(), |
|
35 | - $review->review_type, |
|
36 | - $review->rating |
|
37 | - )); |
|
38 | - } |
|
28 | + /** |
|
29 | + * @return void |
|
30 | + */ |
|
31 | + public function decrease(Review $review) |
|
32 | + { |
|
33 | + $this->update($this->manager->decreaseRating( |
|
34 | + $this->get(), |
|
35 | + $review->review_type, |
|
36 | + $review->rating |
|
37 | + )); |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * @return array |
|
42 | - */ |
|
43 | - public function get() |
|
44 | - { |
|
45 | - $counts = glsr(OptionManager::class)->get('counts', []); |
|
46 | - if (!is_array($counts)) { |
|
47 | - glsr_log()->error('Review counts is not an array; possibly due to incorrectly imported reviews.')->debug($counts); |
|
48 | - return []; |
|
49 | - } |
|
50 | - return $counts; |
|
51 | - } |
|
40 | + /** |
|
41 | + * @return array |
|
42 | + */ |
|
43 | + public function get() |
|
44 | + { |
|
45 | + $counts = glsr(OptionManager::class)->get('counts', []); |
|
46 | + if (!is_array($counts)) { |
|
47 | + glsr_log()->error('Review counts is not an array; possibly due to incorrectly imported reviews.')->debug($counts); |
|
48 | + return []; |
|
49 | + } |
|
50 | + return $counts; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @return void |
|
55 | - */ |
|
56 | - public function increase(Review $review) |
|
57 | - { |
|
58 | - if (empty($counts = $this->get())) { |
|
59 | - $counts = $this->build(); |
|
60 | - } |
|
61 | - $this->update($this->manager->increaseRating($counts, $review->review_type, $review->rating)); |
|
62 | - } |
|
53 | + /** |
|
54 | + * @return void |
|
55 | + */ |
|
56 | + public function increase(Review $review) |
|
57 | + { |
|
58 | + if (empty($counts = $this->get())) { |
|
59 | + $counts = $this->build(); |
|
60 | + } |
|
61 | + $this->update($this->manager->increaseRating($counts, $review->review_type, $review->rating)); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @return void |
|
66 | - */ |
|
67 | - public function update(array $reviewCounts) |
|
68 | - { |
|
69 | - glsr(OptionManager::class)->set('counts', $reviewCounts); |
|
70 | - } |
|
64 | + /** |
|
65 | + * @return void |
|
66 | + */ |
|
67 | + public function update(array $reviewCounts) |
|
68 | + { |
|
69 | + glsr(OptionManager::class)->set('counts', $reviewCounts); |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * @return void |
|
74 | - */ |
|
75 | - public function updateAll() |
|
76 | - { |
|
77 | - $this->update($this->build()); |
|
78 | - } |
|
72 | + /** |
|
73 | + * @return void |
|
74 | + */ |
|
75 | + public function updateAll() |
|
76 | + { |
|
77 | + $this->update($this->build()); |
|
78 | + } |
|
79 | 79 | } |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | |
15 | 15 | public function __construct() |
16 | 16 | { |
17 | - $this->manager = glsr(CountsManager::class); |
|
17 | + $this->manager = glsr( CountsManager::class ); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | /** |
@@ -28,13 +28,13 @@ discard block |
||
28 | 28 | /** |
29 | 29 | * @return void |
30 | 30 | */ |
31 | - public function decrease(Review $review) |
|
31 | + public function decrease( Review $review ) |
|
32 | 32 | { |
33 | - $this->update($this->manager->decreaseRating( |
|
33 | + $this->update( $this->manager->decreaseRating( |
|
34 | 34 | $this->get(), |
35 | 35 | $review->review_type, |
36 | 36 | $review->rating |
37 | - )); |
|
37 | + ) ); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
@@ -42,9 +42,9 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function get() |
44 | 44 | { |
45 | - $counts = glsr(OptionManager::class)->get('counts', []); |
|
46 | - if (!is_array($counts)) { |
|
47 | - glsr_log()->error('Review counts is not an array; possibly due to incorrectly imported reviews.')->debug($counts); |
|
45 | + $counts = glsr( OptionManager::class )->get( 'counts', [] ); |
|
46 | + if( !is_array( $counts ) ) { |
|
47 | + glsr_log()->error( 'Review counts is not an array; possibly due to incorrectly imported reviews.' )->debug( $counts ); |
|
48 | 48 | return []; |
49 | 49 | } |
50 | 50 | return $counts; |
@@ -53,20 +53,20 @@ discard block |
||
53 | 53 | /** |
54 | 54 | * @return void |
55 | 55 | */ |
56 | - public function increase(Review $review) |
|
56 | + public function increase( Review $review ) |
|
57 | 57 | { |
58 | - if (empty($counts = $this->get())) { |
|
58 | + if( empty($counts = $this->get()) ) { |
|
59 | 59 | $counts = $this->build(); |
60 | 60 | } |
61 | - $this->update($this->manager->increaseRating($counts, $review->review_type, $review->rating)); |
|
61 | + $this->update( $this->manager->increaseRating( $counts, $review->review_type, $review->rating ) ); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
65 | 65 | * @return void |
66 | 66 | */ |
67 | - public function update(array $reviewCounts) |
|
67 | + public function update( array $reviewCounts ) |
|
68 | 68 | { |
69 | - glsr(OptionManager::class)->set('counts', $reviewCounts); |
|
69 | + glsr( OptionManager::class )->set( 'counts', $reviewCounts ); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
@@ -74,6 +74,6 @@ discard block |
||
74 | 74 | */ |
75 | 75 | public function updateAll() |
76 | 76 | { |
77 | - $this->update($this->build()); |
|
77 | + $this->update( $this->build() ); |
|
78 | 78 | } |
79 | 79 | } |
@@ -13,299 +13,299 @@ |
||
13 | 13 | |
14 | 14 | class ValidateReview |
15 | 15 | { |
16 | - const RECAPTCHA_ENDPOINT = 'https://www.google.com/recaptcha/api/siteverify'; |
|
16 | + const RECAPTCHA_ENDPOINT = 'https://www.google.com/recaptcha/api/siteverify'; |
|
17 | 17 | |
18 | - const RECAPTCHA_DISABLED = 0; |
|
19 | - const RECAPTCHA_EMPTY = 1; |
|
20 | - const RECAPTCHA_FAILED = 2; |
|
21 | - const RECAPTCHA_INVALID = 3; |
|
22 | - const RECAPTCHA_VALID = 4; |
|
18 | + const RECAPTCHA_DISABLED = 0; |
|
19 | + const RECAPTCHA_EMPTY = 1; |
|
20 | + const RECAPTCHA_FAILED = 2; |
|
21 | + const RECAPTCHA_INVALID = 3; |
|
22 | + const RECAPTCHA_VALID = 4; |
|
23 | 23 | |
24 | - const VALIDATION_RULES = [ |
|
25 | - 'content' => 'required', |
|
26 | - 'email' => 'required|email', |
|
27 | - 'name' => 'required', |
|
28 | - 'rating' => 'required|number|between:1,5', |
|
29 | - 'terms' => 'accepted', |
|
30 | - 'title' => 'required', |
|
31 | - ]; |
|
24 | + const VALIDATION_RULES = [ |
|
25 | + 'content' => 'required', |
|
26 | + 'email' => 'required|email', |
|
27 | + 'name' => 'required', |
|
28 | + 'rating' => 'required|number|between:1,5', |
|
29 | + 'terms' => 'accepted', |
|
30 | + 'title' => 'required', |
|
31 | + ]; |
|
32 | 32 | |
33 | - /** |
|
34 | - * @var string|void |
|
35 | - */ |
|
36 | - public $error; |
|
33 | + /** |
|
34 | + * @var string|void |
|
35 | + */ |
|
36 | + public $error; |
|
37 | 37 | |
38 | - /** |
|
39 | - * @var string |
|
40 | - */ |
|
41 | - public $form_id; |
|
38 | + /** |
|
39 | + * @var string |
|
40 | + */ |
|
41 | + public $form_id; |
|
42 | 42 | |
43 | - /** |
|
44 | - * @var bool |
|
45 | - */ |
|
46 | - public $recaptchaIsUnset = false; |
|
43 | + /** |
|
44 | + * @var bool |
|
45 | + */ |
|
46 | + public $recaptchaIsUnset = false; |
|
47 | 47 | |
48 | - /** |
|
49 | - * @var array |
|
50 | - */ |
|
51 | - public $request; |
|
48 | + /** |
|
49 | + * @var array |
|
50 | + */ |
|
51 | + public $request; |
|
52 | 52 | |
53 | - /** |
|
54 | - * @var array |
|
55 | - */ |
|
56 | - protected $options; |
|
53 | + /** |
|
54 | + * @var array |
|
55 | + */ |
|
56 | + protected $options; |
|
57 | 57 | |
58 | - /** |
|
59 | - * @return static |
|
60 | - */ |
|
61 | - public function validate(array $request) |
|
62 | - { |
|
63 | - $request['ip_address'] = Helper::getIpAddress(); // required for Akismet and Blacklist validation |
|
64 | - $this->form_id = $request['form_id']; |
|
65 | - $this->options = glsr(OptionManager::class)->all(); |
|
66 | - $this->request = $this->validateRequest($request); |
|
67 | - $this->validateCustom(); |
|
68 | - $this->validatePermission(); |
|
69 | - $this->validateHoneyPot(); |
|
70 | - $this->validateReviewLimits(); |
|
71 | - $this->validateBlacklist(); |
|
72 | - $this->validateAkismet(); |
|
73 | - $this->validateRecaptcha(); |
|
74 | - if (!empty($this->error)) { |
|
75 | - $this->setSessionValues('message', $this->error); |
|
76 | - } |
|
77 | - return $this; |
|
78 | - } |
|
58 | + /** |
|
59 | + * @return static |
|
60 | + */ |
|
61 | + public function validate(array $request) |
|
62 | + { |
|
63 | + $request['ip_address'] = Helper::getIpAddress(); // required for Akismet and Blacklist validation |
|
64 | + $this->form_id = $request['form_id']; |
|
65 | + $this->options = glsr(OptionManager::class)->all(); |
|
66 | + $this->request = $this->validateRequest($request); |
|
67 | + $this->validateCustom(); |
|
68 | + $this->validatePermission(); |
|
69 | + $this->validateHoneyPot(); |
|
70 | + $this->validateReviewLimits(); |
|
71 | + $this->validateBlacklist(); |
|
72 | + $this->validateAkismet(); |
|
73 | + $this->validateRecaptcha(); |
|
74 | + if (!empty($this->error)) { |
|
75 | + $this->setSessionValues('message', $this->error); |
|
76 | + } |
|
77 | + return $this; |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * @param string $path |
|
82 | - * @param mixed $fallback |
|
83 | - * @return mixed |
|
84 | - */ |
|
85 | - protected function getOption($path, $fallback = '') |
|
86 | - { |
|
87 | - return Arr::get($this->options, $path, $fallback); |
|
88 | - } |
|
80 | + /** |
|
81 | + * @param string $path |
|
82 | + * @param mixed $fallback |
|
83 | + * @return mixed |
|
84 | + */ |
|
85 | + protected function getOption($path, $fallback = '') |
|
86 | + { |
|
87 | + return Arr::get($this->options, $path, $fallback); |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * @return int |
|
92 | - */ |
|
93 | - protected function getRecaptchaStatus() |
|
94 | - { |
|
95 | - if (!glsr(OptionManager::class)->isRecaptchaEnabled()) { |
|
96 | - return static::RECAPTCHA_DISABLED; |
|
97 | - } |
|
98 | - if (empty($this->request['_recaptcha-token'])) { |
|
99 | - return $this->request['_counter'] < intval(apply_filters('site-reviews/recaptcha/timeout', 5)) |
|
100 | - ? static::RECAPTCHA_EMPTY |
|
101 | - : static::RECAPTCHA_FAILED; |
|
102 | - } |
|
103 | - return $this->getRecaptchaTokenStatus(); |
|
104 | - } |
|
90 | + /** |
|
91 | + * @return int |
|
92 | + */ |
|
93 | + protected function getRecaptchaStatus() |
|
94 | + { |
|
95 | + if (!glsr(OptionManager::class)->isRecaptchaEnabled()) { |
|
96 | + return static::RECAPTCHA_DISABLED; |
|
97 | + } |
|
98 | + if (empty($this->request['_recaptcha-token'])) { |
|
99 | + return $this->request['_counter'] < intval(apply_filters('site-reviews/recaptcha/timeout', 5)) |
|
100 | + ? static::RECAPTCHA_EMPTY |
|
101 | + : static::RECAPTCHA_FAILED; |
|
102 | + } |
|
103 | + return $this->getRecaptchaTokenStatus(); |
|
104 | + } |
|
105 | 105 | |
106 | - /** |
|
107 | - * @return int |
|
108 | - */ |
|
109 | - protected function getRecaptchaTokenStatus() |
|
110 | - { |
|
111 | - $endpoint = add_query_arg([ |
|
112 | - 'remoteip' => Helper::getIpAddress(), |
|
113 | - 'response' => $this->request['_recaptcha-token'], |
|
114 | - 'secret' => $this->getOption('settings.submissions.recaptcha.secret'), |
|
115 | - ], static::RECAPTCHA_ENDPOINT); |
|
116 | - if (is_wp_error($response = wp_remote_get($endpoint))) { |
|
117 | - glsr_log()->error($response->get_error_message()); |
|
118 | - return static::RECAPTCHA_FAILED; |
|
119 | - } |
|
120 | - $response = json_decode(wp_remote_retrieve_body($response)); |
|
121 | - if (!empty($response->success)) { |
|
122 | - return boolval($response->success) |
|
123 | - ? static::RECAPTCHA_VALID |
|
124 | - : static::RECAPTCHA_INVALID; |
|
125 | - } |
|
126 | - foreach ($response->{'error-codes'} as $error) { |
|
127 | - glsr_log()->error('reCAPTCHA error: '.$error); |
|
128 | - } |
|
129 | - return static::RECAPTCHA_INVALID; |
|
130 | - } |
|
106 | + /** |
|
107 | + * @return int |
|
108 | + */ |
|
109 | + protected function getRecaptchaTokenStatus() |
|
110 | + { |
|
111 | + $endpoint = add_query_arg([ |
|
112 | + 'remoteip' => Helper::getIpAddress(), |
|
113 | + 'response' => $this->request['_recaptcha-token'], |
|
114 | + 'secret' => $this->getOption('settings.submissions.recaptcha.secret'), |
|
115 | + ], static::RECAPTCHA_ENDPOINT); |
|
116 | + if (is_wp_error($response = wp_remote_get($endpoint))) { |
|
117 | + glsr_log()->error($response->get_error_message()); |
|
118 | + return static::RECAPTCHA_FAILED; |
|
119 | + } |
|
120 | + $response = json_decode(wp_remote_retrieve_body($response)); |
|
121 | + if (!empty($response->success)) { |
|
122 | + return boolval($response->success) |
|
123 | + ? static::RECAPTCHA_VALID |
|
124 | + : static::RECAPTCHA_INVALID; |
|
125 | + } |
|
126 | + foreach ($response->{'error-codes'} as $error) { |
|
127 | + glsr_log()->error('reCAPTCHA error: '.$error); |
|
128 | + } |
|
129 | + return static::RECAPTCHA_INVALID; |
|
130 | + } |
|
131 | 131 | |
132 | - /** |
|
133 | - * @return array |
|
134 | - */ |
|
135 | - protected function getValidationRules(array $request) |
|
136 | - { |
|
137 | - $rules = array_intersect_key( |
|
138 | - apply_filters('site-reviews/validation/rules', static::VALIDATION_RULES, $request), |
|
139 | - array_flip($this->getOption('settings.submissions.required', [])) |
|
140 | - ); |
|
141 | - $excluded = explode(',', Arr::get($request, 'excluded')); |
|
142 | - return array_diff_key($rules, array_flip($excluded)); |
|
143 | - } |
|
132 | + /** |
|
133 | + * @return array |
|
134 | + */ |
|
135 | + protected function getValidationRules(array $request) |
|
136 | + { |
|
137 | + $rules = array_intersect_key( |
|
138 | + apply_filters('site-reviews/validation/rules', static::VALIDATION_RULES, $request), |
|
139 | + array_flip($this->getOption('settings.submissions.required', [])) |
|
140 | + ); |
|
141 | + $excluded = explode(',', Arr::get($request, 'excluded')); |
|
142 | + return array_diff_key($rules, array_flip($excluded)); |
|
143 | + } |
|
144 | 144 | |
145 | - /** |
|
146 | - * @return bool |
|
147 | - */ |
|
148 | - protected function isRequestValid(array $request) |
|
149 | - { |
|
150 | - $rules = $this->getValidationRules($request); |
|
151 | - $errors = glsr(Validator::class)->validate($request, $rules); |
|
152 | - if (empty($errors)) { |
|
153 | - return true; |
|
154 | - } |
|
155 | - $this->error = __('Please fix the submission errors.', 'site-reviews'); |
|
156 | - $this->setSessionValues('errors', $errors); |
|
157 | - $this->setSessionValues('values', $request); |
|
158 | - return false; |
|
159 | - } |
|
145 | + /** |
|
146 | + * @return bool |
|
147 | + */ |
|
148 | + protected function isRequestValid(array $request) |
|
149 | + { |
|
150 | + $rules = $this->getValidationRules($request); |
|
151 | + $errors = glsr(Validator::class)->validate($request, $rules); |
|
152 | + if (empty($errors)) { |
|
153 | + return true; |
|
154 | + } |
|
155 | + $this->error = __('Please fix the submission errors.', 'site-reviews'); |
|
156 | + $this->setSessionValues('errors', $errors); |
|
157 | + $this->setSessionValues('values', $request); |
|
158 | + return false; |
|
159 | + } |
|
160 | 160 | |
161 | - protected function setError($message, $loggedMessage = '') |
|
162 | - { |
|
163 | - $this->setSessionValues('errors', [], $loggedMessage); |
|
164 | - $this->error = $message; |
|
165 | - } |
|
161 | + protected function setError($message, $loggedMessage = '') |
|
162 | + { |
|
163 | + $this->setSessionValues('errors', [], $loggedMessage); |
|
164 | + $this->error = $message; |
|
165 | + } |
|
166 | 166 | |
167 | - /** |
|
168 | - * @param string $type |
|
169 | - * @param mixed $value |
|
170 | - * @param string $loggedMessage |
|
171 | - * @return void |
|
172 | - */ |
|
173 | - protected function setSessionValues($type, $value, $loggedMessage = '') |
|
174 | - { |
|
175 | - glsr()->sessionSet($this->form_id.$type, $value); |
|
176 | - if (!empty($loggedMessage)) { |
|
177 | - glsr_log()->warning($loggedMessage)->debug($this->request); |
|
178 | - } |
|
179 | - } |
|
167 | + /** |
|
168 | + * @param string $type |
|
169 | + * @param mixed $value |
|
170 | + * @param string $loggedMessage |
|
171 | + * @return void |
|
172 | + */ |
|
173 | + protected function setSessionValues($type, $value, $loggedMessage = '') |
|
174 | + { |
|
175 | + glsr()->sessionSet($this->form_id.$type, $value); |
|
176 | + if (!empty($loggedMessage)) { |
|
177 | + glsr_log()->warning($loggedMessage)->debug($this->request); |
|
178 | + } |
|
179 | + } |
|
180 | 180 | |
181 | - /** |
|
182 | - * @return void |
|
183 | - */ |
|
184 | - protected function validateAkismet() |
|
185 | - { |
|
186 | - if (!empty($this->error)) { |
|
187 | - return; |
|
188 | - } |
|
189 | - if (glsr(Akismet::class)->isSpam($this->request)) { |
|
190 | - $this->setError(__('This review has been flagged as possible spam and cannot be submitted.', 'site-reviews'), |
|
191 | - 'Akismet caught a spam submission (consider adding the IP address to the blacklist):' |
|
192 | - ); |
|
193 | - } |
|
194 | - } |
|
181 | + /** |
|
182 | + * @return void |
|
183 | + */ |
|
184 | + protected function validateAkismet() |
|
185 | + { |
|
186 | + if (!empty($this->error)) { |
|
187 | + return; |
|
188 | + } |
|
189 | + if (glsr(Akismet::class)->isSpam($this->request)) { |
|
190 | + $this->setError(__('This review has been flagged as possible spam and cannot be submitted.', 'site-reviews'), |
|
191 | + 'Akismet caught a spam submission (consider adding the IP address to the blacklist):' |
|
192 | + ); |
|
193 | + } |
|
194 | + } |
|
195 | 195 | |
196 | - /** |
|
197 | - * @return void |
|
198 | - */ |
|
199 | - protected function validateBlacklist() |
|
200 | - { |
|
201 | - if (!empty($this->error)) { |
|
202 | - return; |
|
203 | - } |
|
204 | - if (!glsr(Blacklist::class)->isBlacklisted($this->request)) { |
|
205 | - return; |
|
206 | - } |
|
207 | - $blacklistAction = $this->getOption('settings.submissions.blacklist.action'); |
|
208 | - if ('reject' != $blacklistAction) { |
|
209 | - $this->request['blacklisted'] = true; |
|
210 | - return; |
|
211 | - } |
|
212 | - $this->setError(__('Your review cannot be submitted at this time.', 'site-reviews'), |
|
213 | - 'Blacklisted submission detected:' |
|
214 | - ); |
|
215 | - } |
|
196 | + /** |
|
197 | + * @return void |
|
198 | + */ |
|
199 | + protected function validateBlacklist() |
|
200 | + { |
|
201 | + if (!empty($this->error)) { |
|
202 | + return; |
|
203 | + } |
|
204 | + if (!glsr(Blacklist::class)->isBlacklisted($this->request)) { |
|
205 | + return; |
|
206 | + } |
|
207 | + $blacklistAction = $this->getOption('settings.submissions.blacklist.action'); |
|
208 | + if ('reject' != $blacklistAction) { |
|
209 | + $this->request['blacklisted'] = true; |
|
210 | + return; |
|
211 | + } |
|
212 | + $this->setError(__('Your review cannot be submitted at this time.', 'site-reviews'), |
|
213 | + 'Blacklisted submission detected:' |
|
214 | + ); |
|
215 | + } |
|
216 | 216 | |
217 | - /** |
|
218 | - * @return void |
|
219 | - */ |
|
220 | - protected function validateCustom() |
|
221 | - { |
|
222 | - if (!empty($this->error)) { |
|
223 | - return; |
|
224 | - } |
|
225 | - $validated = apply_filters('site-reviews/validate/custom', true, $this->request); |
|
226 | - if (true === $validated) { |
|
227 | - return; |
|
228 | - } |
|
229 | - $errorMessage = is_string($validated) |
|
230 | - ? $validated |
|
231 | - : __('The review submission failed. Please notify the site administrator.', 'site-reviews'); |
|
232 | - $this->setError($errorMessage); |
|
233 | - $this->setSessionValues('values', $this->request); |
|
234 | - } |
|
217 | + /** |
|
218 | + * @return void |
|
219 | + */ |
|
220 | + protected function validateCustom() |
|
221 | + { |
|
222 | + if (!empty($this->error)) { |
|
223 | + return; |
|
224 | + } |
|
225 | + $validated = apply_filters('site-reviews/validate/custom', true, $this->request); |
|
226 | + if (true === $validated) { |
|
227 | + return; |
|
228 | + } |
|
229 | + $errorMessage = is_string($validated) |
|
230 | + ? $validated |
|
231 | + : __('The review submission failed. Please notify the site administrator.', 'site-reviews'); |
|
232 | + $this->setError($errorMessage); |
|
233 | + $this->setSessionValues('values', $this->request); |
|
234 | + } |
|
235 | 235 | |
236 | - /** |
|
237 | - * @return void |
|
238 | - */ |
|
239 | - protected function validateHoneyPot() |
|
240 | - { |
|
241 | - if (!empty($this->error)) { |
|
242 | - return; |
|
243 | - } |
|
244 | - if (!empty($this->request['gotcha'])) { |
|
245 | - $this->setError(__('The review submission failed. Please notify the site administrator.', 'site-reviews'), |
|
246 | - 'The Honeypot caught a bad submission:' |
|
247 | - ); |
|
248 | - } |
|
249 | - } |
|
236 | + /** |
|
237 | + * @return void |
|
238 | + */ |
|
239 | + protected function validateHoneyPot() |
|
240 | + { |
|
241 | + if (!empty($this->error)) { |
|
242 | + return; |
|
243 | + } |
|
244 | + if (!empty($this->request['gotcha'])) { |
|
245 | + $this->setError(__('The review submission failed. Please notify the site administrator.', 'site-reviews'), |
|
246 | + 'The Honeypot caught a bad submission:' |
|
247 | + ); |
|
248 | + } |
|
249 | + } |
|
250 | 250 | |
251 | - /** |
|
252 | - * @return void |
|
253 | - */ |
|
254 | - protected function validatePermission() |
|
255 | - { |
|
256 | - if (!empty($this->error)) { |
|
257 | - return; |
|
258 | - } |
|
259 | - if (!is_user_logged_in() && glsr(OptionManager::class)->getBool('settings.general.require.login')) { |
|
260 | - $this->setError(__('You must be logged in to submit a review.', 'site-reviews')); |
|
261 | - } |
|
262 | - } |
|
251 | + /** |
|
252 | + * @return void |
|
253 | + */ |
|
254 | + protected function validatePermission() |
|
255 | + { |
|
256 | + if (!empty($this->error)) { |
|
257 | + return; |
|
258 | + } |
|
259 | + if (!is_user_logged_in() && glsr(OptionManager::class)->getBool('settings.general.require.login')) { |
|
260 | + $this->setError(__('You must be logged in to submit a review.', 'site-reviews')); |
|
261 | + } |
|
262 | + } |
|
263 | 263 | |
264 | - /** |
|
265 | - * @return void |
|
266 | - */ |
|
267 | - protected function validateReviewLimits() |
|
268 | - { |
|
269 | - if (!empty($this->error)) { |
|
270 | - return; |
|
271 | - } |
|
272 | - if (glsr(ReviewLimits::class)->hasReachedLimit($this->request)) { |
|
273 | - $this->setError(__('You have already submitted a review.', 'site-reviews')); |
|
274 | - } |
|
275 | - } |
|
264 | + /** |
|
265 | + * @return void |
|
266 | + */ |
|
267 | + protected function validateReviewLimits() |
|
268 | + { |
|
269 | + if (!empty($this->error)) { |
|
270 | + return; |
|
271 | + } |
|
272 | + if (glsr(ReviewLimits::class)->hasReachedLimit($this->request)) { |
|
273 | + $this->setError(__('You have already submitted a review.', 'site-reviews')); |
|
274 | + } |
|
275 | + } |
|
276 | 276 | |
277 | - /** |
|
278 | - * @return void |
|
279 | - */ |
|
280 | - protected function validateRecaptcha() |
|
281 | - { |
|
282 | - if (!empty($this->error)) { |
|
283 | - return; |
|
284 | - } |
|
285 | - $status = $this->getRecaptchaStatus(); |
|
286 | - if (in_array($status, [static::RECAPTCHA_DISABLED, static::RECAPTCHA_VALID])) { |
|
287 | - return; |
|
288 | - } |
|
289 | - if (static::RECAPTCHA_EMPTY === $status) { |
|
290 | - $this->setSessionValues('recaptcha', 'unset'); |
|
291 | - $this->recaptchaIsUnset = true; |
|
292 | - return; |
|
293 | - } |
|
294 | - $this->setSessionValues('recaptcha', 'reset'); |
|
295 | - $errors = [ |
|
296 | - static::RECAPTCHA_FAILED => __('The reCAPTCHA failed to load, please refresh the page and try again.', 'site-reviews'), |
|
297 | - static::RECAPTCHA_INVALID => __('The reCAPTCHA verification failed, please try again.', 'site-reviews'), |
|
298 | - ]; |
|
299 | - $this->setError($errors[$status]); |
|
300 | - } |
|
277 | + /** |
|
278 | + * @return void |
|
279 | + */ |
|
280 | + protected function validateRecaptcha() |
|
281 | + { |
|
282 | + if (!empty($this->error)) { |
|
283 | + return; |
|
284 | + } |
|
285 | + $status = $this->getRecaptchaStatus(); |
|
286 | + if (in_array($status, [static::RECAPTCHA_DISABLED, static::RECAPTCHA_VALID])) { |
|
287 | + return; |
|
288 | + } |
|
289 | + if (static::RECAPTCHA_EMPTY === $status) { |
|
290 | + $this->setSessionValues('recaptcha', 'unset'); |
|
291 | + $this->recaptchaIsUnset = true; |
|
292 | + return; |
|
293 | + } |
|
294 | + $this->setSessionValues('recaptcha', 'reset'); |
|
295 | + $errors = [ |
|
296 | + static::RECAPTCHA_FAILED => __('The reCAPTCHA failed to load, please refresh the page and try again.', 'site-reviews'), |
|
297 | + static::RECAPTCHA_INVALID => __('The reCAPTCHA verification failed, please try again.', 'site-reviews'), |
|
298 | + ]; |
|
299 | + $this->setError($errors[$status]); |
|
300 | + } |
|
301 | 301 | |
302 | - /** |
|
303 | - * @return array |
|
304 | - */ |
|
305 | - protected function validateRequest(array $request) |
|
306 | - { |
|
307 | - return $this->isRequestValid($request) |
|
308 | - ? array_merge(glsr(ValidateReviewDefaults::class)->defaults(), $request) |
|
309 | - : $request; |
|
310 | - } |
|
302 | + /** |
|
303 | + * @return array |
|
304 | + */ |
|
305 | + protected function validateRequest(array $request) |
|
306 | + { |
|
307 | + return $this->isRequestValid($request) |
|
308 | + ? array_merge(glsr(ValidateReviewDefaults::class)->defaults(), $request) |
|
309 | + : $request; |
|
310 | + } |
|
311 | 311 | } |
@@ -58,12 +58,12 @@ discard block |
||
58 | 58 | /** |
59 | 59 | * @return static |
60 | 60 | */ |
61 | - public function validate(array $request) |
|
61 | + public function validate( array $request ) |
|
62 | 62 | { |
63 | 63 | $request['ip_address'] = Helper::getIpAddress(); // required for Akismet and Blacklist validation |
64 | 64 | $this->form_id = $request['form_id']; |
65 | - $this->options = glsr(OptionManager::class)->all(); |
|
66 | - $this->request = $this->validateRequest($request); |
|
65 | + $this->options = glsr( OptionManager::class )->all(); |
|
66 | + $this->request = $this->validateRequest( $request ); |
|
67 | 67 | $this->validateCustom(); |
68 | 68 | $this->validatePermission(); |
69 | 69 | $this->validateHoneyPot(); |
@@ -71,8 +71,8 @@ discard block |
||
71 | 71 | $this->validateBlacklist(); |
72 | 72 | $this->validateAkismet(); |
73 | 73 | $this->validateRecaptcha(); |
74 | - if (!empty($this->error)) { |
|
75 | - $this->setSessionValues('message', $this->error); |
|
74 | + if( !empty($this->error) ) { |
|
75 | + $this->setSessionValues( 'message', $this->error ); |
|
76 | 76 | } |
77 | 77 | return $this; |
78 | 78 | } |
@@ -82,9 +82,9 @@ discard block |
||
82 | 82 | * @param mixed $fallback |
83 | 83 | * @return mixed |
84 | 84 | */ |
85 | - protected function getOption($path, $fallback = '') |
|
85 | + protected function getOption( $path, $fallback = '' ) |
|
86 | 86 | { |
87 | - return Arr::get($this->options, $path, $fallback); |
|
87 | + return Arr::get( $this->options, $path, $fallback ); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
@@ -92,11 +92,11 @@ discard block |
||
92 | 92 | */ |
93 | 93 | protected function getRecaptchaStatus() |
94 | 94 | { |
95 | - if (!glsr(OptionManager::class)->isRecaptchaEnabled()) { |
|
95 | + if( !glsr( OptionManager::class )->isRecaptchaEnabled() ) { |
|
96 | 96 | return static::RECAPTCHA_DISABLED; |
97 | 97 | } |
98 | - if (empty($this->request['_recaptcha-token'])) { |
|
99 | - return $this->request['_counter'] < intval(apply_filters('site-reviews/recaptcha/timeout', 5)) |
|
98 | + if( empty($this->request['_recaptcha-token']) ) { |
|
99 | + return $this->request['_counter'] < intval( apply_filters( 'site-reviews/recaptcha/timeout', 5 ) ) |
|
100 | 100 | ? static::RECAPTCHA_EMPTY |
101 | 101 | : static::RECAPTCHA_FAILED; |
102 | 102 | } |
@@ -108,23 +108,23 @@ discard block |
||
108 | 108 | */ |
109 | 109 | protected function getRecaptchaTokenStatus() |
110 | 110 | { |
111 | - $endpoint = add_query_arg([ |
|
111 | + $endpoint = add_query_arg( [ |
|
112 | 112 | 'remoteip' => Helper::getIpAddress(), |
113 | 113 | 'response' => $this->request['_recaptcha-token'], |
114 | - 'secret' => $this->getOption('settings.submissions.recaptcha.secret'), |
|
115 | - ], static::RECAPTCHA_ENDPOINT); |
|
116 | - if (is_wp_error($response = wp_remote_get($endpoint))) { |
|
117 | - glsr_log()->error($response->get_error_message()); |
|
114 | + 'secret' => $this->getOption( 'settings.submissions.recaptcha.secret' ), |
|
115 | + ], static::RECAPTCHA_ENDPOINT ); |
|
116 | + if( is_wp_error( $response = wp_remote_get( $endpoint ) ) ) { |
|
117 | + glsr_log()->error( $response->get_error_message() ); |
|
118 | 118 | return static::RECAPTCHA_FAILED; |
119 | 119 | } |
120 | - $response = json_decode(wp_remote_retrieve_body($response)); |
|
121 | - if (!empty($response->success)) { |
|
122 | - return boolval($response->success) |
|
120 | + $response = json_decode( wp_remote_retrieve_body( $response ) ); |
|
121 | + if( !empty($response->success) ) { |
|
122 | + return boolval( $response->success ) |
|
123 | 123 | ? static::RECAPTCHA_VALID |
124 | 124 | : static::RECAPTCHA_INVALID; |
125 | 125 | } |
126 | - foreach ($response->{'error-codes'} as $error) { |
|
127 | - glsr_log()->error('reCAPTCHA error: '.$error); |
|
126 | + foreach( $response->{'error-codes'} as $error ) { |
|
127 | + glsr_log()->error( 'reCAPTCHA error: '.$error ); |
|
128 | 128 | } |
129 | 129 | return static::RECAPTCHA_INVALID; |
130 | 130 | } |
@@ -132,35 +132,35 @@ discard block |
||
132 | 132 | /** |
133 | 133 | * @return array |
134 | 134 | */ |
135 | - protected function getValidationRules(array $request) |
|
135 | + protected function getValidationRules( array $request ) |
|
136 | 136 | { |
137 | 137 | $rules = array_intersect_key( |
138 | - apply_filters('site-reviews/validation/rules', static::VALIDATION_RULES, $request), |
|
139 | - array_flip($this->getOption('settings.submissions.required', [])) |
|
138 | + apply_filters( 'site-reviews/validation/rules', static::VALIDATION_RULES, $request ), |
|
139 | + array_flip( $this->getOption( 'settings.submissions.required', [] ) ) |
|
140 | 140 | ); |
141 | - $excluded = explode(',', Arr::get($request, 'excluded')); |
|
142 | - return array_diff_key($rules, array_flip($excluded)); |
|
141 | + $excluded = explode( ',', Arr::get( $request, 'excluded' ) ); |
|
142 | + return array_diff_key( $rules, array_flip( $excluded ) ); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | /** |
146 | 146 | * @return bool |
147 | 147 | */ |
148 | - protected function isRequestValid(array $request) |
|
148 | + protected function isRequestValid( array $request ) |
|
149 | 149 | { |
150 | - $rules = $this->getValidationRules($request); |
|
151 | - $errors = glsr(Validator::class)->validate($request, $rules); |
|
152 | - if (empty($errors)) { |
|
150 | + $rules = $this->getValidationRules( $request ); |
|
151 | + $errors = glsr( Validator::class )->validate( $request, $rules ); |
|
152 | + if( empty($errors) ) { |
|
153 | 153 | return true; |
154 | 154 | } |
155 | - $this->error = __('Please fix the submission errors.', 'site-reviews'); |
|
156 | - $this->setSessionValues('errors', $errors); |
|
157 | - $this->setSessionValues('values', $request); |
|
155 | + $this->error = __( 'Please fix the submission errors.', 'site-reviews' ); |
|
156 | + $this->setSessionValues( 'errors', $errors ); |
|
157 | + $this->setSessionValues( 'values', $request ); |
|
158 | 158 | return false; |
159 | 159 | } |
160 | 160 | |
161 | - protected function setError($message, $loggedMessage = '') |
|
161 | + protected function setError( $message, $loggedMessage = '' ) |
|
162 | 162 | { |
163 | - $this->setSessionValues('errors', [], $loggedMessage); |
|
163 | + $this->setSessionValues( 'errors', [], $loggedMessage ); |
|
164 | 164 | $this->error = $message; |
165 | 165 | } |
166 | 166 | |
@@ -170,11 +170,11 @@ discard block |
||
170 | 170 | * @param string $loggedMessage |
171 | 171 | * @return void |
172 | 172 | */ |
173 | - protected function setSessionValues($type, $value, $loggedMessage = '') |
|
173 | + protected function setSessionValues( $type, $value, $loggedMessage = '' ) |
|
174 | 174 | { |
175 | - glsr()->sessionSet($this->form_id.$type, $value); |
|
176 | - if (!empty($loggedMessage)) { |
|
177 | - glsr_log()->warning($loggedMessage)->debug($this->request); |
|
175 | + glsr()->sessionSet( $this->form_id.$type, $value ); |
|
176 | + if( !empty($loggedMessage) ) { |
|
177 | + glsr_log()->warning( $loggedMessage )->debug( $this->request ); |
|
178 | 178 | } |
179 | 179 | } |
180 | 180 | |
@@ -183,11 +183,11 @@ discard block |
||
183 | 183 | */ |
184 | 184 | protected function validateAkismet() |
185 | 185 | { |
186 | - if (!empty($this->error)) { |
|
186 | + if( !empty($this->error) ) { |
|
187 | 187 | return; |
188 | 188 | } |
189 | - if (glsr(Akismet::class)->isSpam($this->request)) { |
|
190 | - $this->setError(__('This review has been flagged as possible spam and cannot be submitted.', 'site-reviews'), |
|
189 | + if( glsr( Akismet::class )->isSpam( $this->request ) ) { |
|
190 | + $this->setError( __( 'This review has been flagged as possible spam and cannot be submitted.', 'site-reviews' ), |
|
191 | 191 | 'Akismet caught a spam submission (consider adding the IP address to the blacklist):' |
192 | 192 | ); |
193 | 193 | } |
@@ -198,18 +198,18 @@ discard block |
||
198 | 198 | */ |
199 | 199 | protected function validateBlacklist() |
200 | 200 | { |
201 | - if (!empty($this->error)) { |
|
201 | + if( !empty($this->error) ) { |
|
202 | 202 | return; |
203 | 203 | } |
204 | - if (!glsr(Blacklist::class)->isBlacklisted($this->request)) { |
|
204 | + if( !glsr( Blacklist::class )->isBlacklisted( $this->request ) ) { |
|
205 | 205 | return; |
206 | 206 | } |
207 | - $blacklistAction = $this->getOption('settings.submissions.blacklist.action'); |
|
208 | - if ('reject' != $blacklistAction) { |
|
207 | + $blacklistAction = $this->getOption( 'settings.submissions.blacklist.action' ); |
|
208 | + if( 'reject' != $blacklistAction ) { |
|
209 | 209 | $this->request['blacklisted'] = true; |
210 | 210 | return; |
211 | 211 | } |
212 | - $this->setError(__('Your review cannot be submitted at this time.', 'site-reviews'), |
|
212 | + $this->setError( __( 'Your review cannot be submitted at this time.', 'site-reviews' ), |
|
213 | 213 | 'Blacklisted submission detected:' |
214 | 214 | ); |
215 | 215 | } |
@@ -219,18 +219,18 @@ discard block |
||
219 | 219 | */ |
220 | 220 | protected function validateCustom() |
221 | 221 | { |
222 | - if (!empty($this->error)) { |
|
222 | + if( !empty($this->error) ) { |
|
223 | 223 | return; |
224 | 224 | } |
225 | - $validated = apply_filters('site-reviews/validate/custom', true, $this->request); |
|
226 | - if (true === $validated) { |
|
225 | + $validated = apply_filters( 'site-reviews/validate/custom', true, $this->request ); |
|
226 | + if( true === $validated ) { |
|
227 | 227 | return; |
228 | 228 | } |
229 | - $errorMessage = is_string($validated) |
|
229 | + $errorMessage = is_string( $validated ) |
|
230 | 230 | ? $validated |
231 | - : __('The review submission failed. Please notify the site administrator.', 'site-reviews'); |
|
232 | - $this->setError($errorMessage); |
|
233 | - $this->setSessionValues('values', $this->request); |
|
231 | + : __( 'The review submission failed. Please notify the site administrator.', 'site-reviews' ); |
|
232 | + $this->setError( $errorMessage ); |
|
233 | + $this->setSessionValues( 'values', $this->request ); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | /** |
@@ -238,11 +238,11 @@ discard block |
||
238 | 238 | */ |
239 | 239 | protected function validateHoneyPot() |
240 | 240 | { |
241 | - if (!empty($this->error)) { |
|
241 | + if( !empty($this->error) ) { |
|
242 | 242 | return; |
243 | 243 | } |
244 | - if (!empty($this->request['gotcha'])) { |
|
245 | - $this->setError(__('The review submission failed. Please notify the site administrator.', 'site-reviews'), |
|
244 | + if( !empty($this->request['gotcha']) ) { |
|
245 | + $this->setError( __( 'The review submission failed. Please notify the site administrator.', 'site-reviews' ), |
|
246 | 246 | 'The Honeypot caught a bad submission:' |
247 | 247 | ); |
248 | 248 | } |
@@ -253,11 +253,11 @@ discard block |
||
253 | 253 | */ |
254 | 254 | protected function validatePermission() |
255 | 255 | { |
256 | - if (!empty($this->error)) { |
|
256 | + if( !empty($this->error) ) { |
|
257 | 257 | return; |
258 | 258 | } |
259 | - if (!is_user_logged_in() && glsr(OptionManager::class)->getBool('settings.general.require.login')) { |
|
260 | - $this->setError(__('You must be logged in to submit a review.', 'site-reviews')); |
|
259 | + if( !is_user_logged_in() && glsr( OptionManager::class )->getBool( 'settings.general.require.login' ) ) { |
|
260 | + $this->setError( __( 'You must be logged in to submit a review.', 'site-reviews' ) ); |
|
261 | 261 | } |
262 | 262 | } |
263 | 263 | |
@@ -266,11 +266,11 @@ discard block |
||
266 | 266 | */ |
267 | 267 | protected function validateReviewLimits() |
268 | 268 | { |
269 | - if (!empty($this->error)) { |
|
269 | + if( !empty($this->error) ) { |
|
270 | 270 | return; |
271 | 271 | } |
272 | - if (glsr(ReviewLimits::class)->hasReachedLimit($this->request)) { |
|
273 | - $this->setError(__('You have already submitted a review.', 'site-reviews')); |
|
272 | + if( glsr( ReviewLimits::class )->hasReachedLimit( $this->request ) ) { |
|
273 | + $this->setError( __( 'You have already submitted a review.', 'site-reviews' ) ); |
|
274 | 274 | } |
275 | 275 | } |
276 | 276 | |
@@ -279,33 +279,33 @@ discard block |
||
279 | 279 | */ |
280 | 280 | protected function validateRecaptcha() |
281 | 281 | { |
282 | - if (!empty($this->error)) { |
|
282 | + if( !empty($this->error) ) { |
|
283 | 283 | return; |
284 | 284 | } |
285 | 285 | $status = $this->getRecaptchaStatus(); |
286 | - if (in_array($status, [static::RECAPTCHA_DISABLED, static::RECAPTCHA_VALID])) { |
|
286 | + if( in_array( $status, [static::RECAPTCHA_DISABLED, static::RECAPTCHA_VALID] ) ) { |
|
287 | 287 | return; |
288 | 288 | } |
289 | - if (static::RECAPTCHA_EMPTY === $status) { |
|
290 | - $this->setSessionValues('recaptcha', 'unset'); |
|
289 | + if( static::RECAPTCHA_EMPTY === $status ) { |
|
290 | + $this->setSessionValues( 'recaptcha', 'unset' ); |
|
291 | 291 | $this->recaptchaIsUnset = true; |
292 | 292 | return; |
293 | 293 | } |
294 | - $this->setSessionValues('recaptcha', 'reset'); |
|
294 | + $this->setSessionValues( 'recaptcha', 'reset' ); |
|
295 | 295 | $errors = [ |
296 | - static::RECAPTCHA_FAILED => __('The reCAPTCHA failed to load, please refresh the page and try again.', 'site-reviews'), |
|
297 | - static::RECAPTCHA_INVALID => __('The reCAPTCHA verification failed, please try again.', 'site-reviews'), |
|
296 | + static::RECAPTCHA_FAILED => __( 'The reCAPTCHA failed to load, please refresh the page and try again.', 'site-reviews' ), |
|
297 | + static::RECAPTCHA_INVALID => __( 'The reCAPTCHA verification failed, please try again.', 'site-reviews' ), |
|
298 | 298 | ]; |
299 | - $this->setError($errors[$status]); |
|
299 | + $this->setError( $errors[$status] ); |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | /** |
303 | 303 | * @return array |
304 | 304 | */ |
305 | - protected function validateRequest(array $request) |
|
305 | + protected function validateRequest( array $request ) |
|
306 | 306 | { |
307 | - return $this->isRequestValid($request) |
|
308 | - ? array_merge(glsr(ValidateReviewDefaults::class)->defaults(), $request) |
|
307 | + return $this->isRequestValid( $request ) |
|
308 | + ? array_merge( glsr( ValidateReviewDefaults::class )->defaults(), $request ) |
|
309 | 309 | : $request; |
310 | 310 | } |
311 | 311 | } |