@@ -4,23 +4,23 @@ |
||
4 | 4 | |
5 | 5 | class Checkbox extends Field |
6 | 6 | { |
7 | - /** |
|
8 | - * @return array |
|
9 | - */ |
|
10 | - public static function defaults() |
|
11 | - { |
|
12 | - return [ |
|
13 | - 'value' => 1, |
|
14 | - ]; |
|
15 | - } |
|
7 | + /** |
|
8 | + * @return array |
|
9 | + */ |
|
10 | + public static function defaults() |
|
11 | + { |
|
12 | + return [ |
|
13 | + 'value' => 1, |
|
14 | + ]; |
|
15 | + } |
|
16 | 16 | |
17 | - /** |
|
18 | - * @return array |
|
19 | - */ |
|
20 | - public static function required() |
|
21 | - { |
|
22 | - return [ |
|
23 | - 'is_multi' => true, |
|
24 | - ]; |
|
25 | - } |
|
17 | + /** |
|
18 | + * @return array |
|
19 | + */ |
|
20 | + public static function required() |
|
21 | + { |
|
22 | + return [ |
|
23 | + 'is_multi' => true, |
|
24 | + ]; |
|
25 | + } |
|
26 | 26 | } |
@@ -6,29 +6,29 @@ |
||
6 | 6 | |
7 | 7 | class Rating extends Field |
8 | 8 | { |
9 | - /** |
|
10 | - * @return string|void |
|
11 | - */ |
|
12 | - public function build() |
|
13 | - { |
|
14 | - $this->builder->tag = 'select'; |
|
15 | - $this->mergeFieldArgs(); |
|
16 | - return $this->builder->getTag(); |
|
17 | - } |
|
9 | + /** |
|
10 | + * @return string|void |
|
11 | + */ |
|
12 | + public function build() |
|
13 | + { |
|
14 | + $this->builder->tag = 'select'; |
|
15 | + $this->mergeFieldArgs(); |
|
16 | + return $this->builder->getTag(); |
|
17 | + } |
|
18 | 18 | |
19 | - /** |
|
20 | - * @return array |
|
21 | - */ |
|
22 | - public static function required() |
|
23 | - { |
|
24 | - $options = ['' => __('Select a Rating', 'site-reviews')]; |
|
25 | - foreach (range(glsr()->constant('MAX_RATING', RatingModule::class), 1) as $rating) { |
|
26 | - $options[$rating] = sprintf(_n('%s Star', '%s Stars', $rating, 'site-reviews'), $rating); |
|
27 | - } |
|
28 | - return [ |
|
29 | - 'class' => 'glsr-star-rating', |
|
30 | - 'options' => $options, |
|
31 | - 'type' => 'select', |
|
32 | - ]; |
|
33 | - } |
|
19 | + /** |
|
20 | + * @return array |
|
21 | + */ |
|
22 | + public static function required() |
|
23 | + { |
|
24 | + $options = ['' => __('Select a Rating', 'site-reviews')]; |
|
25 | + foreach (range(glsr()->constant('MAX_RATING', RatingModule::class), 1) as $rating) { |
|
26 | + $options[$rating] = sprintf(_n('%s Star', '%s Stars', $rating, 'site-reviews'), $rating); |
|
27 | + } |
|
28 | + return [ |
|
29 | + 'class' => 'glsr-star-rating', |
|
30 | + 'options' => $options, |
|
31 | + 'type' => 'select', |
|
32 | + ]; |
|
33 | + } |
|
34 | 34 | } |
@@ -21,9 +21,9 @@ |
||
21 | 21 | */ |
22 | 22 | public static function required() |
23 | 23 | { |
24 | - $options = ['' => __('Select a Rating', 'site-reviews')]; |
|
25 | - foreach (range(glsr()->constant('MAX_RATING', RatingModule::class), 1) as $rating) { |
|
26 | - $options[$rating] = sprintf(_n('%s Star', '%s Stars', $rating, 'site-reviews'), $rating); |
|
24 | + $options = ['' => __( 'Select a Rating', 'site-reviews' )]; |
|
25 | + foreach( range( glsr()->constant( 'MAX_RATING', RatingModule::class ), 1 ) as $rating ) { |
|
26 | + $options[$rating] = sprintf( _n( '%s Star', '%s Stars', $rating, 'site-reviews' ), $rating ); |
|
27 | 27 | } |
28 | 28 | return [ |
29 | 29 | 'class' => 'glsr-star-rating', |
@@ -4,36 +4,36 @@ |
||
4 | 4 | |
5 | 5 | class Form |
6 | 6 | { |
7 | - /** |
|
8 | - * @param string $id |
|
9 | - * @return string |
|
10 | - */ |
|
11 | - public function buildFields($id) |
|
12 | - { |
|
13 | - return array_reduce($this->getFields($id), function ($carry, $field) { |
|
14 | - return $carry.$field; |
|
15 | - }); |
|
16 | - } |
|
7 | + /** |
|
8 | + * @param string $id |
|
9 | + * @return string |
|
10 | + */ |
|
11 | + public function buildFields($id) |
|
12 | + { |
|
13 | + return array_reduce($this->getFields($id), function ($carry, $field) { |
|
14 | + return $carry.$field; |
|
15 | + }); |
|
16 | + } |
|
17 | 17 | |
18 | - /** |
|
19 | - * @param string $id |
|
20 | - * @return array |
|
21 | - */ |
|
22 | - public function getFields($id) |
|
23 | - { |
|
24 | - $fields = []; |
|
25 | - foreach (glsr()->config('forms/'.$id) as $name => $field) { |
|
26 | - $fields[] = new Field(wp_parse_args($field, ['name' => $name])); |
|
27 | - } |
|
28 | - return $fields; |
|
29 | - } |
|
18 | + /** |
|
19 | + * @param string $id |
|
20 | + * @return array |
|
21 | + */ |
|
22 | + public function getFields($id) |
|
23 | + { |
|
24 | + $fields = []; |
|
25 | + foreach (glsr()->config('forms/'.$id) as $name => $field) { |
|
26 | + $fields[] = new Field(wp_parse_args($field, ['name' => $name])); |
|
27 | + } |
|
28 | + return $fields; |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * @param string $id |
|
33 | - * @return void |
|
34 | - */ |
|
35 | - public function renderFields($id) |
|
36 | - { |
|
37 | - echo $this->buildFields($id); |
|
38 | - } |
|
31 | + /** |
|
32 | + * @param string $id |
|
33 | + * @return void |
|
34 | + */ |
|
35 | + public function renderFields($id) |
|
36 | + { |
|
37 | + echo $this->buildFields($id); |
|
38 | + } |
|
39 | 39 | } |
@@ -8,9 +8,9 @@ discard block |
||
8 | 8 | * @param string $id |
9 | 9 | * @return string |
10 | 10 | */ |
11 | - public function buildFields($id) |
|
11 | + public function buildFields( $id ) |
|
12 | 12 | { |
13 | - return array_reduce($this->getFields($id), function ($carry, $field) { |
|
13 | + return array_reduce( $this->getFields( $id ), function( $carry, $field ) { |
|
14 | 14 | return $carry.$field; |
15 | 15 | }); |
16 | 16 | } |
@@ -19,11 +19,11 @@ discard block |
||
19 | 19 | * @param string $id |
20 | 20 | * @return array |
21 | 21 | */ |
22 | - public function getFields($id) |
|
22 | + public function getFields( $id ) |
|
23 | 23 | { |
24 | 24 | $fields = []; |
25 | - foreach (glsr()->config('forms/'.$id) as $name => $field) { |
|
26 | - $fields[] = new Field(wp_parse_args($field, ['name' => $name])); |
|
25 | + foreach( glsr()->config( 'forms/'.$id ) as $name => $field ) { |
|
26 | + $fields[] = new Field( wp_parse_args( $field, ['name' => $name] ) ); |
|
27 | 27 | } |
28 | 28 | return $fields; |
29 | 29 | } |
@@ -32,8 +32,8 @@ discard block |
||
32 | 32 | * @param string $id |
33 | 33 | * @return void |
34 | 34 | */ |
35 | - public function renderFields($id) |
|
35 | + public function renderFields( $id ) |
|
36 | 36 | { |
37 | - echo $this->buildFields($id); |
|
37 | + echo $this->buildFields( $id ); |
|
38 | 38 | } |
39 | 39 | } |
@@ -302,7 +302,8 @@ |
||
302 | 302 | } |
303 | 303 | if (in_array($field->field['type'], ['radio', 'checkbox'])) { |
304 | 304 | $field->field['checked'] = $field->field['value'] == $this->values[$field->field['path']]; |
305 | - } else { |
|
305 | + } |
|
306 | + else { |
|
306 | 307 | $field->field['value'] = $this->values[$field->field['path']]; |
307 | 308 | } |
308 | 309 | } |
@@ -13,294 +13,294 @@ |
||
13 | 13 | |
14 | 14 | class SiteReviewsForm implements PartialContract |
15 | 15 | { |
16 | - /** |
|
17 | - * @var array |
|
18 | - */ |
|
19 | - protected $args; |
|
16 | + /** |
|
17 | + * @var array |
|
18 | + */ |
|
19 | + protected $args; |
|
20 | 20 | |
21 | - /** |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $errors; |
|
21 | + /** |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + protected $errors; |
|
25 | 25 | |
26 | - /** |
|
27 | - * @var string |
|
28 | - */ |
|
29 | - protected $message; |
|
26 | + /** |
|
27 | + * @var string |
|
28 | + */ |
|
29 | + protected $message; |
|
30 | 30 | |
31 | - /** |
|
32 | - * @var array |
|
33 | - */ |
|
34 | - protected $required; |
|
31 | + /** |
|
32 | + * @var array |
|
33 | + */ |
|
34 | + protected $required; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @var array |
|
38 | - */ |
|
39 | - protected $values; |
|
36 | + /** |
|
37 | + * @var array |
|
38 | + */ |
|
39 | + protected $values; |
|
40 | 40 | |
41 | - /** |
|
42 | - * {@inheritdoc} |
|
43 | - */ |
|
44 | - public function build(array $args = []) |
|
45 | - { |
|
46 | - $this->args = $args; |
|
47 | - if (!is_user_logged_in() && glsr(OptionManager::class)->getBool('settings.general.require.login')) { |
|
48 | - return $this->buildLoginRegister(); |
|
49 | - } |
|
50 | - $this->errors = glsr()->sessionGet($args['id'].'errors', []); |
|
51 | - $this->message = glsr()->sessionGet($args['id'].'message', ''); |
|
52 | - $this->required = glsr(OptionManager::class)->get('settings.submissions.required', []); |
|
53 | - $this->values = glsr()->sessionGet($args['id'].'values', []); |
|
54 | - $fields = array_reduce($this->getFields(), function ($carry, $field) { |
|
55 | - return $carry.$field; |
|
56 | - }); |
|
57 | - return glsr(Template::class)->build('templates/reviews-form', [ |
|
58 | - 'args' => $args, |
|
59 | - 'context' => [ |
|
60 | - 'class' => $this->getClass(), |
|
61 | - 'fields' => $fields, |
|
62 | - 'id' => $this->args['id'], |
|
63 | - 'response' => $this->buildResponse(), |
|
64 | - 'submit_button' => $this->buildSubmitButton().$this->buildRecaptcha(), |
|
65 | - ], |
|
66 | - ]); |
|
67 | - } |
|
41 | + /** |
|
42 | + * {@inheritdoc} |
|
43 | + */ |
|
44 | + public function build(array $args = []) |
|
45 | + { |
|
46 | + $this->args = $args; |
|
47 | + if (!is_user_logged_in() && glsr(OptionManager::class)->getBool('settings.general.require.login')) { |
|
48 | + return $this->buildLoginRegister(); |
|
49 | + } |
|
50 | + $this->errors = glsr()->sessionGet($args['id'].'errors', []); |
|
51 | + $this->message = glsr()->sessionGet($args['id'].'message', ''); |
|
52 | + $this->required = glsr(OptionManager::class)->get('settings.submissions.required', []); |
|
53 | + $this->values = glsr()->sessionGet($args['id'].'values', []); |
|
54 | + $fields = array_reduce($this->getFields(), function ($carry, $field) { |
|
55 | + return $carry.$field; |
|
56 | + }); |
|
57 | + return glsr(Template::class)->build('templates/reviews-form', [ |
|
58 | + 'args' => $args, |
|
59 | + 'context' => [ |
|
60 | + 'class' => $this->getClass(), |
|
61 | + 'fields' => $fields, |
|
62 | + 'id' => $this->args['id'], |
|
63 | + 'response' => $this->buildResponse(), |
|
64 | + 'submit_button' => $this->buildSubmitButton().$this->buildRecaptcha(), |
|
65 | + ], |
|
66 | + ]); |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * @return string |
|
71 | - */ |
|
72 | - protected function buildLoginRegister() |
|
73 | - { |
|
74 | - return glsr(Template::class)->build('templates/login-register', [ |
|
75 | - 'context' => [ |
|
76 | - 'text' => trim($this->getLoginText().' '.$this->getRegisterText()), |
|
77 | - ], |
|
78 | - ]); |
|
79 | - } |
|
69 | + /** |
|
70 | + * @return string |
|
71 | + */ |
|
72 | + protected function buildLoginRegister() |
|
73 | + { |
|
74 | + return glsr(Template::class)->build('templates/login-register', [ |
|
75 | + 'context' => [ |
|
76 | + 'text' => trim($this->getLoginText().' '.$this->getRegisterText()), |
|
77 | + ], |
|
78 | + ]); |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * @return void|string |
|
83 | - */ |
|
84 | - protected function buildRecaptcha() |
|
85 | - { |
|
86 | - if (!glsr(OptionManager::class)->isRecaptchaEnabled()) { |
|
87 | - return; |
|
88 | - } |
|
89 | - return glsr(Builder::class)->div([ |
|
90 | - 'class' => 'glsr-recaptcha-holder', |
|
91 | - 'data-badge' => glsr(OptionManager::class)->get('settings.submissions.recaptcha.position'), |
|
92 | - 'data-sitekey' => sanitize_text_field(glsr(OptionManager::class)->get('settings.submissions.recaptcha.key')), |
|
93 | - 'data-size' => 'invisible', |
|
94 | - ]); |
|
95 | - } |
|
81 | + /** |
|
82 | + * @return void|string |
|
83 | + */ |
|
84 | + protected function buildRecaptcha() |
|
85 | + { |
|
86 | + if (!glsr(OptionManager::class)->isRecaptchaEnabled()) { |
|
87 | + return; |
|
88 | + } |
|
89 | + return glsr(Builder::class)->div([ |
|
90 | + 'class' => 'glsr-recaptcha-holder', |
|
91 | + 'data-badge' => glsr(OptionManager::class)->get('settings.submissions.recaptcha.position'), |
|
92 | + 'data-sitekey' => sanitize_text_field(glsr(OptionManager::class)->get('settings.submissions.recaptcha.key')), |
|
93 | + 'data-size' => 'invisible', |
|
94 | + ]); |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * @return string |
|
99 | - */ |
|
100 | - protected function buildResponse() |
|
101 | - { |
|
102 | - $classes = !empty($this->errors) |
|
103 | - ? glsr(StyleValidationDefaults::class)->defaults()['message_error_class'] |
|
104 | - : ''; |
|
105 | - return glsr(Template::class)->build('templates/form/response', [ |
|
106 | - 'context' => [ |
|
107 | - 'class' => $classes, |
|
108 | - 'message' => wpautop($this->message), |
|
109 | - ], |
|
110 | - 'has_errors' => !empty($this->errors), |
|
111 | - ]); |
|
112 | - } |
|
97 | + /** |
|
98 | + * @return string |
|
99 | + */ |
|
100 | + protected function buildResponse() |
|
101 | + { |
|
102 | + $classes = !empty($this->errors) |
|
103 | + ? glsr(StyleValidationDefaults::class)->defaults()['message_error_class'] |
|
104 | + : ''; |
|
105 | + return glsr(Template::class)->build('templates/form/response', [ |
|
106 | + 'context' => [ |
|
107 | + 'class' => $classes, |
|
108 | + 'message' => wpautop($this->message), |
|
109 | + ], |
|
110 | + 'has_errors' => !empty($this->errors), |
|
111 | + ]); |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * @return string |
|
116 | - */ |
|
117 | - protected function buildSubmitButton() |
|
118 | - { |
|
119 | - return glsr(Template::class)->build('templates/form/submit-button', [ |
|
120 | - 'context' => [ |
|
121 | - 'text' => __('Submit your review', 'site-reviews'), |
|
122 | - ], |
|
123 | - ]); |
|
124 | - } |
|
114 | + /** |
|
115 | + * @return string |
|
116 | + */ |
|
117 | + protected function buildSubmitButton() |
|
118 | + { |
|
119 | + return glsr(Template::class)->build('templates/form/submit-button', [ |
|
120 | + 'context' => [ |
|
121 | + 'text' => __('Submit your review', 'site-reviews'), |
|
122 | + ], |
|
123 | + ]); |
|
124 | + } |
|
125 | 125 | |
126 | - /** |
|
127 | - * @return string |
|
128 | - */ |
|
129 | - protected function getClass() |
|
130 | - { |
|
131 | - return trim('glsr-form '.$this->args['class']); |
|
132 | - } |
|
126 | + /** |
|
127 | + * @return string |
|
128 | + */ |
|
129 | + protected function getClass() |
|
130 | + { |
|
131 | + return trim('glsr-form '.$this->args['class']); |
|
132 | + } |
|
133 | 133 | |
134 | - /** |
|
135 | - * @return array |
|
136 | - */ |
|
137 | - protected function getFields() |
|
138 | - { |
|
139 | - $hiddenFields = $this->getHiddenFields(); |
|
140 | - $hiddenFields[] = $this->getHoneypotField(); |
|
141 | - $fields = $this->normalizeFields(glsr(Form::class)->getFields('submission-form')); |
|
142 | - $paths = array_map(function ($obj) { |
|
143 | - return $obj->field['path']; |
|
144 | - }, $hiddenFields); |
|
145 | - foreach ($fields as $field) { |
|
146 | - $index = array_search($field->field['path'], $paths); |
|
147 | - if (false === $index) { |
|
148 | - continue; |
|
149 | - } |
|
150 | - unset($hiddenFields[$index]); |
|
151 | - } |
|
152 | - return array_merge($hiddenFields, $fields); |
|
153 | - } |
|
134 | + /** |
|
135 | + * @return array |
|
136 | + */ |
|
137 | + protected function getFields() |
|
138 | + { |
|
139 | + $hiddenFields = $this->getHiddenFields(); |
|
140 | + $hiddenFields[] = $this->getHoneypotField(); |
|
141 | + $fields = $this->normalizeFields(glsr(Form::class)->getFields('submission-form')); |
|
142 | + $paths = array_map(function ($obj) { |
|
143 | + return $obj->field['path']; |
|
144 | + }, $hiddenFields); |
|
145 | + foreach ($fields as $field) { |
|
146 | + $index = array_search($field->field['path'], $paths); |
|
147 | + if (false === $index) { |
|
148 | + continue; |
|
149 | + } |
|
150 | + unset($hiddenFields[$index]); |
|
151 | + } |
|
152 | + return array_merge($hiddenFields, $fields); |
|
153 | + } |
|
154 | 154 | |
155 | - /** |
|
156 | - * @return string |
|
157 | - */ |
|
158 | - protected function getLoginText() |
|
159 | - { |
|
160 | - $loginLink = glsr(Builder::class)->a([ |
|
161 | - 'href' => wp_login_url(strval(get_permalink())), |
|
162 | - 'text' => __('logged in', 'site-reviews'), |
|
163 | - ]); |
|
164 | - return sprintf(__('You must be %s to submit a review.', 'site-reviews'), $loginLink); |
|
165 | - } |
|
155 | + /** |
|
156 | + * @return string |
|
157 | + */ |
|
158 | + protected function getLoginText() |
|
159 | + { |
|
160 | + $loginLink = glsr(Builder::class)->a([ |
|
161 | + 'href' => wp_login_url(strval(get_permalink())), |
|
162 | + 'text' => __('logged in', 'site-reviews'), |
|
163 | + ]); |
|
164 | + return sprintf(__('You must be %s to submit a review.', 'site-reviews'), $loginLink); |
|
165 | + } |
|
166 | 166 | |
167 | - /** |
|
168 | - * @return void|string |
|
169 | - */ |
|
170 | - protected function getRegisterText() |
|
171 | - { |
|
172 | - if (!get_option('users_can_register') || !glsr(OptionManager::class)->getBool('settings.general.require.login')) { |
|
173 | - return; |
|
174 | - } |
|
175 | - $registerLink = glsr(Builder::class)->a([ |
|
176 | - 'href' => wp_registration_url(), |
|
177 | - 'text' => __('register', 'site-reviews'), |
|
178 | - ]); |
|
179 | - return sprintf(__('You may also %s for an account.', 'site-reviews'), $registerLink); |
|
180 | - } |
|
167 | + /** |
|
168 | + * @return void|string |
|
169 | + */ |
|
170 | + protected function getRegisterText() |
|
171 | + { |
|
172 | + if (!get_option('users_can_register') || !glsr(OptionManager::class)->getBool('settings.general.require.login')) { |
|
173 | + return; |
|
174 | + } |
|
175 | + $registerLink = glsr(Builder::class)->a([ |
|
176 | + 'href' => wp_registration_url(), |
|
177 | + 'text' => __('register', 'site-reviews'), |
|
178 | + ]); |
|
179 | + return sprintf(__('You may also %s for an account.', 'site-reviews'), $registerLink); |
|
180 | + } |
|
181 | 181 | |
182 | - /** |
|
183 | - * @return array |
|
184 | - */ |
|
185 | - protected function getHiddenFields() |
|
186 | - { |
|
187 | - $fields = [[ |
|
188 | - 'name' => '_action', |
|
189 | - 'value' => 'submit-review', |
|
190 | - ], [ |
|
191 | - 'name' => '_counter', |
|
192 | - ], [ |
|
193 | - 'name' => '_nonce', |
|
194 | - 'value' => wp_create_nonce('submit-review'), |
|
195 | - ], [ |
|
196 | - 'name' => '_post_id', |
|
197 | - 'value' => get_the_ID(), |
|
198 | - ], [ |
|
199 | - 'name' => '_referer', |
|
200 | - 'value' => wp_unslash(filter_input(INPUT_SERVER, 'REQUEST_URI')), |
|
201 | - ], [ |
|
202 | - 'name' => 'assign_to', |
|
203 | - 'value' => $this->args['assign_to'], |
|
204 | - ], [ |
|
205 | - 'name' => 'category', |
|
206 | - 'value' => $this->args['category'], |
|
207 | - ], [ |
|
208 | - 'name' => 'excluded', |
|
209 | - 'value' => $this->args['hide'], |
|
210 | - ], [ |
|
211 | - 'name' => 'form_id', |
|
212 | - 'value' => $this->args['id'], |
|
213 | - ]]; |
|
214 | - return array_map(function ($field) { |
|
215 | - return new Field(wp_parse_args($field, ['type' => 'hidden'])); |
|
216 | - }, $fields); |
|
217 | - } |
|
182 | + /** |
|
183 | + * @return array |
|
184 | + */ |
|
185 | + protected function getHiddenFields() |
|
186 | + { |
|
187 | + $fields = [[ |
|
188 | + 'name' => '_action', |
|
189 | + 'value' => 'submit-review', |
|
190 | + ], [ |
|
191 | + 'name' => '_counter', |
|
192 | + ], [ |
|
193 | + 'name' => '_nonce', |
|
194 | + 'value' => wp_create_nonce('submit-review'), |
|
195 | + ], [ |
|
196 | + 'name' => '_post_id', |
|
197 | + 'value' => get_the_ID(), |
|
198 | + ], [ |
|
199 | + 'name' => '_referer', |
|
200 | + 'value' => wp_unslash(filter_input(INPUT_SERVER, 'REQUEST_URI')), |
|
201 | + ], [ |
|
202 | + 'name' => 'assign_to', |
|
203 | + 'value' => $this->args['assign_to'], |
|
204 | + ], [ |
|
205 | + 'name' => 'category', |
|
206 | + 'value' => $this->args['category'], |
|
207 | + ], [ |
|
208 | + 'name' => 'excluded', |
|
209 | + 'value' => $this->args['hide'], |
|
210 | + ], [ |
|
211 | + 'name' => 'form_id', |
|
212 | + 'value' => $this->args['id'], |
|
213 | + ]]; |
|
214 | + return array_map(function ($field) { |
|
215 | + return new Field(wp_parse_args($field, ['type' => 'hidden'])); |
|
216 | + }, $fields); |
|
217 | + } |
|
218 | 218 | |
219 | - /** |
|
220 | - * @return Field |
|
221 | - */ |
|
222 | - protected function getHoneypotField() |
|
223 | - { |
|
224 | - return new Field([ |
|
225 | - 'name' => 'gotcha', |
|
226 | - 'type' => 'honeypot', |
|
227 | - ]); |
|
228 | - } |
|
219 | + /** |
|
220 | + * @return Field |
|
221 | + */ |
|
222 | + protected function getHoneypotField() |
|
223 | + { |
|
224 | + return new Field([ |
|
225 | + 'name' => 'gotcha', |
|
226 | + 'type' => 'honeypot', |
|
227 | + ]); |
|
228 | + } |
|
229 | 229 | |
230 | - /** |
|
231 | - * @return void |
|
232 | - */ |
|
233 | - protected function normalizeFieldId(Field &$field) |
|
234 | - { |
|
235 | - if (empty($this->args['id']) || empty($field->field['id'])) { |
|
236 | - return; |
|
237 | - } |
|
238 | - $field->field['id'].= '-'.$this->args['id']; |
|
239 | - } |
|
230 | + /** |
|
231 | + * @return void |
|
232 | + */ |
|
233 | + protected function normalizeFieldId(Field &$field) |
|
234 | + { |
|
235 | + if (empty($this->args['id']) || empty($field->field['id'])) { |
|
236 | + return; |
|
237 | + } |
|
238 | + $field->field['id'].= '-'.$this->args['id']; |
|
239 | + } |
|
240 | 240 | |
241 | - /** |
|
242 | - * @return void |
|
243 | - */ |
|
244 | - protected function normalizeFieldClass(Field &$field) |
|
245 | - { |
|
246 | - $field->field['class'] = trim(Arr::get($field->field, 'class').' glsr-field-control'); |
|
247 | - } |
|
241 | + /** |
|
242 | + * @return void |
|
243 | + */ |
|
244 | + protected function normalizeFieldClass(Field &$field) |
|
245 | + { |
|
246 | + $field->field['class'] = trim(Arr::get($field->field, 'class').' glsr-field-control'); |
|
247 | + } |
|
248 | 248 | |
249 | - /** |
|
250 | - * @return void |
|
251 | - */ |
|
252 | - protected function normalizeFieldErrors(Field &$field) |
|
253 | - { |
|
254 | - if (!array_key_exists($field->field['path'], $this->errors)) { |
|
255 | - return; |
|
256 | - } |
|
257 | - $field->field['errors'] = $this->errors[$field->field['path']]; |
|
258 | - } |
|
249 | + /** |
|
250 | + * @return void |
|
251 | + */ |
|
252 | + protected function normalizeFieldErrors(Field &$field) |
|
253 | + { |
|
254 | + if (!array_key_exists($field->field['path'], $this->errors)) { |
|
255 | + return; |
|
256 | + } |
|
257 | + $field->field['errors'] = $this->errors[$field->field['path']]; |
|
258 | + } |
|
259 | 259 | |
260 | - /** |
|
261 | - * @return void |
|
262 | - */ |
|
263 | - protected function normalizeFieldRequired(Field &$field) |
|
264 | - { |
|
265 | - if (!in_array($field->field['path'], $this->required)) { |
|
266 | - return; |
|
267 | - } |
|
268 | - $field->field['required'] = true; |
|
269 | - } |
|
260 | + /** |
|
261 | + * @return void |
|
262 | + */ |
|
263 | + protected function normalizeFieldRequired(Field &$field) |
|
264 | + { |
|
265 | + if (!in_array($field->field['path'], $this->required)) { |
|
266 | + return; |
|
267 | + } |
|
268 | + $field->field['required'] = true; |
|
269 | + } |
|
270 | 270 | |
271 | - /** |
|
272 | - * @return array |
|
273 | - */ |
|
274 | - protected function normalizeFields($fields) |
|
275 | - { |
|
276 | - $normalizedFields = []; |
|
277 | - foreach ($fields as $field) { |
|
278 | - if (in_array($field->field['path'], $this->args['hide'])) { |
|
279 | - continue; |
|
280 | - } |
|
281 | - $field->field['is_public'] = true; |
|
282 | - $this->normalizeFieldClass($field); |
|
283 | - $this->normalizeFieldErrors($field); |
|
284 | - $this->normalizeFieldRequired($field); |
|
285 | - $this->normalizeFieldValue($field); |
|
286 | - $this->normalizeFieldId($field); |
|
287 | - $normalizedFields[] = $field; |
|
288 | - } |
|
289 | - return $normalizedFields; |
|
290 | - } |
|
271 | + /** |
|
272 | + * @return array |
|
273 | + */ |
|
274 | + protected function normalizeFields($fields) |
|
275 | + { |
|
276 | + $normalizedFields = []; |
|
277 | + foreach ($fields as $field) { |
|
278 | + if (in_array($field->field['path'], $this->args['hide'])) { |
|
279 | + continue; |
|
280 | + } |
|
281 | + $field->field['is_public'] = true; |
|
282 | + $this->normalizeFieldClass($field); |
|
283 | + $this->normalizeFieldErrors($field); |
|
284 | + $this->normalizeFieldRequired($field); |
|
285 | + $this->normalizeFieldValue($field); |
|
286 | + $this->normalizeFieldId($field); |
|
287 | + $normalizedFields[] = $field; |
|
288 | + } |
|
289 | + return $normalizedFields; |
|
290 | + } |
|
291 | 291 | |
292 | - /** |
|
293 | - * @return void |
|
294 | - */ |
|
295 | - protected function normalizeFieldValue(Field &$field) |
|
296 | - { |
|
297 | - if (!array_key_exists($field->field['path'], $this->values)) { |
|
298 | - return; |
|
299 | - } |
|
300 | - if (in_array($field->field['type'], ['radio', 'checkbox'])) { |
|
301 | - $field->field['checked'] = $field->field['value'] == $this->values[$field->field['path']]; |
|
302 | - } else { |
|
303 | - $field->field['value'] = $this->values[$field->field['path']]; |
|
304 | - } |
|
305 | - } |
|
292 | + /** |
|
293 | + * @return void |
|
294 | + */ |
|
295 | + protected function normalizeFieldValue(Field &$field) |
|
296 | + { |
|
297 | + if (!array_key_exists($field->field['path'], $this->values)) { |
|
298 | + return; |
|
299 | + } |
|
300 | + if (in_array($field->field['type'], ['radio', 'checkbox'])) { |
|
301 | + $field->field['checked'] = $field->field['value'] == $this->values[$field->field['path']]; |
|
302 | + } else { |
|
303 | + $field->field['value'] = $this->values[$field->field['path']]; |
|
304 | + } |
|
305 | + } |
|
306 | 306 | } |
@@ -41,20 +41,20 @@ discard block |
||
41 | 41 | /** |
42 | 42 | * {@inheritdoc} |
43 | 43 | */ |
44 | - public function build(array $args = []) |
|
44 | + public function build( array $args = [] ) |
|
45 | 45 | { |
46 | 46 | $this->args = $args; |
47 | - if (!is_user_logged_in() && glsr(OptionManager::class)->getBool('settings.general.require.login')) { |
|
47 | + if( !is_user_logged_in() && glsr( OptionManager::class )->getBool( 'settings.general.require.login' ) ) { |
|
48 | 48 | return $this->buildLoginRegister(); |
49 | 49 | } |
50 | - $this->errors = glsr()->sessionGet($args['id'].'errors', []); |
|
51 | - $this->message = glsr()->sessionGet($args['id'].'message', ''); |
|
52 | - $this->required = glsr(OptionManager::class)->get('settings.submissions.required', []); |
|
53 | - $this->values = glsr()->sessionGet($args['id'].'values', []); |
|
54 | - $fields = array_reduce($this->getFields(), function ($carry, $field) { |
|
50 | + $this->errors = glsr()->sessionGet( $args['id'].'errors', [] ); |
|
51 | + $this->message = glsr()->sessionGet( $args['id'].'message', '' ); |
|
52 | + $this->required = glsr( OptionManager::class )->get( 'settings.submissions.required', [] ); |
|
53 | + $this->values = glsr()->sessionGet( $args['id'].'values', [] ); |
|
54 | + $fields = array_reduce( $this->getFields(), function( $carry, $field ) { |
|
55 | 55 | return $carry.$field; |
56 | 56 | }); |
57 | - return glsr(Template::class)->build('templates/reviews-form', [ |
|
57 | + return glsr( Template::class )->build( 'templates/reviews-form', [ |
|
58 | 58 | 'args' => $args, |
59 | 59 | 'context' => [ |
60 | 60 | 'class' => $this->getClass(), |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | 'response' => $this->buildResponse(), |
64 | 64 | 'submit_button' => $this->buildSubmitButton().$this->buildRecaptcha(), |
65 | 65 | ], |
66 | - ]); |
|
66 | + ] ); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -71,11 +71,11 @@ discard block |
||
71 | 71 | */ |
72 | 72 | protected function buildLoginRegister() |
73 | 73 | { |
74 | - return glsr(Template::class)->build('templates/login-register', [ |
|
74 | + return glsr( Template::class )->build( 'templates/login-register', [ |
|
75 | 75 | 'context' => [ |
76 | - 'text' => trim($this->getLoginText().' '.$this->getRegisterText()), |
|
76 | + 'text' => trim( $this->getLoginText().' '.$this->getRegisterText() ), |
|
77 | 77 | ], |
78 | - ]); |
|
78 | + ] ); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
@@ -83,15 +83,15 @@ discard block |
||
83 | 83 | */ |
84 | 84 | protected function buildRecaptcha() |
85 | 85 | { |
86 | - if (!glsr(OptionManager::class)->isRecaptchaEnabled()) { |
|
86 | + if( !glsr( OptionManager::class )->isRecaptchaEnabled() ) { |
|
87 | 87 | return; |
88 | 88 | } |
89 | - return glsr(Builder::class)->div([ |
|
89 | + return glsr( Builder::class )->div( [ |
|
90 | 90 | 'class' => 'glsr-recaptcha-holder', |
91 | - 'data-badge' => glsr(OptionManager::class)->get('settings.submissions.recaptcha.position'), |
|
92 | - 'data-sitekey' => sanitize_text_field(glsr(OptionManager::class)->get('settings.submissions.recaptcha.key')), |
|
91 | + 'data-badge' => glsr( OptionManager::class )->get( 'settings.submissions.recaptcha.position' ), |
|
92 | + 'data-sitekey' => sanitize_text_field( glsr( OptionManager::class )->get( 'settings.submissions.recaptcha.key' ) ), |
|
93 | 93 | 'data-size' => 'invisible', |
94 | - ]); |
|
94 | + ] ); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
@@ -100,15 +100,15 @@ discard block |
||
100 | 100 | protected function buildResponse() |
101 | 101 | { |
102 | 102 | $classes = !empty($this->errors) |
103 | - ? glsr(StyleValidationDefaults::class)->defaults()['message_error_class'] |
|
103 | + ? glsr( StyleValidationDefaults::class )->defaults()['message_error_class'] |
|
104 | 104 | : ''; |
105 | - return glsr(Template::class)->build('templates/form/response', [ |
|
105 | + return glsr( Template::class )->build( 'templates/form/response', [ |
|
106 | 106 | 'context' => [ |
107 | 107 | 'class' => $classes, |
108 | - 'message' => wpautop($this->message), |
|
108 | + 'message' => wpautop( $this->message ), |
|
109 | 109 | ], |
110 | 110 | 'has_errors' => !empty($this->errors), |
111 | - ]); |
|
111 | + ] ); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -116,11 +116,11 @@ discard block |
||
116 | 116 | */ |
117 | 117 | protected function buildSubmitButton() |
118 | 118 | { |
119 | - return glsr(Template::class)->build('templates/form/submit-button', [ |
|
119 | + return glsr( Template::class )->build( 'templates/form/submit-button', [ |
|
120 | 120 | 'context' => [ |
121 | - 'text' => __('Submit your review', 'site-reviews'), |
|
121 | + 'text' => __( 'Submit your review', 'site-reviews' ), |
|
122 | 122 | ], |
123 | - ]); |
|
123 | + ] ); |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | /** |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | */ |
129 | 129 | protected function getClass() |
130 | 130 | { |
131 | - return trim('glsr-form '.$this->args['class']); |
|
131 | + return trim( 'glsr-form '.$this->args['class'] ); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
@@ -138,18 +138,18 @@ discard block |
||
138 | 138 | { |
139 | 139 | $hiddenFields = $this->getHiddenFields(); |
140 | 140 | $hiddenFields[] = $this->getHoneypotField(); |
141 | - $fields = $this->normalizeFields(glsr(Form::class)->getFields('submission-form')); |
|
142 | - $paths = array_map(function ($obj) { |
|
141 | + $fields = $this->normalizeFields( glsr( Form::class )->getFields( 'submission-form' ) ); |
|
142 | + $paths = array_map( function( $obj ) { |
|
143 | 143 | return $obj->field['path']; |
144 | - }, $hiddenFields); |
|
145 | - foreach ($fields as $field) { |
|
146 | - $index = array_search($field->field['path'], $paths); |
|
147 | - if (false === $index) { |
|
144 | + }, $hiddenFields ); |
|
145 | + foreach( $fields as $field ) { |
|
146 | + $index = array_search( $field->field['path'], $paths ); |
|
147 | + if( false === $index ) { |
|
148 | 148 | continue; |
149 | 149 | } |
150 | 150 | unset($hiddenFields[$index]); |
151 | 151 | } |
152 | - return array_merge($hiddenFields, $fields); |
|
152 | + return array_merge( $hiddenFields, $fields ); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
@@ -157,11 +157,11 @@ discard block |
||
157 | 157 | */ |
158 | 158 | protected function getLoginText() |
159 | 159 | { |
160 | - $loginLink = glsr(Builder::class)->a([ |
|
161 | - 'href' => wp_login_url(strval(get_permalink())), |
|
162 | - 'text' => __('logged in', 'site-reviews'), |
|
163 | - ]); |
|
164 | - return sprintf(__('You must be %s to submit a review.', 'site-reviews'), $loginLink); |
|
160 | + $loginLink = glsr( Builder::class )->a( [ |
|
161 | + 'href' => wp_login_url( strval( get_permalink() ) ), |
|
162 | + 'text' => __( 'logged in', 'site-reviews' ), |
|
163 | + ] ); |
|
164 | + return sprintf( __( 'You must be %s to submit a review.', 'site-reviews' ), $loginLink ); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | /** |
@@ -169,14 +169,14 @@ discard block |
||
169 | 169 | */ |
170 | 170 | protected function getRegisterText() |
171 | 171 | { |
172 | - if (!get_option('users_can_register') || !glsr(OptionManager::class)->getBool('settings.general.require.login')) { |
|
172 | + if( !get_option( 'users_can_register' ) || !glsr( OptionManager::class )->getBool( 'settings.general.require.login' ) ) { |
|
173 | 173 | return; |
174 | 174 | } |
175 | - $registerLink = glsr(Builder::class)->a([ |
|
175 | + $registerLink = glsr( Builder::class )->a( [ |
|
176 | 176 | 'href' => wp_registration_url(), |
177 | - 'text' => __('register', 'site-reviews'), |
|
178 | - ]); |
|
179 | - return sprintf(__('You may also %s for an account.', 'site-reviews'), $registerLink); |
|
177 | + 'text' => __( 'register', 'site-reviews' ), |
|
178 | + ] ); |
|
179 | + return sprintf( __( 'You may also %s for an account.', 'site-reviews' ), $registerLink ); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | /** |
@@ -191,13 +191,13 @@ discard block |
||
191 | 191 | 'name' => '_counter', |
192 | 192 | ], [ |
193 | 193 | 'name' => '_nonce', |
194 | - 'value' => wp_create_nonce('submit-review'), |
|
194 | + 'value' => wp_create_nonce( 'submit-review' ), |
|
195 | 195 | ], [ |
196 | 196 | 'name' => '_post_id', |
197 | 197 | 'value' => get_the_ID(), |
198 | 198 | ], [ |
199 | 199 | 'name' => '_referer', |
200 | - 'value' => wp_unslash(filter_input(INPUT_SERVER, 'REQUEST_URI')), |
|
200 | + 'value' => wp_unslash( filter_input( INPUT_SERVER, 'REQUEST_URI' ) ), |
|
201 | 201 | ], [ |
202 | 202 | 'name' => 'assign_to', |
203 | 203 | 'value' => $this->args['assign_to'], |
@@ -211,9 +211,9 @@ discard block |
||
211 | 211 | 'name' => 'form_id', |
212 | 212 | 'value' => $this->args['id'], |
213 | 213 | ]]; |
214 | - return array_map(function ($field) { |
|
215 | - return new Field(wp_parse_args($field, ['type' => 'hidden'])); |
|
216 | - }, $fields); |
|
214 | + return array_map( function( $field ) { |
|
215 | + return new Field( wp_parse_args( $field, ['type' => 'hidden'] ) ); |
|
216 | + }, $fields ); |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | /** |
@@ -221,37 +221,37 @@ discard block |
||
221 | 221 | */ |
222 | 222 | protected function getHoneypotField() |
223 | 223 | { |
224 | - return new Field([ |
|
224 | + return new Field( [ |
|
225 | 225 | 'name' => 'gotcha', |
226 | 226 | 'type' => 'honeypot', |
227 | - ]); |
|
227 | + ] ); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | /** |
231 | 231 | * @return void |
232 | 232 | */ |
233 | - protected function normalizeFieldId(Field &$field) |
|
233 | + protected function normalizeFieldId( Field &$field ) |
|
234 | 234 | { |
235 | - if (empty($this->args['id']) || empty($field->field['id'])) { |
|
235 | + if( empty($this->args['id']) || empty($field->field['id']) ) { |
|
236 | 236 | return; |
237 | 237 | } |
238 | - $field->field['id'].= '-'.$this->args['id']; |
|
238 | + $field->field['id'] .= '-'.$this->args['id']; |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | /** |
242 | 242 | * @return void |
243 | 243 | */ |
244 | - protected function normalizeFieldClass(Field &$field) |
|
244 | + protected function normalizeFieldClass( Field &$field ) |
|
245 | 245 | { |
246 | - $field->field['class'] = trim(Arr::get($field->field, 'class').' glsr-field-control'); |
|
246 | + $field->field['class'] = trim( Arr::get( $field->field, 'class' ).' glsr-field-control' ); |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | /** |
250 | 250 | * @return void |
251 | 251 | */ |
252 | - protected function normalizeFieldErrors(Field &$field) |
|
252 | + protected function normalizeFieldErrors( Field &$field ) |
|
253 | 253 | { |
254 | - if (!array_key_exists($field->field['path'], $this->errors)) { |
|
254 | + if( !array_key_exists( $field->field['path'], $this->errors ) ) { |
|
255 | 255 | return; |
256 | 256 | } |
257 | 257 | $field->field['errors'] = $this->errors[$field->field['path']]; |
@@ -260,9 +260,9 @@ discard block |
||
260 | 260 | /** |
261 | 261 | * @return void |
262 | 262 | */ |
263 | - protected function normalizeFieldRequired(Field &$field) |
|
263 | + protected function normalizeFieldRequired( Field &$field ) |
|
264 | 264 | { |
265 | - if (!in_array($field->field['path'], $this->required)) { |
|
265 | + if( !in_array( $field->field['path'], $this->required ) ) { |
|
266 | 266 | return; |
267 | 267 | } |
268 | 268 | $field->field['required'] = true; |
@@ -271,19 +271,19 @@ discard block |
||
271 | 271 | /** |
272 | 272 | * @return array |
273 | 273 | */ |
274 | - protected function normalizeFields($fields) |
|
274 | + protected function normalizeFields( $fields ) |
|
275 | 275 | { |
276 | 276 | $normalizedFields = []; |
277 | - foreach ($fields as $field) { |
|
278 | - if (in_array($field->field['path'], $this->args['hide'])) { |
|
277 | + foreach( $fields as $field ) { |
|
278 | + if( in_array( $field->field['path'], $this->args['hide'] ) ) { |
|
279 | 279 | continue; |
280 | 280 | } |
281 | 281 | $field->field['is_public'] = true; |
282 | - $this->normalizeFieldClass($field); |
|
283 | - $this->normalizeFieldErrors($field); |
|
284 | - $this->normalizeFieldRequired($field); |
|
285 | - $this->normalizeFieldValue($field); |
|
286 | - $this->normalizeFieldId($field); |
|
282 | + $this->normalizeFieldClass( $field ); |
|
283 | + $this->normalizeFieldErrors( $field ); |
|
284 | + $this->normalizeFieldRequired( $field ); |
|
285 | + $this->normalizeFieldValue( $field ); |
|
286 | + $this->normalizeFieldId( $field ); |
|
287 | 287 | $normalizedFields[] = $field; |
288 | 288 | } |
289 | 289 | return $normalizedFields; |
@@ -292,12 +292,12 @@ discard block |
||
292 | 292 | /** |
293 | 293 | * @return void |
294 | 294 | */ |
295 | - protected function normalizeFieldValue(Field &$field) |
|
295 | + protected function normalizeFieldValue( Field &$field ) |
|
296 | 296 | { |
297 | - if (!array_key_exists($field->field['path'], $this->values)) { |
|
297 | + if( !array_key_exists( $field->field['path'], $this->values ) ) { |
|
298 | 298 | return; |
299 | 299 | } |
300 | - if (in_array($field->field['type'], ['radio', 'checkbox'])) { |
|
300 | + if( in_array( $field->field['type'], ['radio', 'checkbox'] ) ) { |
|
301 | 301 | $field->field['checked'] = $field->field['value'] == $this->values[$field->field['path']]; |
302 | 302 | } else { |
303 | 303 | $field->field['value'] = $this->values[$field->field['path']]; |
@@ -415,7 +415,8 @@ |
||
415 | 415 | { |
416 | 416 | if ($value instanceof DateTime) { |
417 | 417 | $value = $value->format('Y-m-d H:i:s'); |
418 | - } elseif ($this->isObjectOrArray($value)) { |
|
418 | + } |
|
419 | + elseif ($this->isObjectOrArray($value)) { |
|
419 | 420 | $value = json_encode($value); |
420 | 421 | } |
421 | 422 | return (string) $value; |
@@ -10,437 +10,437 @@ |
||
10 | 10 | |
11 | 11 | class Console |
12 | 12 | { |
13 | - const DEBUG = 0; // Detailed debug information |
|
14 | - const INFO = 1; // Interesting events |
|
15 | - const NOTICE = 2; // Normal but significant events |
|
16 | - const WARNING = 4; // Exceptional occurrences that are not errors |
|
17 | - const ERROR = 8; // Runtime errors that do not require immediate action |
|
18 | - const CRITICAL = 16; // Critical conditions |
|
19 | - const ALERT = 32; // Action must be taken immediately |
|
20 | - const EMERGENCY = 64; // System is unusable |
|
21 | - |
|
22 | - protected $file; |
|
23 | - protected $log; |
|
24 | - protected $logOnceKey = 'glsr_log_once'; |
|
25 | - |
|
26 | - public function __construct() |
|
27 | - { |
|
28 | - $this->file = glsr()->path('console.log'); |
|
29 | - $this->log = file_exists($this->file) |
|
30 | - ? file_get_contents($this->file) |
|
31 | - : ''; |
|
32 | - $this->reset(); |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * @return string |
|
37 | - */ |
|
38 | - public function __toString() |
|
39 | - { |
|
40 | - return $this->get(); |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * Action must be taken immediately |
|
45 | - * Example: Entire website down, database unavailable, etc. This should trigger the SMS alerts and wake you up. |
|
46 | - * @param mixed $message |
|
47 | - * @param array $context |
|
48 | - * @return static |
|
49 | - */ |
|
50 | - public function alert($message, array $context = []) |
|
51 | - { |
|
52 | - return $this->log(static::ALERT, $message, $context); |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * @return void |
|
57 | - */ |
|
58 | - public function clear() |
|
59 | - { |
|
60 | - $this->log = ''; |
|
61 | - file_put_contents($this->file, $this->log); |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * Critical conditions |
|
66 | - * Example: Application component unavailable, unexpected exception. |
|
67 | - * @param mixed $message |
|
68 | - * @param array $context |
|
69 | - * @return static |
|
70 | - */ |
|
71 | - public function critical($message, array $context = []) |
|
72 | - { |
|
73 | - return $this->log(static::CRITICAL, $message, $context); |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Detailed debug information. |
|
78 | - * @param mixed $message |
|
79 | - * @param array $context |
|
80 | - * @return static |
|
81 | - */ |
|
82 | - public function debug($message, array $context = []) |
|
83 | - { |
|
84 | - return $this->log(static::DEBUG, $message, $context); |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * System is unusable. |
|
89 | - * @param mixed $message |
|
90 | - * @param array $context |
|
91 | - * @return static |
|
92 | - */ |
|
93 | - public function emergency($message, array $context = []) |
|
94 | - { |
|
95 | - return $this->log(static::EMERGENCY, $message, $context); |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Runtime errors that do not require immediate action but should typically be logged and monitored. |
|
100 | - * @param mixed $message |
|
101 | - * @param array $context |
|
102 | - * @return static |
|
103 | - */ |
|
104 | - public function error($message, array $context = []) |
|
105 | - { |
|
106 | - return $this->log(static::ERROR, $message, $context); |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * @return string |
|
111 | - */ |
|
112 | - public function get() |
|
113 | - { |
|
114 | - return empty($this->log) |
|
115 | - ? __('Console is empty', 'site-reviews') |
|
116 | - : $this->log; |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * @return int |
|
121 | - */ |
|
122 | - public function getLevel() |
|
123 | - { |
|
124 | - return intval(apply_filters('site-reviews/console/level', static::INFO)); |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * @return array |
|
129 | - */ |
|
130 | - public function getLevels() |
|
131 | - { |
|
132 | - $constants = (new ReflectionClass(__CLASS__))->getConstants(); |
|
133 | - return array_map('strtolower', array_flip($constants)); |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * @return string |
|
138 | - */ |
|
139 | - public function humanLevel() |
|
140 | - { |
|
141 | - $level = $this->getLevel(); |
|
142 | - return sprintf('%s (%d)', strtoupper(Arr::get($this->getLevels(), $level, 'unknown')), $level); |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * @param string|null $valueIfEmpty |
|
147 | - * @return string |
|
148 | - */ |
|
149 | - public function humanSize($valueIfEmpty = null) |
|
150 | - { |
|
151 | - $bytes = $this->size(); |
|
152 | - if (empty($bytes) && is_string($valueIfEmpty)) { |
|
153 | - return $valueIfEmpty; |
|
154 | - } |
|
155 | - $exponent = floor(log(max($bytes, 1), 1024)); |
|
156 | - return round($bytes / pow(1024, $exponent), 2).' '.['bytes', 'KB', 'MB', 'GB'][$exponent]; |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * Interesting events |
|
161 | - * Example: User logs in, SQL logs. |
|
162 | - * @param mixed $message |
|
163 | - * @param array $context |
|
164 | - * @return static |
|
165 | - */ |
|
166 | - public function info($message, array $context = []) |
|
167 | - { |
|
168 | - return $this->log(static::INFO, $message, $context); |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * @param int $level |
|
173 | - * @param mixed $message |
|
174 | - * @param array $context |
|
175 | - * @param string $backtraceLine |
|
176 | - * @return static |
|
177 | - */ |
|
178 | - public function log($level, $message, $context = [], $backtraceLine = '') |
|
179 | - { |
|
180 | - if (empty($backtraceLine)) { |
|
181 | - $backtraceLine = $this->getBacktraceLine(); |
|
182 | - } |
|
183 | - if ($this->canLogEntry($level, $backtraceLine)) { |
|
184 | - $levelName = Arr::get($this->getLevels(), $level); |
|
185 | - $context = Arr::consolidate($context); |
|
186 | - $backtraceLine = $this->normalizeBacktraceLine($backtraceLine); |
|
187 | - $message = $this->interpolate($message, $context); |
|
188 | - $entry = $this->buildLogEntry($levelName, $message, $backtraceLine); |
|
189 | - file_put_contents($this->file, $entry.PHP_EOL, FILE_APPEND | LOCK_EX); |
|
190 | - apply_filters('console', $message, $levelName, $backtraceLine); // Show in Blackbar plugin if installed |
|
191 | - $this->reset(); |
|
192 | - } |
|
193 | - return $this; |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * @return void |
|
198 | - */ |
|
199 | - public function logOnce() |
|
200 | - { |
|
201 | - $once = Arr::consolidate(glsr()->{$this->logOnceKey}); |
|
202 | - $levels = $this->getLevels(); |
|
203 | - foreach ($once as $entry) { |
|
204 | - $levelName = Arr::get($entry, 'level'); |
|
205 | - if (!in_array($levelName, $levels)) { |
|
206 | - continue; |
|
207 | - } |
|
208 | - $level = Arr::get(array_flip($levels), $levelName); |
|
209 | - $message = Arr::get($entry, 'message'); |
|
210 | - $backtraceLine = Arr::get($entry, 'backtrace'); |
|
211 | - $this->log($level, $message, [], $backtraceLine); |
|
212 | - } |
|
213 | - glsr()->{$this->logOnceKey} = []; |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * Normal but significant events. |
|
218 | - * @param mixed $message |
|
219 | - * @param array $context |
|
220 | - * @return static |
|
221 | - */ |
|
222 | - public function notice($message, array $context = []) |
|
223 | - { |
|
224 | - return $this->log(static::NOTICE, $message, $context); |
|
225 | - } |
|
226 | - |
|
227 | - /** |
|
228 | - * @param string $levelName |
|
229 | - * @param string $handle |
|
230 | - * @param mixed $data |
|
231 | - * @return void |
|
232 | - */ |
|
233 | - public function once($levelName, $handle, $data) |
|
234 | - { |
|
235 | - $once = Arr::consolidate(glsr()->{$this->logOnceKey}); |
|
236 | - $filtered = array_filter($once, function ($entry) use ($levelName, $handle) { |
|
237 | - return Arr::get($entry, 'level') == $levelName |
|
238 | - && Arr::get($entry, 'handle') == $handle; |
|
239 | - }); |
|
240 | - if (!empty($filtered)) { |
|
241 | - return; |
|
242 | - } |
|
243 | - $once[] = [ |
|
244 | - 'backtrace' => $this->getBacktraceLineFromData($data), |
|
245 | - 'handle' => $handle, |
|
246 | - 'level' => $levelName, |
|
247 | - 'message' => '[RECURRING] '.$this->getMessageFromData($data), |
|
248 | - ]; |
|
249 | - glsr()->{$this->logOnceKey} = $once; |
|
250 | - } |
|
251 | - |
|
252 | - /** |
|
253 | - * @return int |
|
254 | - */ |
|
255 | - public function size() |
|
256 | - { |
|
257 | - return file_exists($this->file) |
|
258 | - ? filesize($this->file) |
|
259 | - : 0; |
|
260 | - } |
|
261 | - |
|
262 | - /** |
|
263 | - * Exceptional occurrences that are not errors |
|
264 | - * Example: Use of deprecated APIs, poor use of an API, undesirable things that are not necessarily wrong. |
|
265 | - * @param mixed $message |
|
266 | - * @param array $context |
|
267 | - * @return static |
|
268 | - */ |
|
269 | - public function warning($message, array $context = []) |
|
270 | - { |
|
271 | - return $this->log(static::WARNING, $message, $context); |
|
272 | - } |
|
273 | - |
|
274 | - /** |
|
275 | - * @param array $backtrace |
|
276 | - * @param int $index |
|
277 | - * @return string |
|
278 | - */ |
|
279 | - protected function buildBacktraceLine($backtrace, $index) |
|
280 | - { |
|
281 | - return sprintf('%s:%s', |
|
282 | - Arr::get($backtrace, $index.'.file'), // realpath |
|
283 | - Arr::get($backtrace, $index.'.line') |
|
284 | - ); |
|
285 | - } |
|
286 | - |
|
287 | - /** |
|
288 | - * @param string $levelName |
|
289 | - * @param mixed $message |
|
290 | - * @param string $backtraceLine |
|
291 | - * @return string |
|
292 | - */ |
|
293 | - protected function buildLogEntry($levelName, $message, $backtraceLine = '') |
|
294 | - { |
|
295 | - return sprintf('[%s] %s [%s] %s', |
|
296 | - current_time('mysql'), |
|
297 | - strtoupper($levelName), |
|
298 | - $backtraceLine, |
|
299 | - $message |
|
300 | - ); |
|
301 | - } |
|
302 | - |
|
303 | - /** |
|
304 | - * @param int $level |
|
305 | - * @return bool |
|
306 | - */ |
|
307 | - protected function canLogEntry($level, $backtraceLine) |
|
308 | - { |
|
309 | - $levelExists = array_key_exists($level, $this->getLevels()); |
|
310 | - if (!Str::contains($backtraceLine, glsr()->path())) { |
|
311 | - return $levelExists; // ignore level restriction if triggered outside of the plugin |
|
312 | - } |
|
313 | - return $levelExists && $level >= $this->getLevel(); |
|
314 | - } |
|
315 | - |
|
316 | - /** |
|
317 | - * @return void|string |
|
318 | - */ |
|
319 | - protected function getBacktraceLine() |
|
320 | - { |
|
321 | - $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 6); |
|
322 | - $search = array_search('glsr_log', glsr_array_column($backtrace, 'function')); |
|
323 | - if (false !== $search) { |
|
324 | - return $this->buildBacktraceLine($backtrace, (int) $search); |
|
325 | - } |
|
326 | - $search = array_search('log', glsr_array_column($backtrace, 'function')); |
|
327 | - if (false !== $search) { |
|
328 | - $index = '{closure}' == Arr::get($backtrace, ($search + 2).'.function') |
|
329 | - ? $search + 4 |
|
330 | - : $search + 1; |
|
331 | - return $this->buildBacktraceLine($backtrace, $index); |
|
332 | - } |
|
333 | - return 'Unknown'; |
|
334 | - } |
|
335 | - |
|
336 | - /** |
|
337 | - * @param mixed $data |
|
338 | - * @return string |
|
339 | - */ |
|
340 | - protected function getBacktraceLineFromData($data) |
|
341 | - { |
|
342 | - $backtrace = $data instanceof Throwable |
|
343 | - ? $data->getTrace() |
|
344 | - : debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1); |
|
345 | - return $this->buildBacktraceLine($backtrace, 0); |
|
346 | - } |
|
347 | - |
|
348 | - /** |
|
349 | - * @param mixed $data |
|
350 | - * @return string |
|
351 | - */ |
|
352 | - protected function getMessageFromData($data) |
|
353 | - { |
|
354 | - return $data instanceof Throwable |
|
355 | - ? $this->normalizeThrowableMessage($data->getMessage()) |
|
356 | - : print_r($data, 1); |
|
357 | - } |
|
358 | - |
|
359 | - /** |
|
360 | - * Interpolates context values into the message placeholders. |
|
361 | - * @param mixed $message |
|
362 | - * @param array $context |
|
363 | - * @return string |
|
364 | - */ |
|
365 | - protected function interpolate($message, $context = []) |
|
366 | - { |
|
367 | - if ($this->isObjectOrArray($message) || !is_array($context)) { |
|
368 | - return print_r($message, true); |
|
369 | - } |
|
370 | - $replace = []; |
|
371 | - foreach ($context as $key => $value) { |
|
372 | - $replace['{'.$key.'}'] = $this->normalizeValue($value); |
|
373 | - } |
|
374 | - return strtr($message, $replace); |
|
375 | - } |
|
376 | - |
|
377 | - /** |
|
378 | - * @param mixed $value |
|
379 | - * @return bool |
|
380 | - */ |
|
381 | - protected function isObjectOrArray($value) |
|
382 | - { |
|
383 | - return is_object($value) || is_array($value); |
|
384 | - } |
|
385 | - |
|
386 | - /** |
|
387 | - * @param string $backtraceLine |
|
388 | - * @return string |
|
389 | - */ |
|
390 | - protected function normalizeBacktraceLine($backtraceLine) |
|
391 | - { |
|
392 | - $search = [ |
|
393 | - glsr()->path('plugin/'), |
|
394 | - glsr()->path('plugin/', false), |
|
395 | - trailingslashit(glsr()->path()), |
|
396 | - trailingslashit(glsr()->path('', false)), |
|
397 | - WP_CONTENT_DIR, |
|
398 | - ABSPATH, |
|
399 | - ]; |
|
400 | - return str_replace(array_unique($search), '', $backtraceLine); |
|
401 | - } |
|
402 | - |
|
403 | - /** |
|
404 | - * @param string $message |
|
405 | - * @return string |
|
406 | - */ |
|
407 | - protected function normalizeThrowableMessage($message) |
|
408 | - { |
|
409 | - $calledIn = strpos($message, ', called in'); |
|
410 | - return false !== $calledIn |
|
411 | - ? substr($message, 0, $calledIn) |
|
412 | - : $message; |
|
413 | - } |
|
414 | - |
|
415 | - /** |
|
416 | - * @param mixed $value |
|
417 | - * @return string |
|
418 | - */ |
|
419 | - protected function normalizeValue($value) |
|
420 | - { |
|
421 | - if ($value instanceof DateTime) { |
|
422 | - $value = $value->format('Y-m-d H:i:s'); |
|
423 | - } elseif ($this->isObjectOrArray($value)) { |
|
424 | - $value = json_encode($value); |
|
425 | - } |
|
426 | - return (string) $value; |
|
427 | - } |
|
428 | - |
|
429 | - /** |
|
430 | - * @return void |
|
431 | - */ |
|
432 | - protected function reset() |
|
433 | - { |
|
434 | - if ($this->size() <= pow(1024, 2) / 8) { |
|
435 | - return; |
|
436 | - } |
|
437 | - $this->clear(); |
|
438 | - file_put_contents( |
|
439 | - $this->file, |
|
440 | - $this->buildLogEntry( |
|
441 | - static::NOTICE, |
|
442 | - __('Console was automatically cleared (128 KB maximum size)', 'site-reviews') |
|
443 | - ) |
|
444 | - ); |
|
445 | - } |
|
13 | + const DEBUG = 0; // Detailed debug information |
|
14 | + const INFO = 1; // Interesting events |
|
15 | + const NOTICE = 2; // Normal but significant events |
|
16 | + const WARNING = 4; // Exceptional occurrences that are not errors |
|
17 | + const ERROR = 8; // Runtime errors that do not require immediate action |
|
18 | + const CRITICAL = 16; // Critical conditions |
|
19 | + const ALERT = 32; // Action must be taken immediately |
|
20 | + const EMERGENCY = 64; // System is unusable |
|
21 | + |
|
22 | + protected $file; |
|
23 | + protected $log; |
|
24 | + protected $logOnceKey = 'glsr_log_once'; |
|
25 | + |
|
26 | + public function __construct() |
|
27 | + { |
|
28 | + $this->file = glsr()->path('console.log'); |
|
29 | + $this->log = file_exists($this->file) |
|
30 | + ? file_get_contents($this->file) |
|
31 | + : ''; |
|
32 | + $this->reset(); |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * @return string |
|
37 | + */ |
|
38 | + public function __toString() |
|
39 | + { |
|
40 | + return $this->get(); |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * Action must be taken immediately |
|
45 | + * Example: Entire website down, database unavailable, etc. This should trigger the SMS alerts and wake you up. |
|
46 | + * @param mixed $message |
|
47 | + * @param array $context |
|
48 | + * @return static |
|
49 | + */ |
|
50 | + public function alert($message, array $context = []) |
|
51 | + { |
|
52 | + return $this->log(static::ALERT, $message, $context); |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * @return void |
|
57 | + */ |
|
58 | + public function clear() |
|
59 | + { |
|
60 | + $this->log = ''; |
|
61 | + file_put_contents($this->file, $this->log); |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * Critical conditions |
|
66 | + * Example: Application component unavailable, unexpected exception. |
|
67 | + * @param mixed $message |
|
68 | + * @param array $context |
|
69 | + * @return static |
|
70 | + */ |
|
71 | + public function critical($message, array $context = []) |
|
72 | + { |
|
73 | + return $this->log(static::CRITICAL, $message, $context); |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Detailed debug information. |
|
78 | + * @param mixed $message |
|
79 | + * @param array $context |
|
80 | + * @return static |
|
81 | + */ |
|
82 | + public function debug($message, array $context = []) |
|
83 | + { |
|
84 | + return $this->log(static::DEBUG, $message, $context); |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * System is unusable. |
|
89 | + * @param mixed $message |
|
90 | + * @param array $context |
|
91 | + * @return static |
|
92 | + */ |
|
93 | + public function emergency($message, array $context = []) |
|
94 | + { |
|
95 | + return $this->log(static::EMERGENCY, $message, $context); |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Runtime errors that do not require immediate action but should typically be logged and monitored. |
|
100 | + * @param mixed $message |
|
101 | + * @param array $context |
|
102 | + * @return static |
|
103 | + */ |
|
104 | + public function error($message, array $context = []) |
|
105 | + { |
|
106 | + return $this->log(static::ERROR, $message, $context); |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * @return string |
|
111 | + */ |
|
112 | + public function get() |
|
113 | + { |
|
114 | + return empty($this->log) |
|
115 | + ? __('Console is empty', 'site-reviews') |
|
116 | + : $this->log; |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * @return int |
|
121 | + */ |
|
122 | + public function getLevel() |
|
123 | + { |
|
124 | + return intval(apply_filters('site-reviews/console/level', static::INFO)); |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * @return array |
|
129 | + */ |
|
130 | + public function getLevels() |
|
131 | + { |
|
132 | + $constants = (new ReflectionClass(__CLASS__))->getConstants(); |
|
133 | + return array_map('strtolower', array_flip($constants)); |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * @return string |
|
138 | + */ |
|
139 | + public function humanLevel() |
|
140 | + { |
|
141 | + $level = $this->getLevel(); |
|
142 | + return sprintf('%s (%d)', strtoupper(Arr::get($this->getLevels(), $level, 'unknown')), $level); |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * @param string|null $valueIfEmpty |
|
147 | + * @return string |
|
148 | + */ |
|
149 | + public function humanSize($valueIfEmpty = null) |
|
150 | + { |
|
151 | + $bytes = $this->size(); |
|
152 | + if (empty($bytes) && is_string($valueIfEmpty)) { |
|
153 | + return $valueIfEmpty; |
|
154 | + } |
|
155 | + $exponent = floor(log(max($bytes, 1), 1024)); |
|
156 | + return round($bytes / pow(1024, $exponent), 2).' '.['bytes', 'KB', 'MB', 'GB'][$exponent]; |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * Interesting events |
|
161 | + * Example: User logs in, SQL logs. |
|
162 | + * @param mixed $message |
|
163 | + * @param array $context |
|
164 | + * @return static |
|
165 | + */ |
|
166 | + public function info($message, array $context = []) |
|
167 | + { |
|
168 | + return $this->log(static::INFO, $message, $context); |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * @param int $level |
|
173 | + * @param mixed $message |
|
174 | + * @param array $context |
|
175 | + * @param string $backtraceLine |
|
176 | + * @return static |
|
177 | + */ |
|
178 | + public function log($level, $message, $context = [], $backtraceLine = '') |
|
179 | + { |
|
180 | + if (empty($backtraceLine)) { |
|
181 | + $backtraceLine = $this->getBacktraceLine(); |
|
182 | + } |
|
183 | + if ($this->canLogEntry($level, $backtraceLine)) { |
|
184 | + $levelName = Arr::get($this->getLevels(), $level); |
|
185 | + $context = Arr::consolidate($context); |
|
186 | + $backtraceLine = $this->normalizeBacktraceLine($backtraceLine); |
|
187 | + $message = $this->interpolate($message, $context); |
|
188 | + $entry = $this->buildLogEntry($levelName, $message, $backtraceLine); |
|
189 | + file_put_contents($this->file, $entry.PHP_EOL, FILE_APPEND | LOCK_EX); |
|
190 | + apply_filters('console', $message, $levelName, $backtraceLine); // Show in Blackbar plugin if installed |
|
191 | + $this->reset(); |
|
192 | + } |
|
193 | + return $this; |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * @return void |
|
198 | + */ |
|
199 | + public function logOnce() |
|
200 | + { |
|
201 | + $once = Arr::consolidate(glsr()->{$this->logOnceKey}); |
|
202 | + $levels = $this->getLevels(); |
|
203 | + foreach ($once as $entry) { |
|
204 | + $levelName = Arr::get($entry, 'level'); |
|
205 | + if (!in_array($levelName, $levels)) { |
|
206 | + continue; |
|
207 | + } |
|
208 | + $level = Arr::get(array_flip($levels), $levelName); |
|
209 | + $message = Arr::get($entry, 'message'); |
|
210 | + $backtraceLine = Arr::get($entry, 'backtrace'); |
|
211 | + $this->log($level, $message, [], $backtraceLine); |
|
212 | + } |
|
213 | + glsr()->{$this->logOnceKey} = []; |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * Normal but significant events. |
|
218 | + * @param mixed $message |
|
219 | + * @param array $context |
|
220 | + * @return static |
|
221 | + */ |
|
222 | + public function notice($message, array $context = []) |
|
223 | + { |
|
224 | + return $this->log(static::NOTICE, $message, $context); |
|
225 | + } |
|
226 | + |
|
227 | + /** |
|
228 | + * @param string $levelName |
|
229 | + * @param string $handle |
|
230 | + * @param mixed $data |
|
231 | + * @return void |
|
232 | + */ |
|
233 | + public function once($levelName, $handle, $data) |
|
234 | + { |
|
235 | + $once = Arr::consolidate(glsr()->{$this->logOnceKey}); |
|
236 | + $filtered = array_filter($once, function ($entry) use ($levelName, $handle) { |
|
237 | + return Arr::get($entry, 'level') == $levelName |
|
238 | + && Arr::get($entry, 'handle') == $handle; |
|
239 | + }); |
|
240 | + if (!empty($filtered)) { |
|
241 | + return; |
|
242 | + } |
|
243 | + $once[] = [ |
|
244 | + 'backtrace' => $this->getBacktraceLineFromData($data), |
|
245 | + 'handle' => $handle, |
|
246 | + 'level' => $levelName, |
|
247 | + 'message' => '[RECURRING] '.$this->getMessageFromData($data), |
|
248 | + ]; |
|
249 | + glsr()->{$this->logOnceKey} = $once; |
|
250 | + } |
|
251 | + |
|
252 | + /** |
|
253 | + * @return int |
|
254 | + */ |
|
255 | + public function size() |
|
256 | + { |
|
257 | + return file_exists($this->file) |
|
258 | + ? filesize($this->file) |
|
259 | + : 0; |
|
260 | + } |
|
261 | + |
|
262 | + /** |
|
263 | + * Exceptional occurrences that are not errors |
|
264 | + * Example: Use of deprecated APIs, poor use of an API, undesirable things that are not necessarily wrong. |
|
265 | + * @param mixed $message |
|
266 | + * @param array $context |
|
267 | + * @return static |
|
268 | + */ |
|
269 | + public function warning($message, array $context = []) |
|
270 | + { |
|
271 | + return $this->log(static::WARNING, $message, $context); |
|
272 | + } |
|
273 | + |
|
274 | + /** |
|
275 | + * @param array $backtrace |
|
276 | + * @param int $index |
|
277 | + * @return string |
|
278 | + */ |
|
279 | + protected function buildBacktraceLine($backtrace, $index) |
|
280 | + { |
|
281 | + return sprintf('%s:%s', |
|
282 | + Arr::get($backtrace, $index.'.file'), // realpath |
|
283 | + Arr::get($backtrace, $index.'.line') |
|
284 | + ); |
|
285 | + } |
|
286 | + |
|
287 | + /** |
|
288 | + * @param string $levelName |
|
289 | + * @param mixed $message |
|
290 | + * @param string $backtraceLine |
|
291 | + * @return string |
|
292 | + */ |
|
293 | + protected function buildLogEntry($levelName, $message, $backtraceLine = '') |
|
294 | + { |
|
295 | + return sprintf('[%s] %s [%s] %s', |
|
296 | + current_time('mysql'), |
|
297 | + strtoupper($levelName), |
|
298 | + $backtraceLine, |
|
299 | + $message |
|
300 | + ); |
|
301 | + } |
|
302 | + |
|
303 | + /** |
|
304 | + * @param int $level |
|
305 | + * @return bool |
|
306 | + */ |
|
307 | + protected function canLogEntry($level, $backtraceLine) |
|
308 | + { |
|
309 | + $levelExists = array_key_exists($level, $this->getLevels()); |
|
310 | + if (!Str::contains($backtraceLine, glsr()->path())) { |
|
311 | + return $levelExists; // ignore level restriction if triggered outside of the plugin |
|
312 | + } |
|
313 | + return $levelExists && $level >= $this->getLevel(); |
|
314 | + } |
|
315 | + |
|
316 | + /** |
|
317 | + * @return void|string |
|
318 | + */ |
|
319 | + protected function getBacktraceLine() |
|
320 | + { |
|
321 | + $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 6); |
|
322 | + $search = array_search('glsr_log', glsr_array_column($backtrace, 'function')); |
|
323 | + if (false !== $search) { |
|
324 | + return $this->buildBacktraceLine($backtrace, (int) $search); |
|
325 | + } |
|
326 | + $search = array_search('log', glsr_array_column($backtrace, 'function')); |
|
327 | + if (false !== $search) { |
|
328 | + $index = '{closure}' == Arr::get($backtrace, ($search + 2).'.function') |
|
329 | + ? $search + 4 |
|
330 | + : $search + 1; |
|
331 | + return $this->buildBacktraceLine($backtrace, $index); |
|
332 | + } |
|
333 | + return 'Unknown'; |
|
334 | + } |
|
335 | + |
|
336 | + /** |
|
337 | + * @param mixed $data |
|
338 | + * @return string |
|
339 | + */ |
|
340 | + protected function getBacktraceLineFromData($data) |
|
341 | + { |
|
342 | + $backtrace = $data instanceof Throwable |
|
343 | + ? $data->getTrace() |
|
344 | + : debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1); |
|
345 | + return $this->buildBacktraceLine($backtrace, 0); |
|
346 | + } |
|
347 | + |
|
348 | + /** |
|
349 | + * @param mixed $data |
|
350 | + * @return string |
|
351 | + */ |
|
352 | + protected function getMessageFromData($data) |
|
353 | + { |
|
354 | + return $data instanceof Throwable |
|
355 | + ? $this->normalizeThrowableMessage($data->getMessage()) |
|
356 | + : print_r($data, 1); |
|
357 | + } |
|
358 | + |
|
359 | + /** |
|
360 | + * Interpolates context values into the message placeholders. |
|
361 | + * @param mixed $message |
|
362 | + * @param array $context |
|
363 | + * @return string |
|
364 | + */ |
|
365 | + protected function interpolate($message, $context = []) |
|
366 | + { |
|
367 | + if ($this->isObjectOrArray($message) || !is_array($context)) { |
|
368 | + return print_r($message, true); |
|
369 | + } |
|
370 | + $replace = []; |
|
371 | + foreach ($context as $key => $value) { |
|
372 | + $replace['{'.$key.'}'] = $this->normalizeValue($value); |
|
373 | + } |
|
374 | + return strtr($message, $replace); |
|
375 | + } |
|
376 | + |
|
377 | + /** |
|
378 | + * @param mixed $value |
|
379 | + * @return bool |
|
380 | + */ |
|
381 | + protected function isObjectOrArray($value) |
|
382 | + { |
|
383 | + return is_object($value) || is_array($value); |
|
384 | + } |
|
385 | + |
|
386 | + /** |
|
387 | + * @param string $backtraceLine |
|
388 | + * @return string |
|
389 | + */ |
|
390 | + protected function normalizeBacktraceLine($backtraceLine) |
|
391 | + { |
|
392 | + $search = [ |
|
393 | + glsr()->path('plugin/'), |
|
394 | + glsr()->path('plugin/', false), |
|
395 | + trailingslashit(glsr()->path()), |
|
396 | + trailingslashit(glsr()->path('', false)), |
|
397 | + WP_CONTENT_DIR, |
|
398 | + ABSPATH, |
|
399 | + ]; |
|
400 | + return str_replace(array_unique($search), '', $backtraceLine); |
|
401 | + } |
|
402 | + |
|
403 | + /** |
|
404 | + * @param string $message |
|
405 | + * @return string |
|
406 | + */ |
|
407 | + protected function normalizeThrowableMessage($message) |
|
408 | + { |
|
409 | + $calledIn = strpos($message, ', called in'); |
|
410 | + return false !== $calledIn |
|
411 | + ? substr($message, 0, $calledIn) |
|
412 | + : $message; |
|
413 | + } |
|
414 | + |
|
415 | + /** |
|
416 | + * @param mixed $value |
|
417 | + * @return string |
|
418 | + */ |
|
419 | + protected function normalizeValue($value) |
|
420 | + { |
|
421 | + if ($value instanceof DateTime) { |
|
422 | + $value = $value->format('Y-m-d H:i:s'); |
|
423 | + } elseif ($this->isObjectOrArray($value)) { |
|
424 | + $value = json_encode($value); |
|
425 | + } |
|
426 | + return (string) $value; |
|
427 | + } |
|
428 | + |
|
429 | + /** |
|
430 | + * @return void |
|
431 | + */ |
|
432 | + protected function reset() |
|
433 | + { |
|
434 | + if ($this->size() <= pow(1024, 2) / 8) { |
|
435 | + return; |
|
436 | + } |
|
437 | + $this->clear(); |
|
438 | + file_put_contents( |
|
439 | + $this->file, |
|
440 | + $this->buildLogEntry( |
|
441 | + static::NOTICE, |
|
442 | + __('Console was automatically cleared (128 KB maximum size)', 'site-reviews') |
|
443 | + ) |
|
444 | + ); |
|
445 | + } |
|
446 | 446 | } |
@@ -10,13 +10,13 @@ discard block |
||
10 | 10 | |
11 | 11 | class Console |
12 | 12 | { |
13 | - const DEBUG = 0; // Detailed debug information |
|
14 | - const INFO = 1; // Interesting events |
|
15 | - const NOTICE = 2; // Normal but significant events |
|
16 | - const WARNING = 4; // Exceptional occurrences that are not errors |
|
17 | - const ERROR = 8; // Runtime errors that do not require immediate action |
|
18 | - const CRITICAL = 16; // Critical conditions |
|
19 | - const ALERT = 32; // Action must be taken immediately |
|
13 | + const DEBUG = 0; // Detailed debug information |
|
14 | + const INFO = 1; // Interesting events |
|
15 | + const NOTICE = 2; // Normal but significant events |
|
16 | + const WARNING = 4; // Exceptional occurrences that are not errors |
|
17 | + const ERROR = 8; // Runtime errors that do not require immediate action |
|
18 | + const CRITICAL = 16; // Critical conditions |
|
19 | + const ALERT = 32; // Action must be taken immediately |
|
20 | 20 | const EMERGENCY = 64; // System is unusable |
21 | 21 | |
22 | 22 | protected $file; |
@@ -25,9 +25,9 @@ discard block |
||
25 | 25 | |
26 | 26 | public function __construct() |
27 | 27 | { |
28 | - $this->file = glsr()->path('console.log'); |
|
29 | - $this->log = file_exists($this->file) |
|
30 | - ? file_get_contents($this->file) |
|
28 | + $this->file = glsr()->path( 'console.log' ); |
|
29 | + $this->log = file_exists( $this->file ) |
|
30 | + ? file_get_contents( $this->file ) |
|
31 | 31 | : ''; |
32 | 32 | $this->reset(); |
33 | 33 | } |
@@ -47,9 +47,9 @@ discard block |
||
47 | 47 | * @param array $context |
48 | 48 | * @return static |
49 | 49 | */ |
50 | - public function alert($message, array $context = []) |
|
50 | + public function alert( $message, array $context = [] ) |
|
51 | 51 | { |
52 | - return $this->log(static::ALERT, $message, $context); |
|
52 | + return $this->log( static::ALERT, $message, $context ); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | public function clear() |
59 | 59 | { |
60 | 60 | $this->log = ''; |
61 | - file_put_contents($this->file, $this->log); |
|
61 | + file_put_contents( $this->file, $this->log ); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
@@ -68,9 +68,9 @@ discard block |
||
68 | 68 | * @param array $context |
69 | 69 | * @return static |
70 | 70 | */ |
71 | - public function critical($message, array $context = []) |
|
71 | + public function critical( $message, array $context = [] ) |
|
72 | 72 | { |
73 | - return $this->log(static::CRITICAL, $message, $context); |
|
73 | + return $this->log( static::CRITICAL, $message, $context ); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
@@ -79,9 +79,9 @@ discard block |
||
79 | 79 | * @param array $context |
80 | 80 | * @return static |
81 | 81 | */ |
82 | - public function debug($message, array $context = []) |
|
82 | + public function debug( $message, array $context = [] ) |
|
83 | 83 | { |
84 | - return $this->log(static::DEBUG, $message, $context); |
|
84 | + return $this->log( static::DEBUG, $message, $context ); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
@@ -90,9 +90,9 @@ discard block |
||
90 | 90 | * @param array $context |
91 | 91 | * @return static |
92 | 92 | */ |
93 | - public function emergency($message, array $context = []) |
|
93 | + public function emergency( $message, array $context = [] ) |
|
94 | 94 | { |
95 | - return $this->log(static::EMERGENCY, $message, $context); |
|
95 | + return $this->log( static::EMERGENCY, $message, $context ); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
@@ -101,9 +101,9 @@ discard block |
||
101 | 101 | * @param array $context |
102 | 102 | * @return static |
103 | 103 | */ |
104 | - public function error($message, array $context = []) |
|
104 | + public function error( $message, array $context = [] ) |
|
105 | 105 | { |
106 | - return $this->log(static::ERROR, $message, $context); |
|
106 | + return $this->log( static::ERROR, $message, $context ); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | public function get() |
113 | 113 | { |
114 | 114 | return empty($this->log) |
115 | - ? __('Console is empty', 'site-reviews') |
|
115 | + ? __( 'Console is empty', 'site-reviews' ) |
|
116 | 116 | : $this->log; |
117 | 117 | } |
118 | 118 | |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | */ |
122 | 122 | public function getLevel() |
123 | 123 | { |
124 | - return intval(apply_filters('site-reviews/console/level', static::INFO)); |
|
124 | + return intval( apply_filters( 'site-reviews/console/level', static::INFO ) ); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -129,8 +129,8 @@ discard block |
||
129 | 129 | */ |
130 | 130 | public function getLevels() |
131 | 131 | { |
132 | - $constants = (new ReflectionClass(__CLASS__))->getConstants(); |
|
133 | - return array_map('strtolower', array_flip($constants)); |
|
132 | + $constants = (new ReflectionClass( __CLASS__ ))->getConstants(); |
|
133 | + return array_map( 'strtolower', array_flip( $constants ) ); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -139,21 +139,21 @@ discard block |
||
139 | 139 | public function humanLevel() |
140 | 140 | { |
141 | 141 | $level = $this->getLevel(); |
142 | - return sprintf('%s (%d)', strtoupper(Arr::get($this->getLevels(), $level, 'unknown')), $level); |
|
142 | + return sprintf( '%s (%d)', strtoupper( Arr::get( $this->getLevels(), $level, 'unknown' ) ), $level ); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | /** |
146 | 146 | * @param string|null $valueIfEmpty |
147 | 147 | * @return string |
148 | 148 | */ |
149 | - public function humanSize($valueIfEmpty = null) |
|
149 | + public function humanSize( $valueIfEmpty = null ) |
|
150 | 150 | { |
151 | 151 | $bytes = $this->size(); |
152 | - if (empty($bytes) && is_string($valueIfEmpty)) { |
|
152 | + if( empty($bytes) && is_string( $valueIfEmpty ) ) { |
|
153 | 153 | return $valueIfEmpty; |
154 | 154 | } |
155 | - $exponent = floor(log(max($bytes, 1), 1024)); |
|
156 | - return round($bytes / pow(1024, $exponent), 2).' '.['bytes', 'KB', 'MB', 'GB'][$exponent]; |
|
155 | + $exponent = floor( log( max( $bytes, 1 ), 1024 ) ); |
|
156 | + return round( $bytes / pow( 1024, $exponent ), 2 ).' '.['bytes', 'KB', 'MB', 'GB'][$exponent]; |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
@@ -163,9 +163,9 @@ discard block |
||
163 | 163 | * @param array $context |
164 | 164 | * @return static |
165 | 165 | */ |
166 | - public function info($message, array $context = []) |
|
166 | + public function info( $message, array $context = [] ) |
|
167 | 167 | { |
168 | - return $this->log(static::INFO, $message, $context); |
|
168 | + return $this->log( static::INFO, $message, $context ); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | /** |
@@ -175,19 +175,19 @@ discard block |
||
175 | 175 | * @param string $backtraceLine |
176 | 176 | * @return static |
177 | 177 | */ |
178 | - public function log($level, $message, $context = [], $backtraceLine = '') |
|
178 | + public function log( $level, $message, $context = [], $backtraceLine = '' ) |
|
179 | 179 | { |
180 | - if (empty($backtraceLine)) { |
|
180 | + if( empty($backtraceLine) ) { |
|
181 | 181 | $backtraceLine = $this->getBacktraceLine(); |
182 | 182 | } |
183 | - if ($this->canLogEntry($level, $backtraceLine)) { |
|
184 | - $levelName = Arr::get($this->getLevels(), $level); |
|
185 | - $context = Arr::consolidate($context); |
|
186 | - $backtraceLine = $this->normalizeBacktraceLine($backtraceLine); |
|
187 | - $message = $this->interpolate($message, $context); |
|
188 | - $entry = $this->buildLogEntry($levelName, $message, $backtraceLine); |
|
189 | - file_put_contents($this->file, $entry.PHP_EOL, FILE_APPEND | LOCK_EX); |
|
190 | - apply_filters('console', $message, $levelName, $backtraceLine); // Show in Blackbar plugin if installed |
|
183 | + if( $this->canLogEntry( $level, $backtraceLine ) ) { |
|
184 | + $levelName = Arr::get( $this->getLevels(), $level ); |
|
185 | + $context = Arr::consolidate( $context ); |
|
186 | + $backtraceLine = $this->normalizeBacktraceLine( $backtraceLine ); |
|
187 | + $message = $this->interpolate( $message, $context ); |
|
188 | + $entry = $this->buildLogEntry( $levelName, $message, $backtraceLine ); |
|
189 | + file_put_contents( $this->file, $entry.PHP_EOL, FILE_APPEND | LOCK_EX ); |
|
190 | + apply_filters( 'console', $message, $levelName, $backtraceLine ); // Show in Blackbar plugin if installed |
|
191 | 191 | $this->reset(); |
192 | 192 | } |
193 | 193 | return $this; |
@@ -198,17 +198,17 @@ discard block |
||
198 | 198 | */ |
199 | 199 | public function logOnce() |
200 | 200 | { |
201 | - $once = Arr::consolidate(glsr()->{$this->logOnceKey}); |
|
201 | + $once = Arr::consolidate( glsr()->{$this->logOnceKey}); |
|
202 | 202 | $levels = $this->getLevels(); |
203 | - foreach ($once as $entry) { |
|
204 | - $levelName = Arr::get($entry, 'level'); |
|
205 | - if (!in_array($levelName, $levels)) { |
|
203 | + foreach( $once as $entry ) { |
|
204 | + $levelName = Arr::get( $entry, 'level' ); |
|
205 | + if( !in_array( $levelName, $levels ) ) { |
|
206 | 206 | continue; |
207 | 207 | } |
208 | - $level = Arr::get(array_flip($levels), $levelName); |
|
209 | - $message = Arr::get($entry, 'message'); |
|
210 | - $backtraceLine = Arr::get($entry, 'backtrace'); |
|
211 | - $this->log($level, $message, [], $backtraceLine); |
|
208 | + $level = Arr::get( array_flip( $levels ), $levelName ); |
|
209 | + $message = Arr::get( $entry, 'message' ); |
|
210 | + $backtraceLine = Arr::get( $entry, 'backtrace' ); |
|
211 | + $this->log( $level, $message, [], $backtraceLine ); |
|
212 | 212 | } |
213 | 213 | glsr()->{$this->logOnceKey} = []; |
214 | 214 | } |
@@ -219,9 +219,9 @@ discard block |
||
219 | 219 | * @param array $context |
220 | 220 | * @return static |
221 | 221 | */ |
222 | - public function notice($message, array $context = []) |
|
222 | + public function notice( $message, array $context = [] ) |
|
223 | 223 | { |
224 | - return $this->log(static::NOTICE, $message, $context); |
|
224 | + return $this->log( static::NOTICE, $message, $context ); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | /** |
@@ -230,21 +230,21 @@ discard block |
||
230 | 230 | * @param mixed $data |
231 | 231 | * @return void |
232 | 232 | */ |
233 | - public function once($levelName, $handle, $data) |
|
233 | + public function once( $levelName, $handle, $data ) |
|
234 | 234 | { |
235 | - $once = Arr::consolidate(glsr()->{$this->logOnceKey}); |
|
236 | - $filtered = array_filter($once, function ($entry) use ($levelName, $handle) { |
|
237 | - return Arr::get($entry, 'level') == $levelName |
|
238 | - && Arr::get($entry, 'handle') == $handle; |
|
235 | + $once = Arr::consolidate( glsr()->{$this->logOnceKey}); |
|
236 | + $filtered = array_filter( $once, function( $entry ) use ($levelName, $handle) { |
|
237 | + return Arr::get( $entry, 'level' ) == $levelName |
|
238 | + && Arr::get( $entry, 'handle' ) == $handle; |
|
239 | 239 | }); |
240 | - if (!empty($filtered)) { |
|
240 | + if( !empty($filtered) ) { |
|
241 | 241 | return; |
242 | 242 | } |
243 | 243 | $once[] = [ |
244 | - 'backtrace' => $this->getBacktraceLineFromData($data), |
|
244 | + 'backtrace' => $this->getBacktraceLineFromData( $data ), |
|
245 | 245 | 'handle' => $handle, |
246 | 246 | 'level' => $levelName, |
247 | - 'message' => '[RECURRING] '.$this->getMessageFromData($data), |
|
247 | + 'message' => '[RECURRING] '.$this->getMessageFromData( $data ), |
|
248 | 248 | ]; |
249 | 249 | glsr()->{$this->logOnceKey} = $once; |
250 | 250 | } |
@@ -254,8 +254,8 @@ discard block |
||
254 | 254 | */ |
255 | 255 | public function size() |
256 | 256 | { |
257 | - return file_exists($this->file) |
|
258 | - ? filesize($this->file) |
|
257 | + return file_exists( $this->file ) |
|
258 | + ? filesize( $this->file ) |
|
259 | 259 | : 0; |
260 | 260 | } |
261 | 261 | |
@@ -266,9 +266,9 @@ discard block |
||
266 | 266 | * @param array $context |
267 | 267 | * @return static |
268 | 268 | */ |
269 | - public function warning($message, array $context = []) |
|
269 | + public function warning( $message, array $context = [] ) |
|
270 | 270 | { |
271 | - return $this->log(static::WARNING, $message, $context); |
|
271 | + return $this->log( static::WARNING, $message, $context ); |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | /** |
@@ -276,11 +276,11 @@ discard block |
||
276 | 276 | * @param int $index |
277 | 277 | * @return string |
278 | 278 | */ |
279 | - protected function buildBacktraceLine($backtrace, $index) |
|
279 | + protected function buildBacktraceLine( $backtrace, $index ) |
|
280 | 280 | { |
281 | - return sprintf('%s:%s', |
|
282 | - Arr::get($backtrace, $index.'.file'), // realpath |
|
283 | - Arr::get($backtrace, $index.'.line') |
|
281 | + return sprintf( '%s:%s', |
|
282 | + Arr::get( $backtrace, $index.'.file' ), // realpath |
|
283 | + Arr::get( $backtrace, $index.'.line' ) |
|
284 | 284 | ); |
285 | 285 | } |
286 | 286 | |
@@ -290,11 +290,11 @@ discard block |
||
290 | 290 | * @param string $backtraceLine |
291 | 291 | * @return string |
292 | 292 | */ |
293 | - protected function buildLogEntry($levelName, $message, $backtraceLine = '') |
|
293 | + protected function buildLogEntry( $levelName, $message, $backtraceLine = '' ) |
|
294 | 294 | { |
295 | - return sprintf('[%s] %s [%s] %s', |
|
296 | - current_time('mysql'), |
|
297 | - strtoupper($levelName), |
|
295 | + return sprintf( '[%s] %s [%s] %s', |
|
296 | + current_time( 'mysql' ), |
|
297 | + strtoupper( $levelName ), |
|
298 | 298 | $backtraceLine, |
299 | 299 | $message |
300 | 300 | ); |
@@ -304,10 +304,10 @@ discard block |
||
304 | 304 | * @param int $level |
305 | 305 | * @return bool |
306 | 306 | */ |
307 | - protected function canLogEntry($level, $backtraceLine) |
|
307 | + protected function canLogEntry( $level, $backtraceLine ) |
|
308 | 308 | { |
309 | - $levelExists = array_key_exists($level, $this->getLevels()); |
|
310 | - if (!Str::contains($backtraceLine, glsr()->path())) { |
|
309 | + $levelExists = array_key_exists( $level, $this->getLevels() ); |
|
310 | + if( !Str::contains( $backtraceLine, glsr()->path() ) ) { |
|
311 | 311 | return $levelExists; // ignore level restriction if triggered outside of the plugin |
312 | 312 | } |
313 | 313 | return $levelExists && $level >= $this->getLevel(); |
@@ -318,17 +318,17 @@ discard block |
||
318 | 318 | */ |
319 | 319 | protected function getBacktraceLine() |
320 | 320 | { |
321 | - $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 6); |
|
322 | - $search = array_search('glsr_log', glsr_array_column($backtrace, 'function')); |
|
323 | - if (false !== $search) { |
|
324 | - return $this->buildBacktraceLine($backtrace, (int) $search); |
|
321 | + $backtrace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 6 ); |
|
322 | + $search = array_search( 'glsr_log', glsr_array_column( $backtrace, 'function' ) ); |
|
323 | + if( false !== $search ) { |
|
324 | + return $this->buildBacktraceLine( $backtrace, (int)$search ); |
|
325 | 325 | } |
326 | - $search = array_search('log', glsr_array_column($backtrace, 'function')); |
|
327 | - if (false !== $search) { |
|
328 | - $index = '{closure}' == Arr::get($backtrace, ($search + 2).'.function') |
|
326 | + $search = array_search( 'log', glsr_array_column( $backtrace, 'function' ) ); |
|
327 | + if( false !== $search ) { |
|
328 | + $index = '{closure}' == Arr::get( $backtrace, ($search + 2).'.function' ) |
|
329 | 329 | ? $search + 4 |
330 | 330 | : $search + 1; |
331 | - return $this->buildBacktraceLine($backtrace, $index); |
|
331 | + return $this->buildBacktraceLine( $backtrace, $index ); |
|
332 | 332 | } |
333 | 333 | return 'Unknown'; |
334 | 334 | } |
@@ -337,23 +337,23 @@ discard block |
||
337 | 337 | * @param mixed $data |
338 | 338 | * @return string |
339 | 339 | */ |
340 | - protected function getBacktraceLineFromData($data) |
|
340 | + protected function getBacktraceLineFromData( $data ) |
|
341 | 341 | { |
342 | 342 | $backtrace = $data instanceof Throwable |
343 | 343 | ? $data->getTrace() |
344 | - : debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1); |
|
345 | - return $this->buildBacktraceLine($backtrace, 0); |
|
344 | + : debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 1 ); |
|
345 | + return $this->buildBacktraceLine( $backtrace, 0 ); |
|
346 | 346 | } |
347 | 347 | |
348 | 348 | /** |
349 | 349 | * @param mixed $data |
350 | 350 | * @return string |
351 | 351 | */ |
352 | - protected function getMessageFromData($data) |
|
352 | + protected function getMessageFromData( $data ) |
|
353 | 353 | { |
354 | 354 | return $data instanceof Throwable |
355 | - ? $this->normalizeThrowableMessage($data->getMessage()) |
|
356 | - : print_r($data, 1); |
|
355 | + ? $this->normalizeThrowableMessage( $data->getMessage() ) |
|
356 | + : print_r( $data, 1 ); |
|
357 | 357 | } |
358 | 358 | |
359 | 359 | /** |
@@ -362,53 +362,53 @@ discard block |
||
362 | 362 | * @param array $context |
363 | 363 | * @return string |
364 | 364 | */ |
365 | - protected function interpolate($message, $context = []) |
|
365 | + protected function interpolate( $message, $context = [] ) |
|
366 | 366 | { |
367 | - if ($this->isObjectOrArray($message) || !is_array($context)) { |
|
368 | - return print_r($message, true); |
|
367 | + if( $this->isObjectOrArray( $message ) || !is_array( $context ) ) { |
|
368 | + return print_r( $message, true ); |
|
369 | 369 | } |
370 | 370 | $replace = []; |
371 | - foreach ($context as $key => $value) { |
|
372 | - $replace['{'.$key.'}'] = $this->normalizeValue($value); |
|
371 | + foreach( $context as $key => $value ) { |
|
372 | + $replace['{'.$key.'}'] = $this->normalizeValue( $value ); |
|
373 | 373 | } |
374 | - return strtr($message, $replace); |
|
374 | + return strtr( $message, $replace ); |
|
375 | 375 | } |
376 | 376 | |
377 | 377 | /** |
378 | 378 | * @param mixed $value |
379 | 379 | * @return bool |
380 | 380 | */ |
381 | - protected function isObjectOrArray($value) |
|
381 | + protected function isObjectOrArray( $value ) |
|
382 | 382 | { |
383 | - return is_object($value) || is_array($value); |
|
383 | + return is_object( $value ) || is_array( $value ); |
|
384 | 384 | } |
385 | 385 | |
386 | 386 | /** |
387 | 387 | * @param string $backtraceLine |
388 | 388 | * @return string |
389 | 389 | */ |
390 | - protected function normalizeBacktraceLine($backtraceLine) |
|
390 | + protected function normalizeBacktraceLine( $backtraceLine ) |
|
391 | 391 | { |
392 | 392 | $search = [ |
393 | - glsr()->path('plugin/'), |
|
394 | - glsr()->path('plugin/', false), |
|
395 | - trailingslashit(glsr()->path()), |
|
396 | - trailingslashit(glsr()->path('', false)), |
|
393 | + glsr()->path( 'plugin/' ), |
|
394 | + glsr()->path( 'plugin/', false ), |
|
395 | + trailingslashit( glsr()->path() ), |
|
396 | + trailingslashit( glsr()->path( '', false ) ), |
|
397 | 397 | WP_CONTENT_DIR, |
398 | 398 | ABSPATH, |
399 | 399 | ]; |
400 | - return str_replace(array_unique($search), '', $backtraceLine); |
|
400 | + return str_replace( array_unique( $search ), '', $backtraceLine ); |
|
401 | 401 | } |
402 | 402 | |
403 | 403 | /** |
404 | 404 | * @param string $message |
405 | 405 | * @return string |
406 | 406 | */ |
407 | - protected function normalizeThrowableMessage($message) |
|
407 | + protected function normalizeThrowableMessage( $message ) |
|
408 | 408 | { |
409 | - $calledIn = strpos($message, ', called in'); |
|
409 | + $calledIn = strpos( $message, ', called in' ); |
|
410 | 410 | return false !== $calledIn |
411 | - ? substr($message, 0, $calledIn) |
|
411 | + ? substr( $message, 0, $calledIn ) |
|
412 | 412 | : $message; |
413 | 413 | } |
414 | 414 | |
@@ -416,14 +416,14 @@ discard block |
||
416 | 416 | * @param mixed $value |
417 | 417 | * @return string |
418 | 418 | */ |
419 | - protected function normalizeValue($value) |
|
419 | + protected function normalizeValue( $value ) |
|
420 | 420 | { |
421 | - if ($value instanceof DateTime) { |
|
422 | - $value = $value->format('Y-m-d H:i:s'); |
|
423 | - } elseif ($this->isObjectOrArray($value)) { |
|
424 | - $value = json_encode($value); |
|
421 | + if( $value instanceof DateTime ) { |
|
422 | + $value = $value->format( 'Y-m-d H:i:s' ); |
|
423 | + } elseif( $this->isObjectOrArray( $value ) ) { |
|
424 | + $value = json_encode( $value ); |
|
425 | 425 | } |
426 | - return (string) $value; |
|
426 | + return (string)$value; |
|
427 | 427 | } |
428 | 428 | |
429 | 429 | /** |
@@ -431,7 +431,7 @@ discard block |
||
431 | 431 | */ |
432 | 432 | protected function reset() |
433 | 433 | { |
434 | - if ($this->size() <= pow(1024, 2) / 8) { |
|
434 | + if( $this->size() <= pow( 1024, 2 ) / 8 ) { |
|
435 | 435 | return; |
436 | 436 | } |
437 | 437 | $this->clear(); |
@@ -439,7 +439,7 @@ discard block |
||
439 | 439 | $this->file, |
440 | 440 | $this->buildLogEntry( |
441 | 441 | static::NOTICE, |
442 | - __('Console was automatically cleared (128 KB maximum size)', 'site-reviews') |
|
442 | + __( 'Console was automatically cleared (128 KB maximum size)', 'site-reviews' ) |
|
443 | 443 | ) |
444 | 444 | ); |
445 | 445 | } |
@@ -19,12 +19,12 @@ |
||
19 | 19 | */ |
20 | 20 | class Thing extends BaseType |
21 | 21 | { |
22 | - /** |
|
23 | - * @var array |
|
24 | - * @see http://schema.org/{property_name} |
|
25 | - */ |
|
26 | - public $allowed = [ |
|
27 | - 'additionalType', 'alternateName', 'description', 'disambiguatingDescription', 'identifier', |
|
28 | - 'image', 'mainEntityOfPage', 'name', 'potentialAction', 'sameAs', 'url', |
|
29 | - ]; |
|
22 | + /** |
|
23 | + * @var array |
|
24 | + * @see http://schema.org/{property_name} |
|
25 | + */ |
|
26 | + public $allowed = [ |
|
27 | + 'additionalType', 'alternateName', 'description', 'disambiguatingDescription', 'identifier', |
|
28 | + 'image', 'mainEntityOfPage', 'name', 'potentialAction', 'sameAs', 'url', |
|
29 | + ]; |
|
30 | 30 | } |
@@ -4,19 +4,19 @@ |
||
4 | 4 | |
5 | 5 | class UnknownType extends BaseType |
6 | 6 | { |
7 | - /** |
|
8 | - * @var array |
|
9 | - * @see http://schema.org/{property_name} |
|
10 | - */ |
|
11 | - public $allowed = [ |
|
12 | - 'aggregateRating', |
|
13 | - ]; |
|
7 | + /** |
|
8 | + * @var array |
|
9 | + * @see http://schema.org/{property_name} |
|
10 | + */ |
|
11 | + public $allowed = [ |
|
12 | + 'aggregateRating', |
|
13 | + ]; |
|
14 | 14 | |
15 | - /** |
|
16 | - * @var array |
|
17 | - * @see http://schema.org/{property_name} |
|
18 | - */ |
|
19 | - public $parents = [ |
|
20 | - 'Thing', |
|
21 | - ]; |
|
15 | + /** |
|
16 | + * @var array |
|
17 | + * @see http://schema.org/{property_name} |
|
18 | + */ |
|
19 | + public $parents = [ |
|
20 | + 'Thing', |
|
21 | + ]; |
|
22 | 22 | } |
@@ -4,22 +4,22 @@ |
||
4 | 4 | |
5 | 5 | interface Type |
6 | 6 | { |
7 | - /** |
|
8 | - * Return an array representation of the type. If the array contains child types, |
|
9 | - * their context needs to be stripped if it's the same. |
|
10 | - * @return array |
|
11 | - */ |
|
12 | - public function toArray(); |
|
7 | + /** |
|
8 | + * Return an array representation of the type. If the array contains child types, |
|
9 | + * their context needs to be stripped if it's the same. |
|
10 | + * @return array |
|
11 | + */ |
|
12 | + public function toArray(); |
|
13 | 13 | |
14 | - /** |
|
15 | - * Create a json-ld script tag for this type, built from the data that `toArray` returns. |
|
16 | - * @return string |
|
17 | - */ |
|
18 | - public function toScript(); |
|
14 | + /** |
|
15 | + * Create a json-ld script tag for this type, built from the data that `toArray` returns. |
|
16 | + * @return string |
|
17 | + */ |
|
18 | + public function toScript(); |
|
19 | 19 | |
20 | - /** |
|
21 | - * Create a json-ld script tag for this type, built from the data that `toArray` returns. |
|
22 | - * @return string |
|
23 | - */ |
|
24 | - public function __toString(); |
|
20 | + /** |
|
21 | + * Create a json-ld script tag for this type, built from the data that `toArray` returns. |
|
22 | + * @return string |
|
23 | + */ |
|
24 | + public function __toString(); |
|
25 | 25 | } |
@@ -57,166 +57,166 @@ |
||
57 | 57 | */ |
58 | 58 | class Organization extends BaseType |
59 | 59 | { |
60 | - /** |
|
61 | - * The schema.org Actions mechanism benefited from extensive discussions across the Web |
|
62 | - * standards community around W3C, in particular from the [Hydra project](http://purl.org/hydra/) |
|
63 | - * community group. |
|
64 | - * @see http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#source_ActionCollabClass |
|
65 | - */ |
|
66 | - const ActionCollabClass = 'http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#source_ActionCollabClass'; |
|
67 | - |
|
68 | - /** |
|
69 | - * This element is based on the work of the Automotive Ontology Working Group, |
|
70 | - * see [www.automotive-ontology.org](http://www.automotive-ontology.org) for details. |
|
71 | - * Many class and property definitions are inspired by or based on abstracts from Wikipedia, |
|
72 | - * the free encyclopedia. |
|
73 | - * @see http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#Automotive_Ontology_Working_Group |
|
74 | - */ |
|
75 | - const AutomotiveOntologyWGClass = 'http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#Automotive_Ontology_Working_Group'; |
|
76 | - |
|
77 | - /** |
|
78 | - * The W3C [Schema Bib Extend](http://www.w3.org/community/schemabibex/) (BibEx) group led the |
|
79 | - * work to improve schema.org for bibliographic information, including terms for periodicals, |
|
80 | - * articles and multi-volume works. The design was inspired in places (e.g. [[pageStart]], |
|
81 | - * [[pageEnd]], [[pagination]]) by the [Bibliographic Ontology](http://bibliontology.com/), |
|
82 | - * 'bibo'. |
|
83 | - * @see http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#source_bibex |
|
84 | - */ |
|
85 | - const BibExTerm = 'http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#source_bibex'; |
|
86 | - |
|
87 | - /** |
|
88 | - * This class is based upon W3C DCAT work, and benefits from collaboration around the DCAT, ADMS |
|
89 | - * and VoID vocabularies. See http://www.w3.org/wiki/WebSchemas/Datasets for full details and |
|
90 | - * mappings. |
|
91 | - * @see http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#source_DatasetClass |
|
92 | - */ |
|
93 | - const DatasetClass = 'http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#source_DatasetClass'; |
|
94 | - |
|
95 | - /** |
|
96 | - * This element is based on the work of the Financial Industry Business Ontology project (see |
|
97 | - * [http://www.fibo.org/schema](http://www.fibo.org/schema) for details), in support of the W3C |
|
98 | - * Financial Industry Business Ontology Community Group |
|
99 | - * ([http://www.fibo.org/community](http://www.fibo.org/community)). Many class and property |
|
100 | - * definitions are inspired by or based on [http://www.fibo.org](http://www.fibo.org). |
|
101 | - * @see http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#FIBO |
|
102 | - */ |
|
103 | - const FIBO = 'http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#FIBO'; |
|
104 | - |
|
105 | - /** |
|
106 | - * The implementation and use of Legal Entity Identifier (LEI) is supported by Global Legal |
|
107 | - * Entity Identifier Foundation [https://www.gleif.org](https://www.gleif.org). |
|
108 | - * @see http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#GLEIF |
|
109 | - */ |
|
110 | - const GLEIF = 'http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#GLEIF'; |
|
111 | - |
|
112 | - /** |
|
113 | - * This class is derived from the GoodRelations Vocabulary for E-Commerce, created by Martin |
|
114 | - * Hepp. GoodRelations is a data model for sharing e-commerce data on the Web that can be |
|
115 | - * expressed in a variety of syntaxes, including RDFa and HTML5 Microdata. More information |
|
116 | - * about GoodRelations can be found at |
|
117 | - * [http://purl.org/goodrelations/](http://purl.org/goodrelations/). |
|
118 | - * @see http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#source_GoodRelationsClass |
|
119 | - */ |
|
120 | - const GoodRelationsClass = 'http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#source_GoodRelationsClass'; |
|
121 | - |
|
122 | - /** |
|
123 | - * This term [uses](http://blog.schema.org/2012/11/good-relations-and-schemaorg.html) |
|
124 | - * terminology from the GoodRelations Vocabulary for E-Commerce, created by Martin Hepp. |
|
125 | - * GoodRelations is a data model for sharing e-commerce data on the Web. More information about |
|
126 | - * GoodRelations can be found at |
|
127 | - * [http://purl.org/goodrelations/](http://purl.org/goodrelations/). |
|
128 | - * @see http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#source_GoodRelationsTerms |
|
129 | - */ |
|
130 | - const GoodRelationsTerms = 'http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#source_GoodRelationsTerms'; |
|
131 | - |
|
132 | - /** |
|
133 | - * This element is based on work by the Web Applications for the Future Internet Lab, Institute |
|
134 | - * of Informatics and Telematics, Pisa, Italy. |
|
135 | - * @see http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#IIT-CNR.it |
|
136 | - */ |
|
137 | - const IITCNRit = 'http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#IIT-CNR.it'; |
|
138 | - |
|
139 | - /** |
|
140 | - * This class is based on the work of the LRMI project, see lrmi.net for details. |
|
141 | - * @see http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#source_LRMIClass |
|
142 | - */ |
|
143 | - const LRMIClass = 'http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#source_LRMIClass'; |
|
144 | - |
|
145 | - /** |
|
146 | - * This vocabulary was improved through collaboration with the MusicBrainz project |
|
147 | - * ([www.musicbrainz.org](http://www.musicbrainz.org)), and is partially inspired by the |
|
148 | - * MusicBrainz and |
|
149 | - * [Music Ontology](http://musicontology.com/docs/getting-started.html) schemas. |
|
150 | - * @see http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#MBZ |
|
151 | - */ |
|
152 | - const MBZ = 'http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#MBZ'; |
|
153 | - |
|
154 | - /** |
|
155 | - * This element is based on the STI Accommodation Ontology, see <a |
|
156 | - * href="http://ontologies.sti-innsbruck.at/acco/ns.html">http://ontologies.sti-innsbruck.at/acco/ns.html</a> |
|
157 | - * for details. |
|
158 | - * Many class and property definitions are inspired by or based on abstracts from Wikipedia, |
|
159 | - * the free encyclopedia. |
|
160 | - * @see https://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#STI_Accommodation_Ontology |
|
161 | - */ |
|
162 | - const STI_Accommodation_Ontology = 'https://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#STI_Accommodation_Ontology'; |
|
163 | - |
|
164 | - /** |
|
165 | - * The Question/Answer types were [based |
|
166 | - * on](https://www.w3.org/wiki/WebSchemas/QASchemaResearch) the Stack Overflow API. |
|
167 | - * @see http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#source_QAStackExchange |
|
168 | - */ |
|
169 | - const Stack_Exchange = 'http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#source_QAStackExchange'; |
|
170 | - |
|
171 | - /** |
|
172 | - * This term and associated definitions draws upon the work of [The Trust |
|
173 | - * Project](http://thetrustproject.org/). |
|
174 | - * @see https://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#TP-draws |
|
175 | - */ |
|
176 | - const The_Trust_Project = 'https://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#TP-draws'; |
|
177 | - |
|
178 | - /** |
|
179 | - * This element is based on the work of the [Tourism Structured Web Data Community |
|
180 | - * Group](https://www.w3.org/community/tourismdata). |
|
181 | - * @see http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#Tourism |
|
182 | - */ |
|
183 | - const Tourism = 'http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#Tourism'; |
|
184 | - |
|
185 | - /** |
|
186 | - * This class contains information contributed by |
|
187 | - * [http://wikidoc.org>WikiDoc](http://wikidoc.org>WikiDoc). |
|
188 | - * @see http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#source_WikiDoc |
|
189 | - */ |
|
190 | - const WikiDoc = 'http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#source_WikiDoc'; |
|
191 | - |
|
192 | - /** |
|
193 | - * This class contains derivatives of IPTC rNews properties. rNews is a data model of publishing |
|
194 | - * metadata with serializations currently available for RDFa as well as HTML5 Microdata. More |
|
195 | - * information about the IPTC and rNews can be found at [rnews.org](http://rnews.org). |
|
196 | - * @see http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#source_rNews |
|
197 | - */ |
|
198 | - const rNews = 'http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#source_rNews'; |
|
199 | - |
|
200 | - /** |
|
201 | - * @var array |
|
202 | - * @see http://schema.org/{property_name} |
|
203 | - */ |
|
204 | - public $allowed = [ |
|
205 | - 'address', 'aggregateRating', 'areaServed', 'award', 'awards', 'brand', 'contactPoint', |
|
206 | - 'contactPoints', 'department', 'dissolutionDate', 'duns', 'email', 'employee', 'employees', |
|
207 | - 'event', 'events', 'faxNumber', 'founder', 'founders', 'foundingDate', 'foundingLocation', |
|
208 | - 'funder', 'globalLocationNumber', 'hasOfferCatalog', 'hasPOS', 'isicV4', 'legalName', |
|
209 | - 'leiCode', 'location', 'logo', 'makesOffer', 'member', 'memberOf', 'members', 'naics', |
|
210 | - 'numberOfEmployees', 'offeredBy', 'owns', 'parentOrganization', 'publishingPrinciples', |
|
211 | - 'review', 'reviews', 'seeks', 'serviceArea', 'sponsor', 'subOrganization', 'taxID', |
|
212 | - 'telephone', 'vatID', |
|
213 | - ]; |
|
214 | - |
|
215 | - /** |
|
216 | - * @var array |
|
217 | - * @see http://schema.org/{property_name} |
|
218 | - */ |
|
219 | - public $parents = [ |
|
220 | - 'Thing', |
|
221 | - ]; |
|
60 | + /** |
|
61 | + * The schema.org Actions mechanism benefited from extensive discussions across the Web |
|
62 | + * standards community around W3C, in particular from the [Hydra project](http://purl.org/hydra/) |
|
63 | + * community group. |
|
64 | + * @see http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#source_ActionCollabClass |
|
65 | + */ |
|
66 | + const ActionCollabClass = 'http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#source_ActionCollabClass'; |
|
67 | + |
|
68 | + /** |
|
69 | + * This element is based on the work of the Automotive Ontology Working Group, |
|
70 | + * see [www.automotive-ontology.org](http://www.automotive-ontology.org) for details. |
|
71 | + * Many class and property definitions are inspired by or based on abstracts from Wikipedia, |
|
72 | + * the free encyclopedia. |
|
73 | + * @see http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#Automotive_Ontology_Working_Group |
|
74 | + */ |
|
75 | + const AutomotiveOntologyWGClass = 'http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#Automotive_Ontology_Working_Group'; |
|
76 | + |
|
77 | + /** |
|
78 | + * The W3C [Schema Bib Extend](http://www.w3.org/community/schemabibex/) (BibEx) group led the |
|
79 | + * work to improve schema.org for bibliographic information, including terms for periodicals, |
|
80 | + * articles and multi-volume works. The design was inspired in places (e.g. [[pageStart]], |
|
81 | + * [[pageEnd]], [[pagination]]) by the [Bibliographic Ontology](http://bibliontology.com/), |
|
82 | + * 'bibo'. |
|
83 | + * @see http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#source_bibex |
|
84 | + */ |
|
85 | + const BibExTerm = 'http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#source_bibex'; |
|
86 | + |
|
87 | + /** |
|
88 | + * This class is based upon W3C DCAT work, and benefits from collaboration around the DCAT, ADMS |
|
89 | + * and VoID vocabularies. See http://www.w3.org/wiki/WebSchemas/Datasets for full details and |
|
90 | + * mappings. |
|
91 | + * @see http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#source_DatasetClass |
|
92 | + */ |
|
93 | + const DatasetClass = 'http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#source_DatasetClass'; |
|
94 | + |
|
95 | + /** |
|
96 | + * This element is based on the work of the Financial Industry Business Ontology project (see |
|
97 | + * [http://www.fibo.org/schema](http://www.fibo.org/schema) for details), in support of the W3C |
|
98 | + * Financial Industry Business Ontology Community Group |
|
99 | + * ([http://www.fibo.org/community](http://www.fibo.org/community)). Many class and property |
|
100 | + * definitions are inspired by or based on [http://www.fibo.org](http://www.fibo.org). |
|
101 | + * @see http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#FIBO |
|
102 | + */ |
|
103 | + const FIBO = 'http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#FIBO'; |
|
104 | + |
|
105 | + /** |
|
106 | + * The implementation and use of Legal Entity Identifier (LEI) is supported by Global Legal |
|
107 | + * Entity Identifier Foundation [https://www.gleif.org](https://www.gleif.org). |
|
108 | + * @see http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#GLEIF |
|
109 | + */ |
|
110 | + const GLEIF = 'http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#GLEIF'; |
|
111 | + |
|
112 | + /** |
|
113 | + * This class is derived from the GoodRelations Vocabulary for E-Commerce, created by Martin |
|
114 | + * Hepp. GoodRelations is a data model for sharing e-commerce data on the Web that can be |
|
115 | + * expressed in a variety of syntaxes, including RDFa and HTML5 Microdata. More information |
|
116 | + * about GoodRelations can be found at |
|
117 | + * [http://purl.org/goodrelations/](http://purl.org/goodrelations/). |
|
118 | + * @see http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#source_GoodRelationsClass |
|
119 | + */ |
|
120 | + const GoodRelationsClass = 'http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#source_GoodRelationsClass'; |
|
121 | + |
|
122 | + /** |
|
123 | + * This term [uses](http://blog.schema.org/2012/11/good-relations-and-schemaorg.html) |
|
124 | + * terminology from the GoodRelations Vocabulary for E-Commerce, created by Martin Hepp. |
|
125 | + * GoodRelations is a data model for sharing e-commerce data on the Web. More information about |
|
126 | + * GoodRelations can be found at |
|
127 | + * [http://purl.org/goodrelations/](http://purl.org/goodrelations/). |
|
128 | + * @see http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#source_GoodRelationsTerms |
|
129 | + */ |
|
130 | + const GoodRelationsTerms = 'http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#source_GoodRelationsTerms'; |
|
131 | + |
|
132 | + /** |
|
133 | + * This element is based on work by the Web Applications for the Future Internet Lab, Institute |
|
134 | + * of Informatics and Telematics, Pisa, Italy. |
|
135 | + * @see http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#IIT-CNR.it |
|
136 | + */ |
|
137 | + const IITCNRit = 'http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#IIT-CNR.it'; |
|
138 | + |
|
139 | + /** |
|
140 | + * This class is based on the work of the LRMI project, see lrmi.net for details. |
|
141 | + * @see http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#source_LRMIClass |
|
142 | + */ |
|
143 | + const LRMIClass = 'http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#source_LRMIClass'; |
|
144 | + |
|
145 | + /** |
|
146 | + * This vocabulary was improved through collaboration with the MusicBrainz project |
|
147 | + * ([www.musicbrainz.org](http://www.musicbrainz.org)), and is partially inspired by the |
|
148 | + * MusicBrainz and |
|
149 | + * [Music Ontology](http://musicontology.com/docs/getting-started.html) schemas. |
|
150 | + * @see http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#MBZ |
|
151 | + */ |
|
152 | + const MBZ = 'http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#MBZ'; |
|
153 | + |
|
154 | + /** |
|
155 | + * This element is based on the STI Accommodation Ontology, see <a |
|
156 | + * href="http://ontologies.sti-innsbruck.at/acco/ns.html">http://ontologies.sti-innsbruck.at/acco/ns.html</a> |
|
157 | + * for details. |
|
158 | + * Many class and property definitions are inspired by or based on abstracts from Wikipedia, |
|
159 | + * the free encyclopedia. |
|
160 | + * @see https://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#STI_Accommodation_Ontology |
|
161 | + */ |
|
162 | + const STI_Accommodation_Ontology = 'https://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#STI_Accommodation_Ontology'; |
|
163 | + |
|
164 | + /** |
|
165 | + * The Question/Answer types were [based |
|
166 | + * on](https://www.w3.org/wiki/WebSchemas/QASchemaResearch) the Stack Overflow API. |
|
167 | + * @see http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#source_QAStackExchange |
|
168 | + */ |
|
169 | + const Stack_Exchange = 'http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#source_QAStackExchange'; |
|
170 | + |
|
171 | + /** |
|
172 | + * This term and associated definitions draws upon the work of [The Trust |
|
173 | + * Project](http://thetrustproject.org/). |
|
174 | + * @see https://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#TP-draws |
|
175 | + */ |
|
176 | + const The_Trust_Project = 'https://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#TP-draws'; |
|
177 | + |
|
178 | + /** |
|
179 | + * This element is based on the work of the [Tourism Structured Web Data Community |
|
180 | + * Group](https://www.w3.org/community/tourismdata). |
|
181 | + * @see http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#Tourism |
|
182 | + */ |
|
183 | + const Tourism = 'http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#Tourism'; |
|
184 | + |
|
185 | + /** |
|
186 | + * This class contains information contributed by |
|
187 | + * [http://wikidoc.org>WikiDoc](http://wikidoc.org>WikiDoc). |
|
188 | + * @see http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#source_WikiDoc |
|
189 | + */ |
|
190 | + const WikiDoc = 'http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#source_WikiDoc'; |
|
191 | + |
|
192 | + /** |
|
193 | + * This class contains derivatives of IPTC rNews properties. rNews is a data model of publishing |
|
194 | + * metadata with serializations currently available for RDFa as well as HTML5 Microdata. More |
|
195 | + * information about the IPTC and rNews can be found at [rnews.org](http://rnews.org). |
|
196 | + * @see http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#source_rNews |
|
197 | + */ |
|
198 | + const rNews = 'http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#source_rNews'; |
|
199 | + |
|
200 | + /** |
|
201 | + * @var array |
|
202 | + * @see http://schema.org/{property_name} |
|
203 | + */ |
|
204 | + public $allowed = [ |
|
205 | + 'address', 'aggregateRating', 'areaServed', 'award', 'awards', 'brand', 'contactPoint', |
|
206 | + 'contactPoints', 'department', 'dissolutionDate', 'duns', 'email', 'employee', 'employees', |
|
207 | + 'event', 'events', 'faxNumber', 'founder', 'founders', 'foundingDate', 'foundingLocation', |
|
208 | + 'funder', 'globalLocationNumber', 'hasOfferCatalog', 'hasPOS', 'isicV4', 'legalName', |
|
209 | + 'leiCode', 'location', 'logo', 'makesOffer', 'member', 'memberOf', 'members', 'naics', |
|
210 | + 'numberOfEmployees', 'offeredBy', 'owns', 'parentOrganization', 'publishingPrinciples', |
|
211 | + 'review', 'reviews', 'seeks', 'serviceArea', 'sponsor', 'subOrganization', 'taxID', |
|
212 | + 'telephone', 'vatID', |
|
213 | + ]; |
|
214 | + |
|
215 | + /** |
|
216 | + * @var array |
|
217 | + * @see http://schema.org/{property_name} |
|
218 | + */ |
|
219 | + public $parents = [ |
|
220 | + 'Thing', |
|
221 | + ]; |
|
222 | 222 | } |