@@ -9,7 +9,7 @@ |
||
9 | 9 | </div> |
10 | 10 | |
11 | 11 | <?php if (empty($response)) { |
12 | - return; |
|
12 | + return; |
|
13 | 13 | } ?> |
14 | 14 | |
15 | 15 | <div class="postbox glsr-response-postbox"> |
@@ -9,138 +9,138 @@ |
||
9 | 9 | |
10 | 10 | class Slack |
11 | 11 | { |
12 | - /** |
|
13 | - * @var string |
|
14 | - */ |
|
15 | - public $endpoint; |
|
12 | + /** |
|
13 | + * @var string |
|
14 | + */ |
|
15 | + public $endpoint; |
|
16 | 16 | |
17 | - /** |
|
18 | - * @var array |
|
19 | - */ |
|
20 | - public $notification; |
|
17 | + /** |
|
18 | + * @var array |
|
19 | + */ |
|
20 | + public $notification; |
|
21 | 21 | |
22 | - /** |
|
23 | - * @var Review |
|
24 | - */ |
|
25 | - public $review; |
|
22 | + /** |
|
23 | + * @var Review |
|
24 | + */ |
|
25 | + public $review; |
|
26 | 26 | |
27 | - public function __construct() |
|
28 | - { |
|
29 | - $this->endpoint = glsr(OptionManager::class)->get('settings.general.notification_slack'); |
|
30 | - } |
|
27 | + public function __construct() |
|
28 | + { |
|
29 | + $this->endpoint = glsr(OptionManager::class)->get('settings.general.notification_slack'); |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * @return Slack |
|
34 | - */ |
|
35 | - public function compose(Review $review, array $notification) |
|
36 | - { |
|
37 | - if (empty($this->endpoint)) { |
|
38 | - return $this; |
|
39 | - } |
|
40 | - $args = shortcode_atts(glsr(SlackDefaults::class)->defaults(), $notification); |
|
41 | - $this->review = $review; |
|
42 | - $notification = [ |
|
43 | - 'icon_url' => $args['icon_url'], |
|
44 | - 'username' => $args['username'], |
|
45 | - 'attachments' => [[ |
|
46 | - 'actions' => $this->buildAction($args), |
|
47 | - 'pretext' => $args['pretext'], |
|
48 | - 'color' => $args['color'], |
|
49 | - 'fallback' => $args['fallback'], |
|
50 | - 'fields' => $this->buildFields(), |
|
51 | - ]], |
|
52 | - ]; |
|
53 | - $this->notification = apply_filters('site-reviews/slack/compose', $notification, $this); |
|
54 | - return $this; |
|
55 | - } |
|
32 | + /** |
|
33 | + * @return Slack |
|
34 | + */ |
|
35 | + public function compose(Review $review, array $notification) |
|
36 | + { |
|
37 | + if (empty($this->endpoint)) { |
|
38 | + return $this; |
|
39 | + } |
|
40 | + $args = shortcode_atts(glsr(SlackDefaults::class)->defaults(), $notification); |
|
41 | + $this->review = $review; |
|
42 | + $notification = [ |
|
43 | + 'icon_url' => $args['icon_url'], |
|
44 | + 'username' => $args['username'], |
|
45 | + 'attachments' => [[ |
|
46 | + 'actions' => $this->buildAction($args), |
|
47 | + 'pretext' => $args['pretext'], |
|
48 | + 'color' => $args['color'], |
|
49 | + 'fallback' => $args['fallback'], |
|
50 | + 'fields' => $this->buildFields(), |
|
51 | + ]], |
|
52 | + ]; |
|
53 | + $this->notification = apply_filters('site-reviews/slack/compose', $notification, $this); |
|
54 | + return $this; |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * @return WP_Error|array |
|
59 | - */ |
|
60 | - public function send() |
|
61 | - { |
|
62 | - if (empty($this->endpoint)) { |
|
63 | - return new WP_Error('slack', 'Slack notification was not sent: missing endpoint'); |
|
64 | - } |
|
65 | - return wp_remote_post($this->endpoint, [ |
|
66 | - 'blocking' => false, |
|
67 | - 'body' => json_encode($this->notification), |
|
68 | - 'headers' => ['Content-Type' => 'application/json'], |
|
69 | - 'httpversion' => '1.0', |
|
70 | - 'method' => 'POST', |
|
71 | - 'redirection' => 5, |
|
72 | - 'sslverify' => false, |
|
73 | - 'timeout' => 45, |
|
74 | - ]); |
|
75 | - } |
|
57 | + /** |
|
58 | + * @return WP_Error|array |
|
59 | + */ |
|
60 | + public function send() |
|
61 | + { |
|
62 | + if (empty($this->endpoint)) { |
|
63 | + return new WP_Error('slack', 'Slack notification was not sent: missing endpoint'); |
|
64 | + } |
|
65 | + return wp_remote_post($this->endpoint, [ |
|
66 | + 'blocking' => false, |
|
67 | + 'body' => json_encode($this->notification), |
|
68 | + 'headers' => ['Content-Type' => 'application/json'], |
|
69 | + 'httpversion' => '1.0', |
|
70 | + 'method' => 'POST', |
|
71 | + 'redirection' => 5, |
|
72 | + 'sslverify' => false, |
|
73 | + 'timeout' => 45, |
|
74 | + ]); |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * @return array |
|
79 | - */ |
|
80 | - protected function buildAction(array $args) |
|
81 | - { |
|
82 | - return [[ |
|
83 | - 'text' => $args['button_text'], |
|
84 | - 'type' => 'button', |
|
85 | - 'url' => $args['button_url'], |
|
86 | - ]]; |
|
87 | - } |
|
77 | + /** |
|
78 | + * @return array |
|
79 | + */ |
|
80 | + protected function buildAction(array $args) |
|
81 | + { |
|
82 | + return [[ |
|
83 | + 'text' => $args['button_text'], |
|
84 | + 'type' => 'button', |
|
85 | + 'url' => $args['button_url'], |
|
86 | + ]]; |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * @return array |
|
91 | - */ |
|
92 | - protected function buildAuthorField() |
|
93 | - { |
|
94 | - $email = !empty($this->review->email) |
|
95 | - ? '<'.$this->review->email.'>' |
|
96 | - : ''; |
|
97 | - $author = trim(rtrim($this->review->author).' '.$email); |
|
98 | - return ['value' => implode(' - ', array_filter([$author, $this->review->ip_address]))]; |
|
99 | - } |
|
89 | + /** |
|
90 | + * @return array |
|
91 | + */ |
|
92 | + protected function buildAuthorField() |
|
93 | + { |
|
94 | + $email = !empty($this->review->email) |
|
95 | + ? '<'.$this->review->email.'>' |
|
96 | + : ''; |
|
97 | + $author = trim(rtrim($this->review->author).' '.$email); |
|
98 | + return ['value' => implode(' - ', array_filter([$author, $this->review->ip_address]))]; |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * @return array |
|
103 | - */ |
|
104 | - protected function buildContentField() |
|
105 | - { |
|
106 | - return !empty($this->review->content) |
|
107 | - ? ['value' => $this->review->content] |
|
108 | - : []; |
|
109 | - } |
|
101 | + /** |
|
102 | + * @return array |
|
103 | + */ |
|
104 | + protected function buildContentField() |
|
105 | + { |
|
106 | + return !empty($this->review->content) |
|
107 | + ? ['value' => $this->review->content] |
|
108 | + : []; |
|
109 | + } |
|
110 | 110 | |
111 | - /** |
|
112 | - * @return array |
|
113 | - */ |
|
114 | - protected function buildFields() |
|
115 | - { |
|
116 | - $fields = [ |
|
117 | - $this->buildStarsField(), |
|
118 | - $this->buildTitleField(), |
|
119 | - $this->buildContentField(), |
|
120 | - $this->buildAuthorField(), |
|
121 | - ]; |
|
122 | - return array_filter($fields); |
|
123 | - } |
|
111 | + /** |
|
112 | + * @return array |
|
113 | + */ |
|
114 | + protected function buildFields() |
|
115 | + { |
|
116 | + $fields = [ |
|
117 | + $this->buildStarsField(), |
|
118 | + $this->buildTitleField(), |
|
119 | + $this->buildContentField(), |
|
120 | + $this->buildAuthorField(), |
|
121 | + ]; |
|
122 | + return array_filter($fields); |
|
123 | + } |
|
124 | 124 | |
125 | - /** |
|
126 | - * @return array |
|
127 | - */ |
|
128 | - protected function buildStarsField() |
|
129 | - { |
|
130 | - $solidStars = str_repeat('★', $this->review->rating); |
|
131 | - $emptyStars = str_repeat('☆', max(0, glsr()->constant('MAX_RATING', Rating::class) - $this->review->rating)); |
|
132 | - $stars = $solidStars.$emptyStars; |
|
133 | - $stars = apply_filters('site-reviews/slack/stars', $stars, $this->review->rating, glsr()->constant('MAX_RATING', Rating::class)); |
|
134 | - return ['title' => $stars]; |
|
135 | - } |
|
125 | + /** |
|
126 | + * @return array |
|
127 | + */ |
|
128 | + protected function buildStarsField() |
|
129 | + { |
|
130 | + $solidStars = str_repeat('★', $this->review->rating); |
|
131 | + $emptyStars = str_repeat('☆', max(0, glsr()->constant('MAX_RATING', Rating::class) - $this->review->rating)); |
|
132 | + $stars = $solidStars.$emptyStars; |
|
133 | + $stars = apply_filters('site-reviews/slack/stars', $stars, $this->review->rating, glsr()->constant('MAX_RATING', Rating::class)); |
|
134 | + return ['title' => $stars]; |
|
135 | + } |
|
136 | 136 | |
137 | - /** |
|
138 | - * @return array |
|
139 | - */ |
|
140 | - protected function buildTitleField() |
|
141 | - { |
|
142 | - return !empty($this->review->title) |
|
143 | - ? ['title' => $this->review->title] |
|
144 | - : []; |
|
145 | - } |
|
137 | + /** |
|
138 | + * @return array |
|
139 | + */ |
|
140 | + protected function buildTitleField() |
|
141 | + { |
|
142 | + return !empty($this->review->title) |
|
143 | + ? ['title' => $this->review->title] |
|
144 | + : []; |
|
145 | + } |
|
146 | 146 | } |
@@ -4,13 +4,13 @@ |
||
4 | 4 | |
5 | 5 | class Hidden extends Field |
6 | 6 | { |
7 | - /** |
|
8 | - * @return array |
|
9 | - */ |
|
10 | - public static function required() |
|
11 | - { |
|
12 | - return [ |
|
13 | - 'is_raw' => true, |
|
14 | - ]; |
|
15 | - } |
|
7 | + /** |
|
8 | + * @return array |
|
9 | + */ |
|
10 | + public static function required() |
|
11 | + { |
|
12 | + return [ |
|
13 | + 'is_raw' => true, |
|
14 | + ]; |
|
15 | + } |
|
16 | 16 | } |
@@ -4,33 +4,33 @@ |
||
4 | 4 | |
5 | 5 | class Code extends Field |
6 | 6 | { |
7 | - /** |
|
8 | - * @return string|void |
|
9 | - */ |
|
10 | - public function build() |
|
11 | - { |
|
12 | - $this->builder->tag = 'textarea'; |
|
13 | - $this->mergeFieldArgs(); |
|
14 | - return $this->builder->getTag(); |
|
15 | - } |
|
7 | + /** |
|
8 | + * @return string|void |
|
9 | + */ |
|
10 | + public function build() |
|
11 | + { |
|
12 | + $this->builder->tag = 'textarea'; |
|
13 | + $this->mergeFieldArgs(); |
|
14 | + return $this->builder->getTag(); |
|
15 | + } |
|
16 | 16 | |
17 | - /** |
|
18 | - * @return array |
|
19 | - */ |
|
20 | - public static function defaults() |
|
21 | - { |
|
22 | - return [ |
|
23 | - 'class' => 'large-text code', |
|
24 | - ]; |
|
25 | - } |
|
17 | + /** |
|
18 | + * @return array |
|
19 | + */ |
|
20 | + public static function defaults() |
|
21 | + { |
|
22 | + return [ |
|
23 | + 'class' => 'large-text code', |
|
24 | + ]; |
|
25 | + } |
|
26 | 26 | |
27 | - /** |
|
28 | - * @return array |
|
29 | - */ |
|
30 | - public static function required() |
|
31 | - { |
|
32 | - return [ |
|
33 | - 'type' => 'textarea', |
|
34 | - ]; |
|
35 | - } |
|
27 | + /** |
|
28 | + * @return array |
|
29 | + */ |
|
30 | + public static function required() |
|
31 | + { |
|
32 | + return [ |
|
33 | + 'type' => 'textarea', |
|
34 | + ]; |
|
35 | + } |
|
36 | 36 | } |
@@ -4,13 +4,13 @@ |
||
4 | 4 | |
5 | 5 | class Text extends Field |
6 | 6 | { |
7 | - /** |
|
8 | - * @return array |
|
9 | - */ |
|
10 | - public static function defaults() |
|
11 | - { |
|
12 | - return [ |
|
13 | - 'class' => 'regular-text', |
|
14 | - ]; |
|
15 | - } |
|
7 | + /** |
|
8 | + * @return array |
|
9 | + */ |
|
10 | + public static function defaults() |
|
11 | + { |
|
12 | + return [ |
|
13 | + 'class' => 'regular-text', |
|
14 | + ]; |
|
15 | + } |
|
16 | 16 | } |
@@ -4,30 +4,30 @@ |
||
4 | 4 | |
5 | 5 | class Honeypot extends Field |
6 | 6 | { |
7 | - /** |
|
8 | - * @return string|void |
|
9 | - */ |
|
10 | - public function build() |
|
11 | - { |
|
12 | - $this->builder->args = wp_parse_args($this->builder->args, [ |
|
13 | - 'name' => $this->builder->args['text'], |
|
14 | - ]); |
|
15 | - $this->builder->tag = 'input'; |
|
16 | - $this->mergeFieldArgs(); |
|
17 | - return $this->builder->getOpeningTag(); |
|
18 | - } |
|
7 | + /** |
|
8 | + * @return string|void |
|
9 | + */ |
|
10 | + public function build() |
|
11 | + { |
|
12 | + $this->builder->args = wp_parse_args($this->builder->args, [ |
|
13 | + 'name' => $this->builder->args['text'], |
|
14 | + ]); |
|
15 | + $this->builder->tag = 'input'; |
|
16 | + $this->mergeFieldArgs(); |
|
17 | + return $this->builder->getOpeningTag(); |
|
18 | + } |
|
19 | 19 | |
20 | - /** |
|
21 | - * @return array |
|
22 | - */ |
|
23 | - public static function required() |
|
24 | - { |
|
25 | - return [ |
|
26 | - 'autocomplete' => 'off', |
|
27 | - 'is_raw' => true, |
|
28 | - 'style' => 'display:none!important', |
|
29 | - 'tabindex' => '-1', |
|
30 | - 'type' => 'text', |
|
31 | - ]; |
|
32 | - } |
|
20 | + /** |
|
21 | + * @return array |
|
22 | + */ |
|
23 | + public static function required() |
|
24 | + { |
|
25 | + return [ |
|
26 | + 'autocomplete' => 'off', |
|
27 | + 'is_raw' => true, |
|
28 | + 'style' => 'display:none!important', |
|
29 | + 'tabindex' => '-1', |
|
30 | + 'type' => 'text', |
|
31 | + ]; |
|
32 | + } |
|
33 | 33 | } |
@@ -4,38 +4,38 @@ |
||
4 | 4 | |
5 | 5 | class YesNo extends Field |
6 | 6 | { |
7 | - /** |
|
8 | - * @return string|void |
|
9 | - */ |
|
10 | - public function build() |
|
11 | - { |
|
12 | - $this->builder->tag = 'input'; |
|
13 | - $this->mergeFieldArgs(); |
|
14 | - return $this->builder->getTag(); |
|
15 | - } |
|
7 | + /** |
|
8 | + * @return string|void |
|
9 | + */ |
|
10 | + public function build() |
|
11 | + { |
|
12 | + $this->builder->tag = 'input'; |
|
13 | + $this->mergeFieldArgs(); |
|
14 | + return $this->builder->getTag(); |
|
15 | + } |
|
16 | 16 | |
17 | - /** |
|
18 | - * @return array |
|
19 | - */ |
|
20 | - public static function defaults() |
|
21 | - { |
|
22 | - return [ |
|
23 | - 'class' => 'inline', |
|
24 | - ]; |
|
25 | - } |
|
17 | + /** |
|
18 | + * @return array |
|
19 | + */ |
|
20 | + public static function defaults() |
|
21 | + { |
|
22 | + return [ |
|
23 | + 'class' => 'inline', |
|
24 | + ]; |
|
25 | + } |
|
26 | 26 | |
27 | - /** |
|
28 | - * @return array |
|
29 | - */ |
|
30 | - public static function required() |
|
31 | - { |
|
32 | - return [ |
|
33 | - 'is_multi' => true, |
|
34 | - 'options' => [ |
|
35 | - 'no' => __('No', 'site-reviews'), |
|
36 | - 'yes' => __('Yes', 'site-reviews'), |
|
37 | - ], |
|
38 | - 'type' => 'radio', |
|
39 | - ]; |
|
40 | - } |
|
27 | + /** |
|
28 | + * @return array |
|
29 | + */ |
|
30 | + public static function required() |
|
31 | + { |
|
32 | + return [ |
|
33 | + 'is_multi' => true, |
|
34 | + 'options' => [ |
|
35 | + 'no' => __('No', 'site-reviews'), |
|
36 | + 'yes' => __('Yes', 'site-reviews'), |
|
37 | + ], |
|
38 | + 'type' => 'radio', |
|
39 | + ]; |
|
40 | + } |
|
41 | 41 | } |
@@ -4,13 +4,13 @@ |
||
4 | 4 | |
5 | 5 | class Number extends Field |
6 | 6 | { |
7 | - /** |
|
8 | - * @return array |
|
9 | - */ |
|
10 | - public static function defaults() |
|
11 | - { |
|
12 | - return [ |
|
13 | - 'class' => 'small-text', |
|
14 | - ]; |
|
15 | - } |
|
7 | + /** |
|
8 | + * @return array |
|
9 | + */ |
|
10 | + public static function defaults() |
|
11 | + { |
|
12 | + return [ |
|
13 | + 'class' => 'small-text', |
|
14 | + ]; |
|
15 | + } |
|
16 | 16 | } |
@@ -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 | } |