@@ -1,4 +1,4 @@ |
||
1 | -<?php defined('WPINC') || die; ?> |
|
1 | +<?php defined( 'WPINC' ) || die; ?> |
|
2 | 2 | |
3 | 3 | <div class="glsr-field {{ class }}"> |
4 | 4 | {{ label }} |
@@ -1,4 +1,4 @@ |
||
1 | -<?php defined('WPINC') || die; ?> |
|
1 | +<?php defined( 'WPINC' ) || die; ?> |
|
2 | 2 | |
3 | 3 | <div class="pagination"> |
4 | 4 | <nav class="navigation" role="navigation"> |
@@ -1,4 +1,4 @@ |
||
1 | -<?php defined('WPINC') || die; ?> |
|
1 | +<?php defined( 'WPINC' ) || die; ?> |
|
2 | 2 | |
3 | 3 | <strong>A new {review_rating}-star review has been submitted:</strong> |
4 | 4 |
@@ -1,4 +1,4 @@ |
||
1 | -<?php defined('WPINC') || die; ?> |
|
1 | +<?php defined( 'WPINC' ) || die; ?> |
|
2 | 2 | |
3 | 3 | <div class="glsr-login-register"> |
4 | 4 | <p>{{ text }}</p> |
@@ -1,4 +1,4 @@ |
||
1 | -<?php defined('WPINC') || die; ?> |
|
1 | +<?php defined( 'WPINC' ) || die; ?> |
|
2 | 2 | |
3 | 3 | <div class="glsr-reviews-wrap"> |
4 | 4 | <div class="{{ class }}" id="{{ id }}"> |
@@ -42,15 +42,15 @@ discard block |
||
42 | 42 | /** |
43 | 43 | * @return Email |
44 | 44 | */ |
45 | - public function compose(array $email) |
|
45 | + public function compose( array $email ) |
|
46 | 46 | { |
47 | - $this->normalize($email); |
|
47 | + $this->normalize( $email ); |
|
48 | 48 | $this->attachments = $this->email['attachments']; |
49 | 49 | $this->headers = $this->buildHeaders(); |
50 | 50 | $this->message = $this->buildHtmlMessage(); |
51 | 51 | $this->subject = $this->email['subject']; |
52 | 52 | $this->to = $this->email['to']; |
53 | - add_action('phpmailer_init', [$this, 'buildPlainTextMessage']); |
|
53 | + add_action( 'phpmailer_init', [$this, 'buildPlainTextMessage'] ); |
|
54 | 54 | return $this; |
55 | 55 | } |
56 | 56 | |
@@ -58,11 +58,11 @@ discard block |
||
58 | 58 | * @param string $format |
59 | 59 | * @return string|null |
60 | 60 | */ |
61 | - public function read($format = '') |
|
61 | + public function read( $format = '' ) |
|
62 | 62 | { |
63 | - if ('plaintext' == $format) { |
|
64 | - $message = $this->stripHtmlTags($this->message); |
|
65 | - return apply_filters('site-reviews/email/message', $message, 'text', $this); |
|
63 | + if( 'plaintext' == $format ) { |
|
64 | + $message = $this->stripHtmlTags( $this->message ); |
|
65 | + return apply_filters( 'site-reviews/email/message', $message, 'text', $this ); |
|
66 | 66 | } |
67 | 67 | return $this->message; |
68 | 68 | } |
@@ -72,10 +72,10 @@ discard block |
||
72 | 72 | */ |
73 | 73 | public function send() |
74 | 74 | { |
75 | - if (!$this->message || !$this->subject || !$this->to) { |
|
75 | + if( !$this->message || !$this->subject || !$this->to ) { |
|
76 | 76 | return; |
77 | 77 | } |
78 | - add_action('wp_mail_failed', [$this, 'logMailError']); |
|
78 | + add_action( 'wp_mail_failed', [$this, 'logMailError'] ); |
|
79 | 79 | $sent = wp_mail( |
80 | 80 | $this->to, |
81 | 81 | $this->subject, |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | $this->headers, |
84 | 84 | $this->attachments |
85 | 85 | ); |
86 | - remove_action('wp_mail_failed', [$this, 'logMailError']); |
|
86 | + remove_action( 'wp_mail_failed', [$this, 'logMailError'] ); |
|
87 | 87 | $this->reset(); |
88 | 88 | return $sent; |
89 | 89 | } |
@@ -92,16 +92,16 @@ discard block |
||
92 | 92 | * @return void |
93 | 93 | * @action phpmailer_init |
94 | 94 | */ |
95 | - public function buildPlainTextMessage(PHPMailer $phpmailer) |
|
95 | + public function buildPlainTextMessage( PHPMailer $phpmailer ) |
|
96 | 96 | { |
97 | - if (empty($this->email)) { |
|
97 | + if( empty($this->email) ) { |
|
98 | 98 | return; |
99 | 99 | } |
100 | - if ('text/plain' === $phpmailer->ContentType || !empty($phpmailer->AltBody)) { |
|
100 | + if( 'text/plain' === $phpmailer->ContentType || !empty($phpmailer->AltBody) ) { |
|
101 | 101 | return; |
102 | 102 | } |
103 | - $message = $this->stripHtmlTags($phpmailer->Body); |
|
104 | - $phpmailer->AltBody = apply_filters('site-reviews/email/message', $message, 'text', $this); |
|
103 | + $message = $this->stripHtmlTags( $phpmailer->Body ); |
|
104 | + $phpmailer->AltBody = apply_filters( 'site-reviews/email/message', $message, 'text', $this ); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
@@ -112,14 +112,14 @@ discard block |
||
112 | 112 | $allowed = [ |
113 | 113 | 'bcc', 'cc', 'from', 'reply-to', |
114 | 114 | ]; |
115 | - $headers = array_intersect_key($this->email, array_flip($allowed)); |
|
116 | - $headers = array_filter($headers); |
|
117 | - foreach ($headers as $key => $value) { |
|
115 | + $headers = array_intersect_key( $this->email, array_flip( $allowed ) ); |
|
116 | + $headers = array_filter( $headers ); |
|
117 | + foreach( $headers as $key => $value ) { |
|
118 | 118 | unset($headers[$key]); |
119 | 119 | $headers[] = $key.': '.$value; |
120 | 120 | } |
121 | 121 | $headers[] = 'Content-Type: text/html'; |
122 | - return apply_filters('site-reviews/email/headers', $headers, $this); |
|
122 | + return apply_filters( 'site-reviews/email/headers', $headers, $this ); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
@@ -127,50 +127,50 @@ discard block |
||
127 | 127 | */ |
128 | 128 | protected function buildHtmlMessage() |
129 | 129 | { |
130 | - $template = trim(glsr(OptionManager::class)->get('settings.general.notification_message')); |
|
131 | - if (!empty($template)) { |
|
132 | - $message = glsr(Template::class)->interpolate($template, $this->email['template-tags'], $this->email['template']); |
|
133 | - } elseif ($this->email['template']) { |
|
134 | - $message = glsr(Template::class)->build('templates/'.$this->email['template'], [ |
|
130 | + $template = trim( glsr( OptionManager::class )->get( 'settings.general.notification_message' ) ); |
|
131 | + if( !empty($template) ) { |
|
132 | + $message = glsr( Template::class )->interpolate( $template, $this->email['template-tags'], $this->email['template'] ); |
|
133 | + } elseif( $this->email['template'] ) { |
|
134 | + $message = glsr( Template::class )->build( 'templates/'.$this->email['template'], [ |
|
135 | 135 | 'context' => $this->email['template-tags'], |
136 | - ]); |
|
136 | + ] ); |
|
137 | 137 | } |
138 | - if (!isset($message)) { |
|
138 | + if( !isset($message) ) { |
|
139 | 139 | $message = $this->email['message']; |
140 | 140 | } |
141 | 141 | $message = $this->email['before'].$message.$this->email['after']; |
142 | - $message = strip_shortcodes($message); |
|
143 | - $message = wptexturize($message); |
|
144 | - $message = wpautop($message); |
|
145 | - $message = str_replace('<> ', '', $message); |
|
146 | - $message = str_replace(']]>', ']]>', $message); |
|
147 | - $message = glsr(Template::class)->build('partials/email/index', [ |
|
142 | + $message = strip_shortcodes( $message ); |
|
143 | + $message = wptexturize( $message ); |
|
144 | + $message = wpautop( $message ); |
|
145 | + $message = str_replace( '<> ', '', $message ); |
|
146 | + $message = str_replace( ']]>', ']]>', $message ); |
|
147 | + $message = glsr( Template::class )->build( 'partials/email/index', [ |
|
148 | 148 | 'context' => ['message' => $message], |
149 | - ]); |
|
150 | - return apply_filters('site-reviews/email/message', stripslashes($message), 'html', $this); |
|
149 | + ] ); |
|
150 | + return apply_filters( 'site-reviews/email/message', stripslashes( $message ), 'html', $this ); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | /** |
154 | 154 | * @param \WP_Error $error |
155 | 155 | * @return void |
156 | 156 | */ |
157 | - protected function logMailError($error) |
|
157 | + protected function logMailError( $error ) |
|
158 | 158 | { |
159 | - glsr_log()->error('Email was not sent (wp_mail failed)') |
|
160 | - ->debug($this) |
|
161 | - ->debug($error); |
|
159 | + glsr_log()->error( 'Email was not sent (wp_mail failed)' ) |
|
160 | + ->debug( $this ) |
|
161 | + ->debug( $error ); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
165 | 165 | * @return void |
166 | 166 | */ |
167 | - protected function normalize(array $email = []) |
|
167 | + protected function normalize( array $email = [] ) |
|
168 | 168 | { |
169 | - $email = shortcode_atts(glsr(EmailDefaults::class)->defaults(), $email); |
|
170 | - if (empty($email['reply-to'])) { |
|
169 | + $email = shortcode_atts( glsr( EmailDefaults::class )->defaults(), $email ); |
|
170 | + if( empty($email['reply-to']) ) { |
|
171 | 171 | $email['reply-to'] = $email['from']; |
172 | 172 | } |
173 | - $this->email = apply_filters('site-reviews/email/compose', $email, $this); |
|
173 | + $this->email = apply_filters( 'site-reviews/email/compose', $email, $this ); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | /** |
@@ -189,21 +189,21 @@ discard block |
||
189 | 189 | /** |
190 | 190 | * @return string |
191 | 191 | */ |
192 | - protected function stripHtmlTags($string) |
|
192 | + protected function stripHtmlTags( $string ) |
|
193 | 193 | { |
194 | 194 | // remove invisible elements |
195 | - $string = preg_replace('@<(embed|head|noembed|noscript|object|script|style)[^>]*?>.*?</\\1>@siu', '', $string); |
|
195 | + $string = preg_replace( '@<(embed|head|noembed|noscript|object|script|style)[^>]*?>.*?</\\1>@siu', '', $string ); |
|
196 | 196 | // replace certain elements with a line-break |
197 | - $string = preg_replace('@</(div|h[1-9]|p|pre|tr)@iu', "\r\n\$0", $string); |
|
197 | + $string = preg_replace( '@</(div|h[1-9]|p|pre|tr)@iu', "\r\n\$0", $string ); |
|
198 | 198 | // replace other elements with a space |
199 | - $string = preg_replace('@</(td|th)@iu', ' $0', $string); |
|
199 | + $string = preg_replace( '@</(td|th)@iu', ' $0', $string ); |
|
200 | 200 | // add a placeholder for plain-text bullets to list elements |
201 | - $string = preg_replace('@<(li)[^>]*?>@siu', '$0-o-^-o-', $string); |
|
201 | + $string = preg_replace( '@<(li)[^>]*?>@siu', '$0-o-^-o-', $string ); |
|
202 | 202 | // strip all remaining HTML tags |
203 | - $string = wp_strip_all_tags($string); |
|
204 | - $string = wp_specialchars_decode($string, ENT_QUOTES); |
|
205 | - $string = preg_replace('/\v(?:[\v\h]+){2,}/', "\r\n\r\n", $string); |
|
206 | - $string = str_replace('-o-^-o-', ' - ', $string); |
|
207 | - return html_entity_decode($string, ENT_QUOTES, 'UTF-8'); |
|
203 | + $string = wp_strip_all_tags( $string ); |
|
204 | + $string = wp_specialchars_decode( $string, ENT_QUOTES ); |
|
205 | + $string = preg_replace( '/\v(?:[\v\h]+){2,}/', "\r\n\r\n", $string ); |
|
206 | + $string = str_replace( '-o-^-o-', ' - ', $string ); |
|
207 | + return html_entity_decode( $string, ENT_QUOTES, 'UTF-8' ); |
|
208 | 208 | } |
209 | 209 | } |
@@ -71,11 +71,11 @@ discard block |
||
71 | 71 | { |
72 | 72 | $this->newSettings = $this->getNewSettings(); |
73 | 73 | $this->oldSettings = $this->getOldSettings(); |
74 | - if (empty($this->oldSettings)) { |
|
74 | + if( empty($this->oldSettings) ) { |
|
75 | 75 | return; |
76 | 76 | } |
77 | - foreach (static::MAPPED_SETTINGS as $old => $new) { |
|
78 | - if (empty($this->oldSettings[$old])) { |
|
77 | + foreach( static::MAPPED_SETTINGS as $old => $new ) { |
|
78 | + if( empty($this->oldSettings[$old]) ) { |
|
79 | 79 | continue; |
80 | 80 | } |
81 | 81 | $this->newSettings[$new] = $this->oldSettings[$old]; |
@@ -83,12 +83,12 @@ discard block |
||
83 | 83 | $this->migrateNotificationSettings(); |
84 | 84 | $this->migrateRecaptchaSettings(); |
85 | 85 | $this->migrateRequiredSettings(); |
86 | - $oldSettings = glsr(Helper::class)->convertDotNotationArray($this->oldSettings); |
|
87 | - $newSettings = glsr(Helper::class)->convertDotNotationArray($this->newSettings); |
|
88 | - if (isset($oldSettings['settings']['strings']) && is_array($oldSettings['settings']['strings'])) { |
|
86 | + $oldSettings = glsr( Helper::class )->convertDotNotationArray( $this->oldSettings ); |
|
87 | + $newSettings = glsr( Helper::class )->convertDotNotationArray( $this->newSettings ); |
|
88 | + if( isset($oldSettings['settings']['strings']) && is_array( $oldSettings['settings']['strings'] ) ) { |
|
89 | 89 | $newSettings['settings']['strings'] = $oldSettings['settings']['strings']; |
90 | 90 | } |
91 | - glsr(OptionManager::class)->set($newSettings); |
|
91 | + glsr( OptionManager::class )->set( $newSettings ); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
@@ -97,8 +97,8 @@ discard block |
||
97 | 97 | protected function getNewSettings() |
98 | 98 | { |
99 | 99 | return wp_parse_args( |
100 | - glsr(Helper::class)->flattenArray(glsr(OptionManager::class)->all()), |
|
101 | - glsr(DefaultsManager::class)->defaults() |
|
100 | + glsr( Helper::class )->flattenArray( glsr( OptionManager::class )->all() ), |
|
101 | + glsr( DefaultsManager::class )->defaults() |
|
102 | 102 | ); |
103 | 103 | } |
104 | 104 | |
@@ -107,10 +107,10 @@ discard block |
||
107 | 107 | */ |
108 | 108 | protected function getOldSettings() |
109 | 109 | { |
110 | - $defaults = array_fill_keys(array_keys(static::MAPPED_SETTINGS), ''); |
|
111 | - $settings = glsr(Helper::class)->flattenArray(get_option('geminilabs_site_reviews-v2', [])); |
|
112 | - if (!empty($settings)) { |
|
113 | - $settings = wp_parse_args($settings, $defaults); |
|
110 | + $defaults = array_fill_keys( array_keys( static::MAPPED_SETTINGS ), '' ); |
|
111 | + $settings = glsr( Helper::class )->flattenArray( get_option( 'geminilabs_site_reviews-v2', [] ) ); |
|
112 | + if( !empty($settings) ) { |
|
113 | + $settings = wp_parse_args( $settings, $defaults ); |
|
114 | 114 | } |
115 | 115 | return $settings; |
116 | 116 | } |
@@ -126,8 +126,8 @@ discard block |
||
126 | 126 | 'webhook' => 'slack', |
127 | 127 | ]; |
128 | 128 | $this->newSettings['settings.general.notifications'] = []; |
129 | - foreach ($notifications as $old => $new) { |
|
130 | - if ($this->oldSettings['settings.general.notification'] != $old) { |
|
129 | + foreach( $notifications as $old => $new ) { |
|
130 | + if( $this->oldSettings['settings.general.notification'] != $old ) { |
|
131 | 131 | continue; |
132 | 132 | } |
133 | 133 | $this->newSettings['settings.general.notifications'][] = $new; |
@@ -144,11 +144,11 @@ discard block |
||
144 | 144 | 'SecretKey' => $this->oldSettings['settings.reviews-form.recaptcha.secret'], |
145 | 145 | 'SiteKey' => $this->oldSettings['settings.reviews-form.recaptcha.key'], |
146 | 146 | ]; |
147 | - if (in_array($this->oldSettings['settings.reviews-form.recaptcha.integration'], ['custom', 'invisible-recaptcha'])) { |
|
147 | + if( in_array( $this->oldSettings['settings.reviews-form.recaptcha.integration'], ['custom', 'invisible-recaptcha'] ) ) { |
|
148 | 148 | $this->newSettings['settings.submissions.recaptcha.integration'] = 'all'; |
149 | 149 | } |
150 | - if ('invisible-recaptcha' == $this->oldSettings['settings.reviews-form.recaptcha.integration']) { |
|
151 | - $recaptcha = wp_parse_args((array) get_site_option('ic-settings', [], false), $recaptcha); |
|
150 | + if( 'invisible-recaptcha' == $this->oldSettings['settings.reviews-form.recaptcha.integration'] ) { |
|
151 | + $recaptcha = wp_parse_args( (array)get_site_option( 'ic-settings', [], false ), $recaptcha ); |
|
152 | 152 | } |
153 | 153 | $this->newSettings['settings.submissions.recaptcha.key'] = $recaptcha['SiteKey']; |
154 | 154 | $this->newSettings['settings.submissions.recaptcha.secret'] = $recaptcha['SecretKey']; |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | */ |
161 | 161 | protected function migrateRequiredSettings() |
162 | 162 | { |
163 | - $this->newSettings['settings.submissions.required'] = array_filter((array) $this->oldSettings['settings.reviews-form.required']); |
|
163 | + $this->newSettings['settings.submissions.required'] = array_filter( (array)$this->oldSettings['settings.reviews-form.required'] ); |
|
164 | 164 | $this->newSettings['settings.submissions.required'][] = 'rating'; |
165 | 165 | $this->newSettings['settings.submissions.required'][] = 'terms'; |
166 | 166 | } |
@@ -26,31 +26,31 @@ discard block |
||
26 | 26 | |
27 | 27 | public function __construct() |
28 | 28 | { |
29 | - $this->endpoint = glsr(OptionManager::class)->get('settings.general.notification_slack'); |
|
29 | + $this->endpoint = glsr( OptionManager::class )->get( 'settings.general.notification_slack' ); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
33 | 33 | * @return Slack |
34 | 34 | */ |
35 | - public function compose(Review $review, array $notification) |
|
35 | + public function compose( Review $review, array $notification ) |
|
36 | 36 | { |
37 | - if (empty($this->endpoint)) { |
|
37 | + if( empty($this->endpoint) ) { |
|
38 | 38 | return $this; |
39 | 39 | } |
40 | - $args = shortcode_atts(glsr(SlackDefaults::class)->defaults(), $notification); |
|
40 | + $args = shortcode_atts( glsr( SlackDefaults::class )->defaults(), $notification ); |
|
41 | 41 | $this->review = $review; |
42 | 42 | $notification = [ |
43 | 43 | 'icon_url' => $args['icon_url'], |
44 | 44 | 'username' => $args['username'], |
45 | 45 | 'attachments' => [[ |
46 | - 'actions' => $this->buildAction($args), |
|
46 | + 'actions' => $this->buildAction( $args ), |
|
47 | 47 | 'pretext' => $args['pretext'], |
48 | 48 | 'color' => $args['color'], |
49 | 49 | 'fallback' => $args['fallback'], |
50 | 50 | 'fields' => $this->buildFields(), |
51 | 51 | ]], |
52 | 52 | ]; |
53 | - $this->notification = apply_filters('site-reviews/slack/compose', $notification, $this); |
|
53 | + $this->notification = apply_filters( 'site-reviews/slack/compose', $notification, $this ); |
|
54 | 54 | return $this; |
55 | 55 | } |
56 | 56 | |
@@ -59,25 +59,25 @@ discard block |
||
59 | 59 | */ |
60 | 60 | public function send() |
61 | 61 | { |
62 | - if (empty($this->endpoint)) { |
|
63 | - return new WP_Error('slack', 'Slack notification was not sent: missing endpoint'); |
|
62 | + if( empty($this->endpoint) ) { |
|
63 | + return new WP_Error( 'slack', 'Slack notification was not sent: missing endpoint' ); |
|
64 | 64 | } |
65 | - return wp_remote_post($this->endpoint, [ |
|
65 | + return wp_remote_post( $this->endpoint, [ |
|
66 | 66 | 'blocking' => false, |
67 | - 'body' => json_encode($this->notification), |
|
67 | + 'body' => json_encode( $this->notification ), |
|
68 | 68 | 'headers' => ['Content-Type' => 'application/json'], |
69 | 69 | 'httpversion' => '1.0', |
70 | 70 | 'method' => 'POST', |
71 | 71 | 'redirection' => 5, |
72 | 72 | 'sslverify' => false, |
73 | 73 | 'timeout' => 45, |
74 | - ]); |
|
74 | + ] ); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | /** |
78 | 78 | * @return array |
79 | 79 | */ |
80 | - protected function buildAction(array $args) |
|
80 | + protected function buildAction( array $args ) |
|
81 | 81 | { |
82 | 82 | return [[ |
83 | 83 | 'text' => $args['button_text'], |
@@ -94,8 +94,8 @@ discard block |
||
94 | 94 | $email = !empty($this->review->email) |
95 | 95 | ? '<'.$this->review->email.'>' |
96 | 96 | : ''; |
97 | - $author = trim(rtrim($this->review->author).' '.$email); |
|
98 | - return ['value' => implode(' - ', array_filter([$author, $this->review->ip_address]))]; |
|
97 | + $author = trim( rtrim( $this->review->author ).' '.$email ); |
|
98 | + return ['value' => implode( ' - ', array_filter( [$author, $this->review->ip_address] ) )]; |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | $this->buildContentField(), |
120 | 120 | $this->buildAuthorField(), |
121 | 121 | ]; |
122 | - return array_filter($fields); |
|
122 | + return array_filter( $fields ); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
@@ -127,10 +127,10 @@ discard block |
||
127 | 127 | */ |
128 | 128 | protected function buildStarsField() |
129 | 129 | { |
130 | - $solidStars = str_repeat('★', $this->review->rating); |
|
131 | - $emptyStars = str_repeat('☆', max(0, glsr()->constant('MAX_RATING', Rating::class) - $this->review->rating)); |
|
130 | + $solidStars = str_repeat( '★', $this->review->rating ); |
|
131 | + $emptyStars = str_repeat( '☆', max( 0, glsr()->constant( 'MAX_RATING', Rating::class ) - $this->review->rating ) ); |
|
132 | 132 | $stars = $solidStars.$emptyStars; |
133 | - $stars = apply_filters('site-reviews/slack/stars', $stars, $this->review->rating, glsr()->constant('MAX_RATING', Rating::class)); |
|
133 | + $stars = apply_filters( 'site-reviews/slack/stars', $stars, $this->review->rating, glsr()->constant( 'MAX_RATING', Rating::class ) ); |
|
134 | 134 | return ['title' => $stars]; |
135 | 135 | } |
136 | 136 |
@@ -26,26 +26,26 @@ |
||
26 | 26 | /** |
27 | 27 | * @return string |
28 | 28 | */ |
29 | - public function relative($date) |
|
29 | + public function relative( $date ) |
|
30 | 30 | { |
31 | - $diff = time() - strtotime($date); |
|
32 | - foreach (static::$TIME_PERIODS as $i => $timePeriod) { |
|
33 | - if ($diff > $timePeriod[0]) { |
|
31 | + $diff = time() - strtotime( $date ); |
|
32 | + foreach( static::$TIME_PERIODS as $i => $timePeriod ) { |
|
33 | + if( $diff > $timePeriod[0] ) { |
|
34 | 34 | continue; |
35 | 35 | } |
36 | - $unit = intval(floor($diff / $timePeriod[1])); |
|
36 | + $unit = intval( floor( $diff / $timePeriod[1] ) ); |
|
37 | 37 | $relativeDates = [ |
38 | - _n('%s second ago', '%s seconds ago', $unit, 'site-reviews'), |
|
39 | - _n('%s minute ago', '%s minutes ago', $unit, 'site-reviews'), |
|
40 | - _n('an hour ago', '%s hours ago', $unit, 'site-reviews'), |
|
41 | - _n('yesterday', '%s days ago', $unit, 'site-reviews'), |
|
42 | - _n('a week ago', '%s weeks ago', $unit, 'site-reviews'), |
|
43 | - _n('%s month ago', '%s months ago', $unit, 'site-reviews'), |
|
44 | - _n('%s year ago', '%s years ago', $unit, 'site-reviews'), |
|
38 | + _n( '%s second ago', '%s seconds ago', $unit, 'site-reviews' ), |
|
39 | + _n( '%s minute ago', '%s minutes ago', $unit, 'site-reviews' ), |
|
40 | + _n( 'an hour ago', '%s hours ago', $unit, 'site-reviews' ), |
|
41 | + _n( 'yesterday', '%s days ago', $unit, 'site-reviews' ), |
|
42 | + _n( 'a week ago', '%s weeks ago', $unit, 'site-reviews' ), |
|
43 | + _n( '%s month ago', '%s months ago', $unit, 'site-reviews' ), |
|
44 | + _n( '%s year ago', '%s years ago', $unit, 'site-reviews' ), |
|
45 | 45 | ]; |
46 | 46 | $relativeDate = $relativeDates[$i]; |
47 | - return false !== strpos($relativeDate, '%s') |
|
48 | - ? sprintf($relativeDate, $unit) |
|
47 | + return false !== strpos( $relativeDate, '%s' ) |
|
48 | + ? sprintf( $relativeDate, $unit ) |
|
49 | 49 | : $relativeDate; |
50 | 50 | } |
51 | 51 | } |