@@ -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"> |
@@ -15,14 +15,20 @@ |
||
| 15 | 15 | <span class="glsr-addon-link button button-secondary" disabled> |
| 16 | 16 | <?= __('Installed', 'site-reviews'); ?> |
| 17 | 17 | </span> |
| 18 | - <?php else: ?> |
|
| 19 | - <a href="<?= wp_nonce_url(self_admin_url('plugins.php?action=activate&plugin='.$plugin), 'activate-plugin_'.$plugin); ?>" class="glsr-addon-link button button-secondary"> |
|
| 18 | + <?php else { |
|
| 19 | + : ?> |
|
| 20 | + <a href="<?= wp_nonce_url(self_admin_url('plugins.php?action=activate&plugin='.$plugin), 'activate-plugin_'.$plugin); |
|
| 21 | +} |
|
| 22 | +?>" class="glsr-addon-link button button-secondary"> |
|
| 20 | 23 | <?= __('Activate', 'site-reviews'); ?> |
| 21 | 24 | </a> |
| 22 | 25 | <?php endif; ?> |
| 23 | - <?php else: ?> |
|
| 26 | + <?php else { |
|
| 27 | + : ?> |
|
| 24 | 28 | <a href="{{ link }}" class="glsr-addon-link glsr-external button button-secondary"> |
| 25 | - <?= __('More Info', 'site-reviews'); ?> |
|
| 29 | + <?= __('More Info', 'site-reviews'); |
|
| 30 | +} |
|
| 31 | +?> |
|
| 26 | 32 | </a> |
| 27 | 33 | <?php endif; ?> |
| 28 | 34 | </div> |
@@ -9,24 +9,24 @@ |
||
| 9 | 9 | <p><?= __('Add-ons extend the functionality of Site Reviews.', 'site-reviews'); ?></p> |
| 10 | 10 | <div class="glsr-addons wp-clearfix"> |
| 11 | 11 | <?php |
| 12 | - $template->render('partials/addons/addon', [ |
|
| 13 | - 'context' => [ |
|
| 14 | - 'description' => __('Allow your visitors to submit multiple images with their reviews.', 'site-reviews'), |
|
| 15 | - 'link' => 'https://niftyplugins.com/addons/site-reviews-images/', |
|
| 16 | - 'slug' => 'images', |
|
| 17 | - 'title' => 'Images', |
|
| 18 | - ], |
|
| 19 | - 'plugin' => 'site-reviews-images/site-reviews-images.php', |
|
| 20 | - ]); |
|
| 21 | - $template->render('partials/addons/addon', [ |
|
| 22 | - 'context' => [ |
|
| 23 | - 'description' => __('Sync your Tripadvisor reviews to your website and manage them with Site Reviews.', 'site-reviews'), |
|
| 24 | - 'link' => 'https://niftyplugins.com/addons/site-reviews-tripadvisor/', |
|
| 25 | - 'slug' => 'tripadvisor', |
|
| 26 | - 'title' => 'Tripadvisor Reviews', |
|
| 27 | - ], |
|
| 28 | - 'plugin' => 'site-reviews-tripadvisor/site-reviews-tripadvisor.php', |
|
| 29 | - ]); |
|
| 30 | - ?> |
|
| 12 | + $template->render('partials/addons/addon', [ |
|
| 13 | + 'context' => [ |
|
| 14 | + 'description' => __('Allow your visitors to submit multiple images with their reviews.', 'site-reviews'), |
|
| 15 | + 'link' => 'https://niftyplugins.com/addons/site-reviews-images/', |
|
| 16 | + 'slug' => 'images', |
|
| 17 | + 'title' => 'Images', |
|
| 18 | + ], |
|
| 19 | + 'plugin' => 'site-reviews-images/site-reviews-images.php', |
|
| 20 | + ]); |
|
| 21 | + $template->render('partials/addons/addon', [ |
|
| 22 | + 'context' => [ |
|
| 23 | + 'description' => __('Sync your Tripadvisor reviews to your website and manage them with Site Reviews.', 'site-reviews'), |
|
| 24 | + 'link' => 'https://niftyplugins.com/addons/site-reviews-tripadvisor/', |
|
| 25 | + 'slug' => 'tripadvisor', |
|
| 26 | + 'title' => 'Tripadvisor Reviews', |
|
| 27 | + ], |
|
| 28 | + 'plugin' => 'site-reviews-tripadvisor/site-reviews-tripadvisor.php', |
|
| 29 | + ]); |
|
| 30 | + ?> |
|
| 31 | 31 | </div> |
| 32 | 32 | </div> |
@@ -6,77 +6,77 @@ |
||
| 6 | 6 | |
| 7 | 7 | class Polylang |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * @param int|string $postId |
|
| 11 | - * @return \WP_Post|void|null |
|
| 12 | - */ |
|
| 13 | - public function getPost($postId) |
|
| 14 | - { |
|
| 15 | - $postId = trim($postId); |
|
| 16 | - if (empty($postId) || !is_numeric($postId)) { |
|
| 17 | - return; |
|
| 18 | - } |
|
| 19 | - if ($this->isEnabled()) { |
|
| 20 | - $polylangPostId = pll_get_post($postId, pll_get_post_language(get_the_ID())); |
|
| 21 | - } |
|
| 22 | - if (!empty($polylangPostId)) { |
|
| 23 | - $postId = $polylangPostId; |
|
| 24 | - } |
|
| 25 | - return get_post(intval($postId)); |
|
| 26 | - } |
|
| 9 | + /** |
|
| 10 | + * @param int|string $postId |
|
| 11 | + * @return \WP_Post|void|null |
|
| 12 | + */ |
|
| 13 | + public function getPost($postId) |
|
| 14 | + { |
|
| 15 | + $postId = trim($postId); |
|
| 16 | + if (empty($postId) || !is_numeric($postId)) { |
|
| 17 | + return; |
|
| 18 | + } |
|
| 19 | + if ($this->isEnabled()) { |
|
| 20 | + $polylangPostId = pll_get_post($postId, pll_get_post_language(get_the_ID())); |
|
| 21 | + } |
|
| 22 | + if (!empty($polylangPostId)) { |
|
| 23 | + $postId = $polylangPostId; |
|
| 24 | + } |
|
| 25 | + return get_post(intval($postId)); |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @return array |
|
| 30 | - */ |
|
| 31 | - public function getPostIds(array $postIds) |
|
| 32 | - { |
|
| 33 | - if (!$this->isEnabled()) { |
|
| 34 | - return $postIds; |
|
| 35 | - } |
|
| 36 | - $newPostIds = []; |
|
| 37 | - foreach ($this->cleanIds($postIds) as $postId) { |
|
| 38 | - $newPostIds = array_merge( |
|
| 39 | - $newPostIds, |
|
| 40 | - array_values(pll_get_post_translations($postId)) |
|
| 41 | - ); |
|
| 42 | - } |
|
| 43 | - return $this->cleanIds($newPostIds); |
|
| 44 | - } |
|
| 28 | + /** |
|
| 29 | + * @return array |
|
| 30 | + */ |
|
| 31 | + public function getPostIds(array $postIds) |
|
| 32 | + { |
|
| 33 | + if (!$this->isEnabled()) { |
|
| 34 | + return $postIds; |
|
| 35 | + } |
|
| 36 | + $newPostIds = []; |
|
| 37 | + foreach ($this->cleanIds($postIds) as $postId) { |
|
| 38 | + $newPostIds = array_merge( |
|
| 39 | + $newPostIds, |
|
| 40 | + array_values(pll_get_post_translations($postId)) |
|
| 41 | + ); |
|
| 42 | + } |
|
| 43 | + return $this->cleanIds($newPostIds); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @return bool |
|
| 48 | - */ |
|
| 49 | - public function isActive() |
|
| 50 | - { |
|
| 51 | - return function_exists('PLL') |
|
| 52 | - && function_exists('pll_get_post') |
|
| 53 | - && function_exists('pll_get_post_language') |
|
| 54 | - && function_exists('pll_get_post_translations'); |
|
| 55 | - } |
|
| 46 | + /** |
|
| 47 | + * @return bool |
|
| 48 | + */ |
|
| 49 | + public function isActive() |
|
| 50 | + { |
|
| 51 | + return function_exists('PLL') |
|
| 52 | + && function_exists('pll_get_post') |
|
| 53 | + && function_exists('pll_get_post_language') |
|
| 54 | + && function_exists('pll_get_post_translations'); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * @return bool |
|
| 59 | - */ |
|
| 60 | - public function isEnabled() |
|
| 61 | - { |
|
| 62 | - return $this->isActive() |
|
| 63 | - && glsr(OptionManager::class)->getBool('settings.general.support.polylang'); |
|
| 64 | - } |
|
| 57 | + /** |
|
| 58 | + * @return bool |
|
| 59 | + */ |
|
| 60 | + public function isEnabled() |
|
| 61 | + { |
|
| 62 | + return $this->isActive() |
|
| 63 | + && glsr(OptionManager::class)->getBool('settings.general.support.polylang'); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * @return bool |
|
| 68 | - */ |
|
| 69 | - public function isSupported() |
|
| 70 | - { |
|
| 71 | - return defined('POLYLANG_VERSION') |
|
| 72 | - && version_compare(POLYLANG_VERSION, '2.3', '>='); |
|
| 73 | - } |
|
| 66 | + /** |
|
| 67 | + * @return bool |
|
| 68 | + */ |
|
| 69 | + public function isSupported() |
|
| 70 | + { |
|
| 71 | + return defined('POLYLANG_VERSION') |
|
| 72 | + && version_compare(POLYLANG_VERSION, '2.3', '>='); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * @return array |
|
| 77 | - */ |
|
| 78 | - protected function cleanIds(array $postIds) |
|
| 79 | - { |
|
| 80 | - return array_filter(array_unique($postIds)); |
|
| 81 | - } |
|
| 75 | + /** |
|
| 76 | + * @return array |
|
| 77 | + */ |
|
| 78 | + protected function cleanIds(array $postIds) |
|
| 79 | + { |
|
| 80 | + return array_filter(array_unique($postIds)); |
|
| 81 | + } |
|
| 82 | 82 | } |
@@ -9,201 +9,201 @@ |
||
| 9 | 9 | |
| 10 | 10 | class Email |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * @var array |
|
| 14 | - */ |
|
| 15 | - public $attachments; |
|
| 16 | - |
|
| 17 | - /** |
|
| 18 | - * @var array |
|
| 19 | - */ |
|
| 20 | - public $email; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * @var array |
|
| 24 | - */ |
|
| 25 | - public $headers; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * @var string |
|
| 29 | - */ |
|
| 30 | - public $message; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * @var string |
|
| 34 | - */ |
|
| 35 | - public $subject; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @var string|array |
|
| 39 | - */ |
|
| 40 | - public $to; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @return Email |
|
| 44 | - */ |
|
| 45 | - public function compose(array $email) |
|
| 46 | - { |
|
| 47 | - $this->normalize($email); |
|
| 48 | - $this->attachments = $this->email['attachments']; |
|
| 49 | - $this->headers = $this->buildHeaders(); |
|
| 50 | - $this->message = $this->buildHtmlMessage(); |
|
| 51 | - $this->subject = $this->email['subject']; |
|
| 52 | - $this->to = $this->email['to']; |
|
| 53 | - add_action('phpmailer_init', [$this, 'buildPlainTextMessage']); |
|
| 54 | - return $this; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @param string $format |
|
| 59 | - * @return string|null |
|
| 60 | - */ |
|
| 61 | - public function read($format = '') |
|
| 62 | - { |
|
| 63 | - if ('plaintext' == $format) { |
|
| 64 | - $message = $this->stripHtmlTags($this->message); |
|
| 65 | - return apply_filters('site-reviews/email/message', $message, 'text', $this); |
|
| 66 | - } |
|
| 67 | - return $this->message; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * @return void|bool |
|
| 72 | - */ |
|
| 73 | - public function send() |
|
| 74 | - { |
|
| 75 | - if (!$this->message || !$this->subject || !$this->to) { |
|
| 76 | - return; |
|
| 77 | - } |
|
| 78 | - add_action('wp_mail_failed', [$this, 'logMailError']); |
|
| 79 | - $sent = wp_mail( |
|
| 80 | - $this->to, |
|
| 81 | - $this->subject, |
|
| 82 | - $this->message, |
|
| 83 | - $this->headers, |
|
| 84 | - $this->attachments |
|
| 85 | - ); |
|
| 86 | - remove_action('wp_mail_failed', [$this, 'logMailError']); |
|
| 87 | - $this->reset(); |
|
| 88 | - return $sent; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * @return void |
|
| 93 | - * @action phpmailer_init |
|
| 94 | - */ |
|
| 95 | - public function buildPlainTextMessage(PHPMailer $phpmailer) |
|
| 96 | - { |
|
| 97 | - if (empty($this->email)) { |
|
| 98 | - return; |
|
| 99 | - } |
|
| 100 | - if ('text/plain' === $phpmailer->ContentType || !empty($phpmailer->AltBody)) { |
|
| 101 | - return; |
|
| 102 | - } |
|
| 103 | - $message = $this->stripHtmlTags($phpmailer->Body); |
|
| 104 | - $phpmailer->AltBody = apply_filters('site-reviews/email/message', $message, 'text', $this); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * @return array |
|
| 109 | - */ |
|
| 110 | - protected function buildHeaders() |
|
| 111 | - { |
|
| 112 | - $allowed = [ |
|
| 113 | - 'bcc', 'cc', 'from', 'reply-to', |
|
| 114 | - ]; |
|
| 115 | - $headers = array_intersect_key($this->email, array_flip($allowed)); |
|
| 116 | - $headers = array_filter($headers); |
|
| 117 | - foreach ($headers as $key => $value) { |
|
| 118 | - unset($headers[$key]); |
|
| 119 | - $headers[] = $key.': '.$value; |
|
| 120 | - } |
|
| 121 | - $headers[] = 'Content-Type: text/html'; |
|
| 122 | - return apply_filters('site-reviews/email/headers', $headers, $this); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * @return string |
|
| 127 | - */ |
|
| 128 | - protected function buildHtmlMessage() |
|
| 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'], [ |
|
| 135 | - 'context' => $this->email['template-tags'], |
|
| 136 | - ]); |
|
| 137 | - } |
|
| 138 | - if (!isset($message)) { |
|
| 139 | - $message = $this->email['message']; |
|
| 140 | - } |
|
| 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', [ |
|
| 148 | - 'context' => ['message' => $message], |
|
| 149 | - ]); |
|
| 150 | - return apply_filters('site-reviews/email/message', stripslashes($message), 'html', $this); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * @param \WP_Error $error |
|
| 155 | - * @return void |
|
| 156 | - */ |
|
| 157 | - protected function logMailError($error) |
|
| 158 | - { |
|
| 159 | - glsr_log()->error('Email was not sent (wp_mail failed)') |
|
| 160 | - ->debug($this) |
|
| 161 | - ->debug($error); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * @return void |
|
| 166 | - */ |
|
| 167 | - protected function normalize(array $email = []) |
|
| 168 | - { |
|
| 169 | - $email = shortcode_atts(glsr(EmailDefaults::class)->defaults(), $email); |
|
| 170 | - if (empty($email['reply-to'])) { |
|
| 171 | - $email['reply-to'] = $email['from']; |
|
| 172 | - } |
|
| 173 | - $this->email = apply_filters('site-reviews/email/compose', $email, $this); |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * @return void |
|
| 178 | - */ |
|
| 179 | - protected function reset() |
|
| 180 | - { |
|
| 181 | - $this->attachments = []; |
|
| 182 | - $this->email = []; |
|
| 183 | - $this->headers = []; |
|
| 184 | - $this->message = null; |
|
| 185 | - $this->subject = null; |
|
| 186 | - $this->to = null; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * @return string |
|
| 191 | - */ |
|
| 192 | - protected function stripHtmlTags($string) |
|
| 193 | - { |
|
| 194 | - // remove invisible elements |
|
| 195 | - $string = preg_replace('@<(embed|head|noembed|noscript|object|script|style)[^>]*?>.*?</\\1>@siu', '', $string); |
|
| 196 | - // replace certain elements with a line-break |
|
| 197 | - $string = preg_replace('@</(div|h[1-9]|p|pre|tr)@iu', "\r\n\$0", $string); |
|
| 198 | - // replace other elements with a space |
|
| 199 | - $string = preg_replace('@</(td|th)@iu', ' $0', $string); |
|
| 200 | - // add a placeholder for plain-text bullets to list elements |
|
| 201 | - $string = preg_replace('@<(li)[^>]*?>@siu', '$0-o-^-o-', $string); |
|
| 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'); |
|
| 208 | - } |
|
| 12 | + /** |
|
| 13 | + * @var array |
|
| 14 | + */ |
|
| 15 | + public $attachments; |
|
| 16 | + |
|
| 17 | + /** |
|
| 18 | + * @var array |
|
| 19 | + */ |
|
| 20 | + public $email; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * @var array |
|
| 24 | + */ |
|
| 25 | + public $headers; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * @var string |
|
| 29 | + */ |
|
| 30 | + public $message; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * @var string |
|
| 34 | + */ |
|
| 35 | + public $subject; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @var string|array |
|
| 39 | + */ |
|
| 40 | + public $to; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @return Email |
|
| 44 | + */ |
|
| 45 | + public function compose(array $email) |
|
| 46 | + { |
|
| 47 | + $this->normalize($email); |
|
| 48 | + $this->attachments = $this->email['attachments']; |
|
| 49 | + $this->headers = $this->buildHeaders(); |
|
| 50 | + $this->message = $this->buildHtmlMessage(); |
|
| 51 | + $this->subject = $this->email['subject']; |
|
| 52 | + $this->to = $this->email['to']; |
|
| 53 | + add_action('phpmailer_init', [$this, 'buildPlainTextMessage']); |
|
| 54 | + return $this; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @param string $format |
|
| 59 | + * @return string|null |
|
| 60 | + */ |
|
| 61 | + public function read($format = '') |
|
| 62 | + { |
|
| 63 | + if ('plaintext' == $format) { |
|
| 64 | + $message = $this->stripHtmlTags($this->message); |
|
| 65 | + return apply_filters('site-reviews/email/message', $message, 'text', $this); |
|
| 66 | + } |
|
| 67 | + return $this->message; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * @return void|bool |
|
| 72 | + */ |
|
| 73 | + public function send() |
|
| 74 | + { |
|
| 75 | + if (!$this->message || !$this->subject || !$this->to) { |
|
| 76 | + return; |
|
| 77 | + } |
|
| 78 | + add_action('wp_mail_failed', [$this, 'logMailError']); |
|
| 79 | + $sent = wp_mail( |
|
| 80 | + $this->to, |
|
| 81 | + $this->subject, |
|
| 82 | + $this->message, |
|
| 83 | + $this->headers, |
|
| 84 | + $this->attachments |
|
| 85 | + ); |
|
| 86 | + remove_action('wp_mail_failed', [$this, 'logMailError']); |
|
| 87 | + $this->reset(); |
|
| 88 | + return $sent; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * @return void |
|
| 93 | + * @action phpmailer_init |
|
| 94 | + */ |
|
| 95 | + public function buildPlainTextMessage(PHPMailer $phpmailer) |
|
| 96 | + { |
|
| 97 | + if (empty($this->email)) { |
|
| 98 | + return; |
|
| 99 | + } |
|
| 100 | + if ('text/plain' === $phpmailer->ContentType || !empty($phpmailer->AltBody)) { |
|
| 101 | + return; |
|
| 102 | + } |
|
| 103 | + $message = $this->stripHtmlTags($phpmailer->Body); |
|
| 104 | + $phpmailer->AltBody = apply_filters('site-reviews/email/message', $message, 'text', $this); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * @return array |
|
| 109 | + */ |
|
| 110 | + protected function buildHeaders() |
|
| 111 | + { |
|
| 112 | + $allowed = [ |
|
| 113 | + 'bcc', 'cc', 'from', 'reply-to', |
|
| 114 | + ]; |
|
| 115 | + $headers = array_intersect_key($this->email, array_flip($allowed)); |
|
| 116 | + $headers = array_filter($headers); |
|
| 117 | + foreach ($headers as $key => $value) { |
|
| 118 | + unset($headers[$key]); |
|
| 119 | + $headers[] = $key.': '.$value; |
|
| 120 | + } |
|
| 121 | + $headers[] = 'Content-Type: text/html'; |
|
| 122 | + return apply_filters('site-reviews/email/headers', $headers, $this); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * @return string |
|
| 127 | + */ |
|
| 128 | + protected function buildHtmlMessage() |
|
| 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'], [ |
|
| 135 | + 'context' => $this->email['template-tags'], |
|
| 136 | + ]); |
|
| 137 | + } |
|
| 138 | + if (!isset($message)) { |
|
| 139 | + $message = $this->email['message']; |
|
| 140 | + } |
|
| 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', [ |
|
| 148 | + 'context' => ['message' => $message], |
|
| 149 | + ]); |
|
| 150 | + return apply_filters('site-reviews/email/message', stripslashes($message), 'html', $this); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * @param \WP_Error $error |
|
| 155 | + * @return void |
|
| 156 | + */ |
|
| 157 | + protected function logMailError($error) |
|
| 158 | + { |
|
| 159 | + glsr_log()->error('Email was not sent (wp_mail failed)') |
|
| 160 | + ->debug($this) |
|
| 161 | + ->debug($error); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * @return void |
|
| 166 | + */ |
|
| 167 | + protected function normalize(array $email = []) |
|
| 168 | + { |
|
| 169 | + $email = shortcode_atts(glsr(EmailDefaults::class)->defaults(), $email); |
|
| 170 | + if (empty($email['reply-to'])) { |
|
| 171 | + $email['reply-to'] = $email['from']; |
|
| 172 | + } |
|
| 173 | + $this->email = apply_filters('site-reviews/email/compose', $email, $this); |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * @return void |
|
| 178 | + */ |
|
| 179 | + protected function reset() |
|
| 180 | + { |
|
| 181 | + $this->attachments = []; |
|
| 182 | + $this->email = []; |
|
| 183 | + $this->headers = []; |
|
| 184 | + $this->message = null; |
|
| 185 | + $this->subject = null; |
|
| 186 | + $this->to = null; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * @return string |
|
| 191 | + */ |
|
| 192 | + protected function stripHtmlTags($string) |
|
| 193 | + { |
|
| 194 | + // remove invisible elements |
|
| 195 | + $string = preg_replace('@<(embed|head|noembed|noscript|object|script|style)[^>]*?>.*?</\\1>@siu', '', $string); |
|
| 196 | + // replace certain elements with a line-break |
|
| 197 | + $string = preg_replace('@</(div|h[1-9]|p|pre|tr)@iu', "\r\n\$0", $string); |
|
| 198 | + // replace other elements with a space |
|
| 199 | + $string = preg_replace('@</(td|th)@iu', ' $0', $string); |
|
| 200 | + // add a placeholder for plain-text bullets to list elements |
|
| 201 | + $string = preg_replace('@<(li)[^>]*?>@siu', '$0-o-^-o-', $string); |
|
| 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'); |
|
| 208 | + } |
|
| 209 | 209 | } |
@@ -130,7 +130,8 @@ |
||
| 130 | 130 | $template = trim(glsr(OptionManager::class)->get('settings.general.notification_message')); |
| 131 | 131 | if (!empty($template)) { |
| 132 | 132 | $message = glsr(Template::class)->interpolate($template, $this->email['template-tags'], $this->email['template']); |
| 133 | - } elseif ($this->email['template']) { |
|
| 133 | + } |
|
| 134 | + elseif ($this->email['template']) { |
|
| 134 | 135 | $message = glsr(Template::class)->build('templates/'.$this->email['template'], [ |
| 135 | 136 | 'context' => $this->email['template-tags'], |
| 136 | 137 | ]); |
@@ -8,160 +8,160 @@ |
||
| 8 | 8 | |
| 9 | 9 | class Upgrade_3_0_0 |
| 10 | 10 | { |
| 11 | - const MAPPED_SETTINGS = [ |
|
| 12 | - 'settings.general.notification' => 'settings.general.notifications', // array |
|
| 13 | - 'settings.general.notification_email' => 'settings.general.notification_email', |
|
| 14 | - 'settings.general.notification_message' => 'settings.general.notification_message', |
|
| 15 | - 'settings.general.require.approval' => 'settings.general.require.approval', |
|
| 16 | - 'settings.general.require.login' => 'settings.general.require.login', |
|
| 17 | - 'settings.general.require.login_register' => 'settings.general.require.login_register', |
|
| 18 | - 'settings.general.webhook_url' => 'settings.general.notification_slack', |
|
| 19 | - 'settings.reviews-form.akismet' => 'settings.submissions.akismet', |
|
| 20 | - 'settings.reviews-form.blacklist.action' => 'settings.submissions.blacklist.action', |
|
| 21 | - 'settings.reviews-form.blacklist.entries' => 'settings.submissions.blacklist.entries', |
|
| 22 | - 'settings.reviews-form.recaptcha.integration' => 'settings.submissions.recaptcha.integration', |
|
| 23 | - 'settings.reviews-form.recaptcha.key' => 'settings.submissions.recaptcha.key', |
|
| 24 | - 'settings.reviews-form.recaptcha.position' => 'settings.submissions.recaptcha.position', |
|
| 25 | - 'settings.reviews-form.recaptcha.secret' => 'settings.submissions.recaptcha.secret', |
|
| 26 | - 'settings.reviews-form.required' => 'settings.submissions.required', // array |
|
| 27 | - 'settings.reviews.assigned_links.enabled' => 'settings.reviews.assigned_links', |
|
| 28 | - 'settings.reviews.avatars.enabled' => 'settings.reviews.avatars', |
|
| 29 | - 'settings.reviews.date.custom' => 'settings.reviews.date.custom', |
|
| 30 | - 'settings.reviews.date.format' => 'settings.reviews.date.format', |
|
| 31 | - 'settings.reviews.excerpt.enabled' => 'settings.reviews.excerpts', |
|
| 32 | - 'settings.reviews.excerpt.length' => 'settings.reviews.excerpts_length', |
|
| 33 | - 'settings.reviews.schema.address' => 'settings.schema.address', |
|
| 34 | - 'settings.reviews.schema.description.custom' => 'settings.schema.description.custom', |
|
| 35 | - 'settings.reviews.schema.description.default' => 'settings.schema.description.default', |
|
| 36 | - 'settings.reviews.schema.highprice' => 'settings.schema.highprice', |
|
| 37 | - 'settings.reviews.schema.image.custom' => 'settings.schema.image.custom', |
|
| 38 | - 'settings.reviews.schema.image.default' => 'settings.schema.image.default', |
|
| 39 | - 'settings.reviews.schema.lowprice' => 'settings.schema.lowprice', |
|
| 40 | - 'settings.reviews.schema.name.custom' => 'settings.schema.name.custom', |
|
| 41 | - 'settings.reviews.schema.name.default' => 'settings.schema.name.default', |
|
| 42 | - 'settings.reviews.schema.pricecurrency' => 'settings.schema.pricecurrency', |
|
| 43 | - 'settings.reviews.schema.pricerange' => 'settings.schema.pricerange', |
|
| 44 | - 'settings.reviews.schema.telephone' => 'settings.schema.telephone', |
|
| 45 | - 'settings.reviews.schema.type.custom' => 'settings.schema.type.custom', |
|
| 46 | - 'settings.reviews.schema.type.default' => 'settings.schema.type.default', |
|
| 47 | - 'settings.reviews.schema.url.custom' => 'settings.schema.url.custom', |
|
| 48 | - 'settings.reviews.schema.url.default' => 'settings.schema.url.default', |
|
| 49 | - 'version' => 'version_upgraded_from', |
|
| 50 | - ]; |
|
| 11 | + const MAPPED_SETTINGS = [ |
|
| 12 | + 'settings.general.notification' => 'settings.general.notifications', // array |
|
| 13 | + 'settings.general.notification_email' => 'settings.general.notification_email', |
|
| 14 | + 'settings.general.notification_message' => 'settings.general.notification_message', |
|
| 15 | + 'settings.general.require.approval' => 'settings.general.require.approval', |
|
| 16 | + 'settings.general.require.login' => 'settings.general.require.login', |
|
| 17 | + 'settings.general.require.login_register' => 'settings.general.require.login_register', |
|
| 18 | + 'settings.general.webhook_url' => 'settings.general.notification_slack', |
|
| 19 | + 'settings.reviews-form.akismet' => 'settings.submissions.akismet', |
|
| 20 | + 'settings.reviews-form.blacklist.action' => 'settings.submissions.blacklist.action', |
|
| 21 | + 'settings.reviews-form.blacklist.entries' => 'settings.submissions.blacklist.entries', |
|
| 22 | + 'settings.reviews-form.recaptcha.integration' => 'settings.submissions.recaptcha.integration', |
|
| 23 | + 'settings.reviews-form.recaptcha.key' => 'settings.submissions.recaptcha.key', |
|
| 24 | + 'settings.reviews-form.recaptcha.position' => 'settings.submissions.recaptcha.position', |
|
| 25 | + 'settings.reviews-form.recaptcha.secret' => 'settings.submissions.recaptcha.secret', |
|
| 26 | + 'settings.reviews-form.required' => 'settings.submissions.required', // array |
|
| 27 | + 'settings.reviews.assigned_links.enabled' => 'settings.reviews.assigned_links', |
|
| 28 | + 'settings.reviews.avatars.enabled' => 'settings.reviews.avatars', |
|
| 29 | + 'settings.reviews.date.custom' => 'settings.reviews.date.custom', |
|
| 30 | + 'settings.reviews.date.format' => 'settings.reviews.date.format', |
|
| 31 | + 'settings.reviews.excerpt.enabled' => 'settings.reviews.excerpts', |
|
| 32 | + 'settings.reviews.excerpt.length' => 'settings.reviews.excerpts_length', |
|
| 33 | + 'settings.reviews.schema.address' => 'settings.schema.address', |
|
| 34 | + 'settings.reviews.schema.description.custom' => 'settings.schema.description.custom', |
|
| 35 | + 'settings.reviews.schema.description.default' => 'settings.schema.description.default', |
|
| 36 | + 'settings.reviews.schema.highprice' => 'settings.schema.highprice', |
|
| 37 | + 'settings.reviews.schema.image.custom' => 'settings.schema.image.custom', |
|
| 38 | + 'settings.reviews.schema.image.default' => 'settings.schema.image.default', |
|
| 39 | + 'settings.reviews.schema.lowprice' => 'settings.schema.lowprice', |
|
| 40 | + 'settings.reviews.schema.name.custom' => 'settings.schema.name.custom', |
|
| 41 | + 'settings.reviews.schema.name.default' => 'settings.schema.name.default', |
|
| 42 | + 'settings.reviews.schema.pricecurrency' => 'settings.schema.pricecurrency', |
|
| 43 | + 'settings.reviews.schema.pricerange' => 'settings.schema.pricerange', |
|
| 44 | + 'settings.reviews.schema.telephone' => 'settings.schema.telephone', |
|
| 45 | + 'settings.reviews.schema.type.custom' => 'settings.schema.type.custom', |
|
| 46 | + 'settings.reviews.schema.type.default' => 'settings.schema.type.default', |
|
| 47 | + 'settings.reviews.schema.url.custom' => 'settings.schema.url.custom', |
|
| 48 | + 'settings.reviews.schema.url.default' => 'settings.schema.url.default', |
|
| 49 | + 'version' => 'version_upgraded_from', |
|
| 50 | + ]; |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @var array |
|
| 54 | - */ |
|
| 55 | - protected $newSettings; |
|
| 52 | + /** |
|
| 53 | + * @var array |
|
| 54 | + */ |
|
| 55 | + protected $newSettings; |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * @var array |
|
| 59 | - */ |
|
| 60 | - protected $oldSettings; |
|
| 57 | + /** |
|
| 58 | + * @var array |
|
| 59 | + */ |
|
| 60 | + protected $oldSettings; |
|
| 61 | 61 | |
| 62 | - public function __construct() |
|
| 63 | - { |
|
| 64 | - $this->migrateSettings(); |
|
| 65 | - } |
|
| 62 | + public function __construct() |
|
| 63 | + { |
|
| 64 | + $this->migrateSettings(); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * @return void |
|
| 69 | - */ |
|
| 70 | - public function migrateSettings() |
|
| 71 | - { |
|
| 72 | - $this->newSettings = $this->getNewSettings(); |
|
| 73 | - $this->oldSettings = $this->getOldSettings(); |
|
| 74 | - if (empty($this->oldSettings)) { |
|
| 75 | - return; |
|
| 76 | - } |
|
| 77 | - foreach (static::MAPPED_SETTINGS as $old => $new) { |
|
| 78 | - if (empty($this->oldSettings[$old])) { |
|
| 79 | - continue; |
|
| 80 | - } |
|
| 81 | - $this->newSettings[$new] = $this->oldSettings[$old]; |
|
| 82 | - } |
|
| 83 | - $this->migrateNotificationSettings(); |
|
| 84 | - $this->migrateRecaptchaSettings(); |
|
| 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'])) { |
|
| 89 | - $newSettings['settings']['strings'] = $oldSettings['settings']['strings']; |
|
| 90 | - } |
|
| 91 | - glsr(OptionManager::class)->set($newSettings); |
|
| 92 | - } |
|
| 67 | + /** |
|
| 68 | + * @return void |
|
| 69 | + */ |
|
| 70 | + public function migrateSettings() |
|
| 71 | + { |
|
| 72 | + $this->newSettings = $this->getNewSettings(); |
|
| 73 | + $this->oldSettings = $this->getOldSettings(); |
|
| 74 | + if (empty($this->oldSettings)) { |
|
| 75 | + return; |
|
| 76 | + } |
|
| 77 | + foreach (static::MAPPED_SETTINGS as $old => $new) { |
|
| 78 | + if (empty($this->oldSettings[$old])) { |
|
| 79 | + continue; |
|
| 80 | + } |
|
| 81 | + $this->newSettings[$new] = $this->oldSettings[$old]; |
|
| 82 | + } |
|
| 83 | + $this->migrateNotificationSettings(); |
|
| 84 | + $this->migrateRecaptchaSettings(); |
|
| 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'])) { |
|
| 89 | + $newSettings['settings']['strings'] = $oldSettings['settings']['strings']; |
|
| 90 | + } |
|
| 91 | + glsr(OptionManager::class)->set($newSettings); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * @return array |
|
| 96 | - */ |
|
| 97 | - protected function getNewSettings() |
|
| 98 | - { |
|
| 99 | - return wp_parse_args( |
|
| 100 | - glsr(Helper::class)->flattenArray(glsr(OptionManager::class)->all()), |
|
| 101 | - glsr(DefaultsManager::class)->defaults() |
|
| 102 | - ); |
|
| 103 | - } |
|
| 94 | + /** |
|
| 95 | + * @return array |
|
| 96 | + */ |
|
| 97 | + protected function getNewSettings() |
|
| 98 | + { |
|
| 99 | + return wp_parse_args( |
|
| 100 | + glsr(Helper::class)->flattenArray(glsr(OptionManager::class)->all()), |
|
| 101 | + glsr(DefaultsManager::class)->defaults() |
|
| 102 | + ); |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * @return array |
|
| 107 | - */ |
|
| 108 | - protected function getOldSettings() |
|
| 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); |
|
| 114 | - } |
|
| 115 | - return $settings; |
|
| 116 | - } |
|
| 105 | + /** |
|
| 106 | + * @return array |
|
| 107 | + */ |
|
| 108 | + protected function getOldSettings() |
|
| 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); |
|
| 114 | + } |
|
| 115 | + return $settings; |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - /** |
|
| 119 | - * @return void |
|
| 120 | - */ |
|
| 121 | - protected function migrateNotificationSettings() |
|
| 122 | - { |
|
| 123 | - $notifications = [ |
|
| 124 | - 'custom' => 'custom', |
|
| 125 | - 'default' => 'admin', |
|
| 126 | - 'webhook' => 'slack', |
|
| 127 | - ]; |
|
| 128 | - $this->newSettings['settings.general.notifications'] = []; |
|
| 129 | - foreach ($notifications as $old => $new) { |
|
| 130 | - if ($this->oldSettings['settings.general.notification'] != $old) { |
|
| 131 | - continue; |
|
| 132 | - } |
|
| 133 | - $this->newSettings['settings.general.notifications'][] = $new; |
|
| 134 | - } |
|
| 135 | - } |
|
| 118 | + /** |
|
| 119 | + * @return void |
|
| 120 | + */ |
|
| 121 | + protected function migrateNotificationSettings() |
|
| 122 | + { |
|
| 123 | + $notifications = [ |
|
| 124 | + 'custom' => 'custom', |
|
| 125 | + 'default' => 'admin', |
|
| 126 | + 'webhook' => 'slack', |
|
| 127 | + ]; |
|
| 128 | + $this->newSettings['settings.general.notifications'] = []; |
|
| 129 | + foreach ($notifications as $old => $new) { |
|
| 130 | + if ($this->oldSettings['settings.general.notification'] != $old) { |
|
| 131 | + continue; |
|
| 132 | + } |
|
| 133 | + $this->newSettings['settings.general.notifications'][] = $new; |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | - /** |
|
| 138 | - * @return void |
|
| 139 | - */ |
|
| 140 | - protected function migrateRecaptchaSettings() |
|
| 141 | - { |
|
| 142 | - $recaptcha = [ |
|
| 143 | - 'BadgePosition' => $this->oldSettings['settings.reviews-form.recaptcha.position'], |
|
| 144 | - 'SecretKey' => $this->oldSettings['settings.reviews-form.recaptcha.secret'], |
|
| 145 | - 'SiteKey' => $this->oldSettings['settings.reviews-form.recaptcha.key'], |
|
| 146 | - ]; |
|
| 147 | - if (in_array($this->oldSettings['settings.reviews-form.recaptcha.integration'], ['custom', 'invisible-recaptcha'])) { |
|
| 148 | - $this->newSettings['settings.submissions.recaptcha.integration'] = 'all'; |
|
| 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); |
|
| 152 | - } |
|
| 153 | - $this->newSettings['settings.submissions.recaptcha.key'] = $recaptcha['SiteKey']; |
|
| 154 | - $this->newSettings['settings.submissions.recaptcha.secret'] = $recaptcha['SecretKey']; |
|
| 155 | - $this->newSettings['settings.submissions.recaptcha.position'] = $recaptcha['BadgePosition']; |
|
| 156 | - } |
|
| 137 | + /** |
|
| 138 | + * @return void |
|
| 139 | + */ |
|
| 140 | + protected function migrateRecaptchaSettings() |
|
| 141 | + { |
|
| 142 | + $recaptcha = [ |
|
| 143 | + 'BadgePosition' => $this->oldSettings['settings.reviews-form.recaptcha.position'], |
|
| 144 | + 'SecretKey' => $this->oldSettings['settings.reviews-form.recaptcha.secret'], |
|
| 145 | + 'SiteKey' => $this->oldSettings['settings.reviews-form.recaptcha.key'], |
|
| 146 | + ]; |
|
| 147 | + if (in_array($this->oldSettings['settings.reviews-form.recaptcha.integration'], ['custom', 'invisible-recaptcha'])) { |
|
| 148 | + $this->newSettings['settings.submissions.recaptcha.integration'] = 'all'; |
|
| 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); |
|
| 152 | + } |
|
| 153 | + $this->newSettings['settings.submissions.recaptcha.key'] = $recaptcha['SiteKey']; |
|
| 154 | + $this->newSettings['settings.submissions.recaptcha.secret'] = $recaptcha['SecretKey']; |
|
| 155 | + $this->newSettings['settings.submissions.recaptcha.position'] = $recaptcha['BadgePosition']; |
|
| 156 | + } |
|
| 157 | 157 | |
| 158 | - /** |
|
| 159 | - * @return void |
|
| 160 | - */ |
|
| 161 | - protected function migrateRequiredSettings() |
|
| 162 | - { |
|
| 163 | - $this->newSettings['settings.submissions.required'] = array_filter((array) $this->oldSettings['settings.reviews-form.required']); |
|
| 164 | - $this->newSettings['settings.submissions.required'][] = 'rating'; |
|
| 165 | - $this->newSettings['settings.submissions.required'][] = 'terms'; |
|
| 166 | - } |
|
| 158 | + /** |
|
| 159 | + * @return void |
|
| 160 | + */ |
|
| 161 | + protected function migrateRequiredSettings() |
|
| 162 | + { |
|
| 163 | + $this->newSettings['settings.submissions.required'] = array_filter((array) $this->oldSettings['settings.reviews-form.required']); |
|
| 164 | + $this->newSettings['settings.submissions.required'][] = 'rating'; |
|
| 165 | + $this->newSettings['settings.submissions.required'][] = 'terms'; |
|
| 166 | + } |
|
| 167 | 167 | } |
@@ -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,49 +4,49 @@ |
||
| 4 | 4 | |
| 5 | 5 | class Date |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * [60, 1], |
|
| 9 | - * [60 * 100, 60], |
|
| 10 | - * [3600 * 70, 3600], |
|
| 11 | - * [3600 * 24 * 10, 3600 * 24], |
|
| 12 | - * [3600 * 24 * 30, 3600 * 24 * 7], |
|
| 13 | - * [3600 * 24 * 30 * 30, 3600 * 24 * 30], |
|
| 14 | - * [INF, 3600 * 24 * 265],. |
|
| 15 | - */ |
|
| 16 | - protected static $TIME_PERIODS = [ |
|
| 17 | - [60, 1], |
|
| 18 | - [6000, 60], |
|
| 19 | - [252000, 3600], |
|
| 20 | - [864000, 86400], |
|
| 21 | - [2592000, 604800], |
|
| 22 | - [77760000, 2592000], |
|
| 23 | - [INF, 22896000], |
|
| 24 | - ]; |
|
| 7 | + /** |
|
| 8 | + * [60, 1], |
|
| 9 | + * [60 * 100, 60], |
|
| 10 | + * [3600 * 70, 3600], |
|
| 11 | + * [3600 * 24 * 10, 3600 * 24], |
|
| 12 | + * [3600 * 24 * 30, 3600 * 24 * 7], |
|
| 13 | + * [3600 * 24 * 30 * 30, 3600 * 24 * 30], |
|
| 14 | + * [INF, 3600 * 24 * 265],. |
|
| 15 | + */ |
|
| 16 | + protected static $TIME_PERIODS = [ |
|
| 17 | + [60, 1], |
|
| 18 | + [6000, 60], |
|
| 19 | + [252000, 3600], |
|
| 20 | + [864000, 86400], |
|
| 21 | + [2592000, 604800], |
|
| 22 | + [77760000, 2592000], |
|
| 23 | + [INF, 22896000], |
|
| 24 | + ]; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @return string |
|
| 28 | - */ |
|
| 29 | - public function relative($date) |
|
| 30 | - { |
|
| 31 | - $diff = time() - strtotime($date); |
|
| 32 | - foreach (static::$TIME_PERIODS as $i => $timePeriod) { |
|
| 33 | - if ($diff > $timePeriod[0]) { |
|
| 34 | - continue; |
|
| 35 | - } |
|
| 36 | - $unit = intval(floor($diff / $timePeriod[1])); |
|
| 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'), |
|
| 45 | - ]; |
|
| 46 | - $relativeDate = $relativeDates[$i]; |
|
| 47 | - return false !== strpos($relativeDate, '%s') |
|
| 48 | - ? sprintf($relativeDate, $unit) |
|
| 49 | - : $relativeDate; |
|
| 50 | - } |
|
| 51 | - } |
|
| 26 | + /** |
|
| 27 | + * @return string |
|
| 28 | + */ |
|
| 29 | + public function relative($date) |
|
| 30 | + { |
|
| 31 | + $diff = time() - strtotime($date); |
|
| 32 | + foreach (static::$TIME_PERIODS as $i => $timePeriod) { |
|
| 33 | + if ($diff > $timePeriod[0]) { |
|
| 34 | + continue; |
|
| 35 | + } |
|
| 36 | + $unit = intval(floor($diff / $timePeriod[1])); |
|
| 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'), |
|
| 45 | + ]; |
|
| 46 | + $relativeDate = $relativeDates[$i]; |
|
| 47 | + return false !== strpos($relativeDate, '%s') |
|
| 48 | + ? sprintf($relativeDate, $unit) |
|
| 49 | + : $relativeDate; |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | 52 | } |
@@ -6,151 +6,151 @@ |
||
| 6 | 6 | |
| 7 | 7 | class Translator |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * @param string $translation |
|
| 11 | - * @param string $text |
|
| 12 | - * @param string $domain |
|
| 13 | - * @return string |
|
| 14 | - */ |
|
| 15 | - public function filterGettext($translation, $text, $domain) |
|
| 16 | - { |
|
| 17 | - return $this->translate($translation, $domain, [ |
|
| 18 | - 'single' => $text, |
|
| 19 | - ]); |
|
| 20 | - } |
|
| 9 | + /** |
|
| 10 | + * @param string $translation |
|
| 11 | + * @param string $text |
|
| 12 | + * @param string $domain |
|
| 13 | + * @return string |
|
| 14 | + */ |
|
| 15 | + public function filterGettext($translation, $text, $domain) |
|
| 16 | + { |
|
| 17 | + return $this->translate($translation, $domain, [ |
|
| 18 | + 'single' => $text, |
|
| 19 | + ]); |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @param string $translation |
|
| 24 | - * @param string $text |
|
| 25 | - * @param string $context |
|
| 26 | - * @param string $domain |
|
| 27 | - * @return string |
|
| 28 | - */ |
|
| 29 | - public function filterGettextWithContext($translation, $text, $context, $domain) |
|
| 30 | - { |
|
| 31 | - return $this->translate($translation, $domain, [ |
|
| 32 | - 'context' => $context, |
|
| 33 | - 'single' => $text, |
|
| 34 | - ]); |
|
| 35 | - } |
|
| 22 | + /** |
|
| 23 | + * @param string $translation |
|
| 24 | + * @param string $text |
|
| 25 | + * @param string $context |
|
| 26 | + * @param string $domain |
|
| 27 | + * @return string |
|
| 28 | + */ |
|
| 29 | + public function filterGettextWithContext($translation, $text, $context, $domain) |
|
| 30 | + { |
|
| 31 | + return $this->translate($translation, $domain, [ |
|
| 32 | + 'context' => $context, |
|
| 33 | + 'single' => $text, |
|
| 34 | + ]); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @param string $translation |
|
| 39 | - * @param string $single |
|
| 40 | - * @param string $plural |
|
| 41 | - * @param int $number |
|
| 42 | - * @param string $domain |
|
| 43 | - * @return string |
|
| 44 | - */ |
|
| 45 | - public function filterNgettext($translation, $single, $plural, $number, $domain) |
|
| 46 | - { |
|
| 47 | - return $this->translate($translation, $domain, [ |
|
| 48 | - 'number' => $number, |
|
| 49 | - 'plural' => $plural, |
|
| 50 | - 'single' => $single, |
|
| 51 | - ]); |
|
| 52 | - } |
|
| 37 | + /** |
|
| 38 | + * @param string $translation |
|
| 39 | + * @param string $single |
|
| 40 | + * @param string $plural |
|
| 41 | + * @param int $number |
|
| 42 | + * @param string $domain |
|
| 43 | + * @return string |
|
| 44 | + */ |
|
| 45 | + public function filterNgettext($translation, $single, $plural, $number, $domain) |
|
| 46 | + { |
|
| 47 | + return $this->translate($translation, $domain, [ |
|
| 48 | + 'number' => $number, |
|
| 49 | + 'plural' => $plural, |
|
| 50 | + 'single' => $single, |
|
| 51 | + ]); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @param string $translation |
|
| 56 | - * @param string $single |
|
| 57 | - * @param string $plural |
|
| 58 | - * @param int $number |
|
| 59 | - * @param string $context |
|
| 60 | - * @param string $domain |
|
| 61 | - * @return string |
|
| 62 | - */ |
|
| 63 | - public function filterNgettextWithContext($translation, $single, $plural, $number, $context, $domain) |
|
| 64 | - { |
|
| 65 | - return $this->translate($translation, $domain, [ |
|
| 66 | - 'context' => $context, |
|
| 67 | - 'number' => $number, |
|
| 68 | - 'plural' => $plural, |
|
| 69 | - 'single' => $single, |
|
| 70 | - ]); |
|
| 71 | - } |
|
| 54 | + /** |
|
| 55 | + * @param string $translation |
|
| 56 | + * @param string $single |
|
| 57 | + * @param string $plural |
|
| 58 | + * @param int $number |
|
| 59 | + * @param string $context |
|
| 60 | + * @param string $domain |
|
| 61 | + * @return string |
|
| 62 | + */ |
|
| 63 | + public function filterNgettextWithContext($translation, $single, $plural, $number, $context, $domain) |
|
| 64 | + { |
|
| 65 | + return $this->translate($translation, $domain, [ |
|
| 66 | + 'context' => $context, |
|
| 67 | + 'number' => $number, |
|
| 68 | + 'plural' => $plural, |
|
| 69 | + 'single' => $single, |
|
| 70 | + ]); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * @param string $original |
|
| 75 | - * @param string $domain |
|
| 76 | - * @return string |
|
| 77 | - */ |
|
| 78 | - public function translate($original, $domain, array $args) |
|
| 79 | - { |
|
| 80 | - $domains = apply_filters('site-reviews/translator/domains', [Application::ID]); |
|
| 81 | - if (!in_array($domain, $domains)) { |
|
| 82 | - return $original; |
|
| 83 | - } |
|
| 84 | - $args = $this->normalizeTranslationArgs($args); |
|
| 85 | - $strings = $this->getTranslationStrings($args['single'], $args['plural']); |
|
| 86 | - if (empty($strings)) { |
|
| 87 | - return $original; |
|
| 88 | - } |
|
| 89 | - $string = current($strings); |
|
| 90 | - return 'plural' == $string['type'] |
|
| 91 | - ? $this->translatePlural($domain, $string, $args) |
|
| 92 | - : $this->translateSingle($domain, $string, $args); |
|
| 93 | - } |
|
| 73 | + /** |
|
| 74 | + * @param string $original |
|
| 75 | + * @param string $domain |
|
| 76 | + * @return string |
|
| 77 | + */ |
|
| 78 | + public function translate($original, $domain, array $args) |
|
| 79 | + { |
|
| 80 | + $domains = apply_filters('site-reviews/translator/domains', [Application::ID]); |
|
| 81 | + if (!in_array($domain, $domains)) { |
|
| 82 | + return $original; |
|
| 83 | + } |
|
| 84 | + $args = $this->normalizeTranslationArgs($args); |
|
| 85 | + $strings = $this->getTranslationStrings($args['single'], $args['plural']); |
|
| 86 | + if (empty($strings)) { |
|
| 87 | + return $original; |
|
| 88 | + } |
|
| 89 | + $string = current($strings); |
|
| 90 | + return 'plural' == $string['type'] |
|
| 91 | + ? $this->translatePlural($domain, $string, $args) |
|
| 92 | + : $this->translateSingle($domain, $string, $args); |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * @param string $single |
|
| 97 | - * @param string $plural |
|
| 98 | - * @return array |
|
| 99 | - */ |
|
| 100 | - protected function getTranslationStrings($single, $plural) |
|
| 101 | - { |
|
| 102 | - return array_filter(glsr(Translation::class)->translations(), function ($string) use ($single, $plural) { |
|
| 103 | - return $string['s1'] == html_entity_decode($single, ENT_COMPAT, 'UTF-8') |
|
| 104 | - && $string['p1'] == html_entity_decode($plural, ENT_COMPAT, 'UTF-8'); |
|
| 105 | - }); |
|
| 106 | - } |
|
| 95 | + /** |
|
| 96 | + * @param string $single |
|
| 97 | + * @param string $plural |
|
| 98 | + * @return array |
|
| 99 | + */ |
|
| 100 | + protected function getTranslationStrings($single, $plural) |
|
| 101 | + { |
|
| 102 | + return array_filter(glsr(Translation::class)->translations(), function ($string) use ($single, $plural) { |
|
| 103 | + return $string['s1'] == html_entity_decode($single, ENT_COMPAT, 'UTF-8') |
|
| 104 | + && $string['p1'] == html_entity_decode($plural, ENT_COMPAT, 'UTF-8'); |
|
| 105 | + }); |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * @return array |
|
| 110 | - */ |
|
| 111 | - protected function normalizeTranslationArgs(array $args) |
|
| 112 | - { |
|
| 113 | - $defaults = [ |
|
| 114 | - 'context' => '', |
|
| 115 | - 'number' => 1, |
|
| 116 | - 'plural' => '', |
|
| 117 | - 'single' => '', |
|
| 118 | - ]; |
|
| 119 | - return shortcode_atts($defaults, $args); |
|
| 120 | - } |
|
| 108 | + /** |
|
| 109 | + * @return array |
|
| 110 | + */ |
|
| 111 | + protected function normalizeTranslationArgs(array $args) |
|
| 112 | + { |
|
| 113 | + $defaults = [ |
|
| 114 | + 'context' => '', |
|
| 115 | + 'number' => 1, |
|
| 116 | + 'plural' => '', |
|
| 117 | + 'single' => '', |
|
| 118 | + ]; |
|
| 119 | + return shortcode_atts($defaults, $args); |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * @param string $domain |
|
| 124 | - * @return string |
|
| 125 | - */ |
|
| 126 | - protected function translatePlural($domain, array $string, array $args) |
|
| 127 | - { |
|
| 128 | - if (!empty($string['s2'])) { |
|
| 129 | - $args['single'] = $string['s2']; |
|
| 130 | - } |
|
| 131 | - if (!empty($string['p2'])) { |
|
| 132 | - $args['plural'] = $string['p2']; |
|
| 133 | - } |
|
| 134 | - return get_translations_for_domain($domain)->translate_plural( |
|
| 135 | - $args['single'], |
|
| 136 | - $args['plural'], |
|
| 137 | - $args['number'], |
|
| 138 | - $args['context'] |
|
| 139 | - ); |
|
| 140 | - } |
|
| 122 | + /** |
|
| 123 | + * @param string $domain |
|
| 124 | + * @return string |
|
| 125 | + */ |
|
| 126 | + protected function translatePlural($domain, array $string, array $args) |
|
| 127 | + { |
|
| 128 | + if (!empty($string['s2'])) { |
|
| 129 | + $args['single'] = $string['s2']; |
|
| 130 | + } |
|
| 131 | + if (!empty($string['p2'])) { |
|
| 132 | + $args['plural'] = $string['p2']; |
|
| 133 | + } |
|
| 134 | + return get_translations_for_domain($domain)->translate_plural( |
|
| 135 | + $args['single'], |
|
| 136 | + $args['plural'], |
|
| 137 | + $args['number'], |
|
| 138 | + $args['context'] |
|
| 139 | + ); |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | - /** |
|
| 143 | - * @param string $domain |
|
| 144 | - * @return string |
|
| 145 | - */ |
|
| 146 | - protected function translateSingle($domain, array $string, array $args) |
|
| 147 | - { |
|
| 148 | - if (!empty($string['s2'])) { |
|
| 149 | - $args['single'] = $string['s2']; |
|
| 150 | - } |
|
| 151 | - return get_translations_for_domain($domain)->translate( |
|
| 152 | - $args['single'], |
|
| 153 | - $args['context'] |
|
| 154 | - ); |
|
| 155 | - } |
|
| 142 | + /** |
|
| 143 | + * @param string $domain |
|
| 144 | + * @return string |
|
| 145 | + */ |
|
| 146 | + protected function translateSingle($domain, array $string, array $args) |
|
| 147 | + { |
|
| 148 | + if (!empty($string['s2'])) { |
|
| 149 | + $args['single'] = $string['s2']; |
|
| 150 | + } |
|
| 151 | + return get_translations_for_domain($domain)->translate( |
|
| 152 | + $args['single'], |
|
| 153 | + $args['context'] |
|
| 154 | + ); |
|
| 155 | + } |
|
| 156 | 156 | } |