@@ -1,10 +1,10 @@ |
||
| 1 | 1 | <div class="notice is-dismissible glsr-notice" data-dismiss="trustalyze"> |
| 2 | 2 | <div class="glsr-notice-icon"> |
| 3 | - <img width="96" height="96" src="<?= glsr()->url('assets/images/trustalyze-badge.png'); ?>"> |
|
| 3 | + <img width="96" height="96" src="<?= glsr()->url( 'assets/images/trustalyze-badge.png' ); ?>"> |
|
| 4 | 4 | </div> |
| 5 | 5 | <div class="glsr-notice-content"> |
| 6 | 6 | <h3>Validate Your Reviews on the Blockchain With the Trustalyze Confidence System</h3> |
| 7 | 7 | <p>Site Reviews integrates with the <a href="https://trustalyze.com/plans?ref=105">Trustalyze Confidence System</a>, a service which uses blockchain technology to verify to your visitors and customers that your reviews are authentic.</p> |
| 8 | - <a href="<?= admin_url('edit.php?post_type='.glsr()->post_type.'&page=settings#tab-general'); ?>" class="button">Enable the integration</a> |
|
| 8 | + <a href="<?= admin_url( 'edit.php?post_type='.glsr()->post_type.'&page=settings#tab-general' ); ?>" class="button">Enable the integration</a> |
|
| 9 | 9 | </div> |
| 10 | 10 | </div> |
@@ -12,210 +12,210 @@ |
||
| 12 | 12 | |
| 13 | 13 | class TrustalyzeController extends Controller |
| 14 | 14 | { |
| 15 | - protected $apiKey = 'settings.general.trustalyze_serial'; |
|
| 16 | - protected $emailKey = 'settings.general.trustalyze_email'; |
|
| 17 | - protected $enabledKey = 'settings.general.trustalyze'; |
|
| 18 | - protected $trustalyzeKey = '_glsr_trustalyze'; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * @return array |
|
| 22 | - * @filter site-reviews/settings/callback |
|
| 23 | - */ |
|
| 24 | - public function filterSettingsCallback(array $settings) |
|
| 25 | - { |
|
| 26 | - if ('yes' !== Arr::get($settings, $this->enabledKey)) { |
|
| 27 | - return $settings; |
|
| 28 | - } |
|
| 29 | - $isApiKeyModified = $this->isEmptyOrModified($this->apiKey, $settings); |
|
| 30 | - $isEmailModified = $this->isEmptyOrModified($this->emailKey, $settings); |
|
| 31 | - $isAccountVerified = glsr(OptionManager::class)->getWP($this->trustalyzeKey, false); |
|
| 32 | - if (!$isAccountVerified || $isApiKeyModified || $isEmailModified) { |
|
| 33 | - $settings = $this->sanitizeTrustalyzeSettings($settings); |
|
| 34 | - } |
|
| 35 | - return $settings; |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @param string $template |
|
| 40 | - * @return array |
|
| 41 | - * @filter site-reviews/interpolate/partials/form/table-row-multiple |
|
| 42 | - */ |
|
| 43 | - public function filterSettingsTableRow(array $context, $template, array $data) |
|
| 44 | - { |
|
| 45 | - if ($this->enabledKey !== Arr::get($data, 'field.path')) { |
|
| 46 | - return $context; |
|
| 47 | - } |
|
| 48 | - $isAccountValidated = !empty(glsr(OptionManager::class)->getWP($this->trustalyzeKey)); |
|
| 49 | - $isIntegrationEnabled = glsr(OptionManager::class)->getBool('settings.general.trustalyze'); |
|
| 50 | - if ($isAccountValidated && $isIntegrationEnabled) { |
|
| 51 | - return $context; |
|
| 52 | - } |
|
| 53 | - $context['field'].= $this->buildCreateButton(); |
|
| 54 | - return $context; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Triggered when a review is created. |
|
| 59 | - * @return void |
|
| 60 | - * @action site-reviews/review/created |
|
| 61 | - */ |
|
| 62 | - public function onCreated(Review $review) |
|
| 63 | - { |
|
| 64 | - if (!$this->canPostReview($review)) { |
|
| 65 | - return; |
|
| 66 | - } |
|
| 67 | - $trustalyze = glsr(Trustalyze::class)->sendReview($review); |
|
| 68 | - if ($trustalyze->success) { |
|
| 69 | - glsr(Database::class)->set($review->ID, 'trustalyze', $trustalyze->review_id); |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * Triggered when a review is reverted to its original title/content/date_timestamp. |
|
| 75 | - * @return void |
|
| 76 | - * @action site-reviews/review/reverted |
|
| 77 | - */ |
|
| 78 | - public function onReverted(Review $review) |
|
| 79 | - { |
|
| 80 | - if (!$this->canPostReview($review)) { |
|
| 81 | - return; |
|
| 82 | - } |
|
| 83 | - $trustalyze = glsr(Trustalyze::class)->sendReview($review); |
|
| 84 | - if ($trustalyze->success) { |
|
| 85 | - glsr(Database::class)->set($review->ID, 'trustalyze', $trustalyze->review_id); |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * Triggered when an existing review is updated. |
|
| 91 | - * @return void |
|
| 92 | - * @action site-reviews/review/saved |
|
| 93 | - */ |
|
| 94 | - public function onSaved(Review $review) |
|
| 95 | - { |
|
| 96 | - if (!$this->canPostReview($review)) { |
|
| 97 | - return; |
|
| 98 | - } |
|
| 99 | - $trustalyze = glsr(Trustalyze::class)->sendReview($review); |
|
| 100 | - if ($trustalyze->success) { |
|
| 101 | - glsr(Database::class)->set($review->ID, 'trustalyze', $trustalyze->review_id); |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * Triggered when a review's response is added or updated. |
|
| 107 | - * @param int $metaId |
|
| 108 | - * @param int $postId |
|
| 109 | - * @param string $metaKey |
|
| 110 | - * @return void |
|
| 111 | - * @action updated_postmeta |
|
| 112 | - */ |
|
| 113 | - public function onUpdatedMeta($metaId, $postId, $metaKey) |
|
| 114 | - { |
|
| 115 | - $review = glsr_get_review($postId); |
|
| 116 | - if (!$this->canPostResponse($review) || '_response' !== $metaKey) { |
|
| 117 | - return; |
|
| 118 | - } |
|
| 119 | - $trustalyze = glsr(Trustalyze::class)->sendReviewResponse($review); |
|
| 120 | - if ($trustalyze->success) { |
|
| 121 | - glsr(Database::class)->set($review->ID, 'trustalyze_response', true); |
|
| 122 | - } |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * @return string |
|
| 127 | - */ |
|
| 128 | - protected function buildCreateButton() |
|
| 129 | - { |
|
| 130 | - return glsr(Builder::class)->a(__('Create Your Trustalyze Account', 'site-reviews'), [ |
|
| 131 | - 'class' => 'button', |
|
| 132 | - 'href' => Trustalyze::WEB_URL, |
|
| 133 | - 'target' => '_blank', |
|
| 134 | - ]); |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * @return bool |
|
| 139 | - */ |
|
| 140 | - protected function canPostResponse(Review $review) |
|
| 141 | - { |
|
| 142 | - $requiredValues = [ |
|
| 143 | - glsr(Database::class)->get($review->ID, 'trustalyze'), |
|
| 144 | - $review->response, |
|
| 145 | - $review->review_id, |
|
| 146 | - ]; |
|
| 147 | - return $this->canProceed($review, 'trustalyze_response') |
|
| 148 | - && 'publish' === $review->status |
|
| 149 | - && 3 === count(array_filter($requiredValues)); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * @return bool |
|
| 154 | - */ |
|
| 155 | - protected function canPostReview(Review $review) |
|
| 156 | - { |
|
| 157 | - $requiredValues = [ |
|
| 158 | - $review->author, |
|
| 159 | - $review->content, |
|
| 160 | - $review->rating, |
|
| 161 | - $review->review_id, |
|
| 162 | - $review->title, |
|
| 163 | - ]; |
|
| 164 | - return $this->canProceed($review) |
|
| 165 | - && 'publish' === $review->status |
|
| 166 | - && 5 === count(array_filter($requiredValues)); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * @param string $metaKey |
|
| 171 | - * @return bool |
|
| 172 | - */ |
|
| 173 | - protected function canProceed(Review $review, $metaKey = 'trustalyze') |
|
| 174 | - { |
|
| 175 | - return glsr(OptionManager::class)->getBool($this->enabledKey) |
|
| 176 | - && $this->isReviewPostId($review->ID) |
|
| 177 | - && !$this->hasMetaKey($review, $metaKey); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * @param string $metaKey |
|
| 182 | - * @return bool |
|
| 183 | - */ |
|
| 184 | - protected function hasMetaKey(Review $review, $metaKey = 'trustalyze') |
|
| 185 | - { |
|
| 186 | - return '' !== glsr(Database::class)->get($review->ID, $metaKey); |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * @param string $key |
|
| 191 | - * @return bool |
|
| 192 | - */ |
|
| 193 | - protected function isEmptyOrModified($key, array $settings) |
|
| 194 | - { |
|
| 195 | - $oldValue = glsr_get_option($key); |
|
| 196 | - $newValue = Arr::get($settings, $key); |
|
| 197 | - return empty($newValue) || $newValue !== $oldValue; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - /** |
|
| 201 | - * @return array |
|
| 202 | - */ |
|
| 203 | - protected function sanitizeTrustalyzeSettings(array $settings) |
|
| 204 | - { |
|
| 205 | - $trustalyze = glsr(Trustalyze::class)->activateKey( |
|
| 206 | - Arr::get($settings, $this->apiKey), |
|
| 207 | - Arr::get($settings, $this->emailKey) |
|
| 208 | - ); |
|
| 209 | - if ($trustalyze->success) { |
|
| 210 | - update_option($this->trustalyzeKey, Arr::get($trustalyze->response, 'producttype')); |
|
| 211 | - } else { |
|
| 212 | - delete_option($this->trustalyzeKey); |
|
| 213 | - $settings = Arr::set($settings, $this->enabledKey, 'no'); |
|
| 214 | - glsr(Notice::class)->addError(sprintf( |
|
| 215 | - __('Your Trustalyze account details could not be verified, please try again. %s', 'site-reviews'), |
|
| 216 | - '('.$trustalyze->message.')' |
|
| 217 | - )); |
|
| 218 | - } |
|
| 219 | - return $settings; |
|
| 220 | - } |
|
| 15 | + protected $apiKey = 'settings.general.trustalyze_serial'; |
|
| 16 | + protected $emailKey = 'settings.general.trustalyze_email'; |
|
| 17 | + protected $enabledKey = 'settings.general.trustalyze'; |
|
| 18 | + protected $trustalyzeKey = '_glsr_trustalyze'; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * @return array |
|
| 22 | + * @filter site-reviews/settings/callback |
|
| 23 | + */ |
|
| 24 | + public function filterSettingsCallback(array $settings) |
|
| 25 | + { |
|
| 26 | + if ('yes' !== Arr::get($settings, $this->enabledKey)) { |
|
| 27 | + return $settings; |
|
| 28 | + } |
|
| 29 | + $isApiKeyModified = $this->isEmptyOrModified($this->apiKey, $settings); |
|
| 30 | + $isEmailModified = $this->isEmptyOrModified($this->emailKey, $settings); |
|
| 31 | + $isAccountVerified = glsr(OptionManager::class)->getWP($this->trustalyzeKey, false); |
|
| 32 | + if (!$isAccountVerified || $isApiKeyModified || $isEmailModified) { |
|
| 33 | + $settings = $this->sanitizeTrustalyzeSettings($settings); |
|
| 34 | + } |
|
| 35 | + return $settings; |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * @param string $template |
|
| 40 | + * @return array |
|
| 41 | + * @filter site-reviews/interpolate/partials/form/table-row-multiple |
|
| 42 | + */ |
|
| 43 | + public function filterSettingsTableRow(array $context, $template, array $data) |
|
| 44 | + { |
|
| 45 | + if ($this->enabledKey !== Arr::get($data, 'field.path')) { |
|
| 46 | + return $context; |
|
| 47 | + } |
|
| 48 | + $isAccountValidated = !empty(glsr(OptionManager::class)->getWP($this->trustalyzeKey)); |
|
| 49 | + $isIntegrationEnabled = glsr(OptionManager::class)->getBool('settings.general.trustalyze'); |
|
| 50 | + if ($isAccountValidated && $isIntegrationEnabled) { |
|
| 51 | + return $context; |
|
| 52 | + } |
|
| 53 | + $context['field'].= $this->buildCreateButton(); |
|
| 54 | + return $context; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Triggered when a review is created. |
|
| 59 | + * @return void |
|
| 60 | + * @action site-reviews/review/created |
|
| 61 | + */ |
|
| 62 | + public function onCreated(Review $review) |
|
| 63 | + { |
|
| 64 | + if (!$this->canPostReview($review)) { |
|
| 65 | + return; |
|
| 66 | + } |
|
| 67 | + $trustalyze = glsr(Trustalyze::class)->sendReview($review); |
|
| 68 | + if ($trustalyze->success) { |
|
| 69 | + glsr(Database::class)->set($review->ID, 'trustalyze', $trustalyze->review_id); |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * Triggered when a review is reverted to its original title/content/date_timestamp. |
|
| 75 | + * @return void |
|
| 76 | + * @action site-reviews/review/reverted |
|
| 77 | + */ |
|
| 78 | + public function onReverted(Review $review) |
|
| 79 | + { |
|
| 80 | + if (!$this->canPostReview($review)) { |
|
| 81 | + return; |
|
| 82 | + } |
|
| 83 | + $trustalyze = glsr(Trustalyze::class)->sendReview($review); |
|
| 84 | + if ($trustalyze->success) { |
|
| 85 | + glsr(Database::class)->set($review->ID, 'trustalyze', $trustalyze->review_id); |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * Triggered when an existing review is updated. |
|
| 91 | + * @return void |
|
| 92 | + * @action site-reviews/review/saved |
|
| 93 | + */ |
|
| 94 | + public function onSaved(Review $review) |
|
| 95 | + { |
|
| 96 | + if (!$this->canPostReview($review)) { |
|
| 97 | + return; |
|
| 98 | + } |
|
| 99 | + $trustalyze = glsr(Trustalyze::class)->sendReview($review); |
|
| 100 | + if ($trustalyze->success) { |
|
| 101 | + glsr(Database::class)->set($review->ID, 'trustalyze', $trustalyze->review_id); |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * Triggered when a review's response is added or updated. |
|
| 107 | + * @param int $metaId |
|
| 108 | + * @param int $postId |
|
| 109 | + * @param string $metaKey |
|
| 110 | + * @return void |
|
| 111 | + * @action updated_postmeta |
|
| 112 | + */ |
|
| 113 | + public function onUpdatedMeta($metaId, $postId, $metaKey) |
|
| 114 | + { |
|
| 115 | + $review = glsr_get_review($postId); |
|
| 116 | + if (!$this->canPostResponse($review) || '_response' !== $metaKey) { |
|
| 117 | + return; |
|
| 118 | + } |
|
| 119 | + $trustalyze = glsr(Trustalyze::class)->sendReviewResponse($review); |
|
| 120 | + if ($trustalyze->success) { |
|
| 121 | + glsr(Database::class)->set($review->ID, 'trustalyze_response', true); |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * @return string |
|
| 127 | + */ |
|
| 128 | + protected function buildCreateButton() |
|
| 129 | + { |
|
| 130 | + return glsr(Builder::class)->a(__('Create Your Trustalyze Account', 'site-reviews'), [ |
|
| 131 | + 'class' => 'button', |
|
| 132 | + 'href' => Trustalyze::WEB_URL, |
|
| 133 | + 'target' => '_blank', |
|
| 134 | + ]); |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * @return bool |
|
| 139 | + */ |
|
| 140 | + protected function canPostResponse(Review $review) |
|
| 141 | + { |
|
| 142 | + $requiredValues = [ |
|
| 143 | + glsr(Database::class)->get($review->ID, 'trustalyze'), |
|
| 144 | + $review->response, |
|
| 145 | + $review->review_id, |
|
| 146 | + ]; |
|
| 147 | + return $this->canProceed($review, 'trustalyze_response') |
|
| 148 | + && 'publish' === $review->status |
|
| 149 | + && 3 === count(array_filter($requiredValues)); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * @return bool |
|
| 154 | + */ |
|
| 155 | + protected function canPostReview(Review $review) |
|
| 156 | + { |
|
| 157 | + $requiredValues = [ |
|
| 158 | + $review->author, |
|
| 159 | + $review->content, |
|
| 160 | + $review->rating, |
|
| 161 | + $review->review_id, |
|
| 162 | + $review->title, |
|
| 163 | + ]; |
|
| 164 | + return $this->canProceed($review) |
|
| 165 | + && 'publish' === $review->status |
|
| 166 | + && 5 === count(array_filter($requiredValues)); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * @param string $metaKey |
|
| 171 | + * @return bool |
|
| 172 | + */ |
|
| 173 | + protected function canProceed(Review $review, $metaKey = 'trustalyze') |
|
| 174 | + { |
|
| 175 | + return glsr(OptionManager::class)->getBool($this->enabledKey) |
|
| 176 | + && $this->isReviewPostId($review->ID) |
|
| 177 | + && !$this->hasMetaKey($review, $metaKey); |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * @param string $metaKey |
|
| 182 | + * @return bool |
|
| 183 | + */ |
|
| 184 | + protected function hasMetaKey(Review $review, $metaKey = 'trustalyze') |
|
| 185 | + { |
|
| 186 | + return '' !== glsr(Database::class)->get($review->ID, $metaKey); |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * @param string $key |
|
| 191 | + * @return bool |
|
| 192 | + */ |
|
| 193 | + protected function isEmptyOrModified($key, array $settings) |
|
| 194 | + { |
|
| 195 | + $oldValue = glsr_get_option($key); |
|
| 196 | + $newValue = Arr::get($settings, $key); |
|
| 197 | + return empty($newValue) || $newValue !== $oldValue; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * @return array |
|
| 202 | + */ |
|
| 203 | + protected function sanitizeTrustalyzeSettings(array $settings) |
|
| 204 | + { |
|
| 205 | + $trustalyze = glsr(Trustalyze::class)->activateKey( |
|
| 206 | + Arr::get($settings, $this->apiKey), |
|
| 207 | + Arr::get($settings, $this->emailKey) |
|
| 208 | + ); |
|
| 209 | + if ($trustalyze->success) { |
|
| 210 | + update_option($this->trustalyzeKey, Arr::get($trustalyze->response, 'producttype')); |
|
| 211 | + } else { |
|
| 212 | + delete_option($this->trustalyzeKey); |
|
| 213 | + $settings = Arr::set($settings, $this->enabledKey, 'no'); |
|
| 214 | + glsr(Notice::class)->addError(sprintf( |
|
| 215 | + __('Your Trustalyze account details could not be verified, please try again. %s', 'site-reviews'), |
|
| 216 | + '('.$trustalyze->message.')' |
|
| 217 | + )); |
|
| 218 | + } |
|
| 219 | + return $settings; |
|
| 220 | + } |
|
| 221 | 221 | } |
@@ -21,16 +21,16 @@ discard block |
||
| 21 | 21 | * @return array |
| 22 | 22 | * @filter site-reviews/settings/callback |
| 23 | 23 | */ |
| 24 | - public function filterSettingsCallback(array $settings) |
|
| 24 | + public function filterSettingsCallback( array $settings ) |
|
| 25 | 25 | { |
| 26 | - if ('yes' !== Arr::get($settings, $this->enabledKey)) { |
|
| 26 | + if( 'yes' !== Arr::get( $settings, $this->enabledKey ) ) { |
|
| 27 | 27 | return $settings; |
| 28 | 28 | } |
| 29 | - $isApiKeyModified = $this->isEmptyOrModified($this->apiKey, $settings); |
|
| 30 | - $isEmailModified = $this->isEmptyOrModified($this->emailKey, $settings); |
|
| 31 | - $isAccountVerified = glsr(OptionManager::class)->getWP($this->trustalyzeKey, false); |
|
| 32 | - if (!$isAccountVerified || $isApiKeyModified || $isEmailModified) { |
|
| 33 | - $settings = $this->sanitizeTrustalyzeSettings($settings); |
|
| 29 | + $isApiKeyModified = $this->isEmptyOrModified( $this->apiKey, $settings ); |
|
| 30 | + $isEmailModified = $this->isEmptyOrModified( $this->emailKey, $settings ); |
|
| 31 | + $isAccountVerified = glsr( OptionManager::class )->getWP( $this->trustalyzeKey, false ); |
|
| 32 | + if( !$isAccountVerified || $isApiKeyModified || $isEmailModified ) { |
|
| 33 | + $settings = $this->sanitizeTrustalyzeSettings( $settings ); |
|
| 34 | 34 | } |
| 35 | 35 | return $settings; |
| 36 | 36 | } |
@@ -40,17 +40,17 @@ discard block |
||
| 40 | 40 | * @return array |
| 41 | 41 | * @filter site-reviews/interpolate/partials/form/table-row-multiple |
| 42 | 42 | */ |
| 43 | - public function filterSettingsTableRow(array $context, $template, array $data) |
|
| 43 | + public function filterSettingsTableRow( array $context, $template, array $data ) |
|
| 44 | 44 | { |
| 45 | - if ($this->enabledKey !== Arr::get($data, 'field.path')) { |
|
| 45 | + if( $this->enabledKey !== Arr::get( $data, 'field.path' ) ) { |
|
| 46 | 46 | return $context; |
| 47 | 47 | } |
| 48 | - $isAccountValidated = !empty(glsr(OptionManager::class)->getWP($this->trustalyzeKey)); |
|
| 49 | - $isIntegrationEnabled = glsr(OptionManager::class)->getBool('settings.general.trustalyze'); |
|
| 50 | - if ($isAccountValidated && $isIntegrationEnabled) { |
|
| 48 | + $isAccountValidated = !empty(glsr( OptionManager::class )->getWP( $this->trustalyzeKey )); |
|
| 49 | + $isIntegrationEnabled = glsr( OptionManager::class )->getBool( 'settings.general.trustalyze' ); |
|
| 50 | + if( $isAccountValidated && $isIntegrationEnabled ) { |
|
| 51 | 51 | return $context; |
| 52 | 52 | } |
| 53 | - $context['field'].= $this->buildCreateButton(); |
|
| 53 | + $context['field'] .= $this->buildCreateButton(); |
|
| 54 | 54 | return $context; |
| 55 | 55 | } |
| 56 | 56 | |
@@ -59,14 +59,14 @@ discard block |
||
| 59 | 59 | * @return void |
| 60 | 60 | * @action site-reviews/review/created |
| 61 | 61 | */ |
| 62 | - public function onCreated(Review $review) |
|
| 62 | + public function onCreated( Review $review ) |
|
| 63 | 63 | { |
| 64 | - if (!$this->canPostReview($review)) { |
|
| 64 | + if( !$this->canPostReview( $review ) ) { |
|
| 65 | 65 | return; |
| 66 | 66 | } |
| 67 | - $trustalyze = glsr(Trustalyze::class)->sendReview($review); |
|
| 68 | - if ($trustalyze->success) { |
|
| 69 | - glsr(Database::class)->set($review->ID, 'trustalyze', $trustalyze->review_id); |
|
| 67 | + $trustalyze = glsr( Trustalyze::class )->sendReview( $review ); |
|
| 68 | + if( $trustalyze->success ) { |
|
| 69 | + glsr( Database::class )->set( $review->ID, 'trustalyze', $trustalyze->review_id ); |
|
| 70 | 70 | } |
| 71 | 71 | } |
| 72 | 72 | |
@@ -75,14 +75,14 @@ discard block |
||
| 75 | 75 | * @return void |
| 76 | 76 | * @action site-reviews/review/reverted |
| 77 | 77 | */ |
| 78 | - public function onReverted(Review $review) |
|
| 78 | + public function onReverted( Review $review ) |
|
| 79 | 79 | { |
| 80 | - if (!$this->canPostReview($review)) { |
|
| 80 | + if( !$this->canPostReview( $review ) ) { |
|
| 81 | 81 | return; |
| 82 | 82 | } |
| 83 | - $trustalyze = glsr(Trustalyze::class)->sendReview($review); |
|
| 84 | - if ($trustalyze->success) { |
|
| 85 | - glsr(Database::class)->set($review->ID, 'trustalyze', $trustalyze->review_id); |
|
| 83 | + $trustalyze = glsr( Trustalyze::class )->sendReview( $review ); |
|
| 84 | + if( $trustalyze->success ) { |
|
| 85 | + glsr( Database::class )->set( $review->ID, 'trustalyze', $trustalyze->review_id ); |
|
| 86 | 86 | } |
| 87 | 87 | } |
| 88 | 88 | |
@@ -91,14 +91,14 @@ discard block |
||
| 91 | 91 | * @return void |
| 92 | 92 | * @action site-reviews/review/saved |
| 93 | 93 | */ |
| 94 | - public function onSaved(Review $review) |
|
| 94 | + public function onSaved( Review $review ) |
|
| 95 | 95 | { |
| 96 | - if (!$this->canPostReview($review)) { |
|
| 96 | + if( !$this->canPostReview( $review ) ) { |
|
| 97 | 97 | return; |
| 98 | 98 | } |
| 99 | - $trustalyze = glsr(Trustalyze::class)->sendReview($review); |
|
| 100 | - if ($trustalyze->success) { |
|
| 101 | - glsr(Database::class)->set($review->ID, 'trustalyze', $trustalyze->review_id); |
|
| 99 | + $trustalyze = glsr( Trustalyze::class )->sendReview( $review ); |
|
| 100 | + if( $trustalyze->success ) { |
|
| 101 | + glsr( Database::class )->set( $review->ID, 'trustalyze', $trustalyze->review_id ); |
|
| 102 | 102 | } |
| 103 | 103 | } |
| 104 | 104 | |
@@ -110,15 +110,15 @@ discard block |
||
| 110 | 110 | * @return void |
| 111 | 111 | * @action updated_postmeta |
| 112 | 112 | */ |
| 113 | - public function onUpdatedMeta($metaId, $postId, $metaKey) |
|
| 113 | + public function onUpdatedMeta( $metaId, $postId, $metaKey ) |
|
| 114 | 114 | { |
| 115 | - $review = glsr_get_review($postId); |
|
| 116 | - if (!$this->canPostResponse($review) || '_response' !== $metaKey) { |
|
| 115 | + $review = glsr_get_review( $postId ); |
|
| 116 | + if( !$this->canPostResponse( $review ) || '_response' !== $metaKey ) { |
|
| 117 | 117 | return; |
| 118 | 118 | } |
| 119 | - $trustalyze = glsr(Trustalyze::class)->sendReviewResponse($review); |
|
| 120 | - if ($trustalyze->success) { |
|
| 121 | - glsr(Database::class)->set($review->ID, 'trustalyze_response', true); |
|
| 119 | + $trustalyze = glsr( Trustalyze::class )->sendReviewResponse( $review ); |
|
| 120 | + if( $trustalyze->success ) { |
|
| 121 | + glsr( Database::class )->set( $review->ID, 'trustalyze_response', true ); |
|
| 122 | 122 | } |
| 123 | 123 | } |
| 124 | 124 | |
@@ -127,32 +127,32 @@ discard block |
||
| 127 | 127 | */ |
| 128 | 128 | protected function buildCreateButton() |
| 129 | 129 | { |
| 130 | - return glsr(Builder::class)->a(__('Create Your Trustalyze Account', 'site-reviews'), [ |
|
| 130 | + return glsr( Builder::class )->a( __( 'Create Your Trustalyze Account', 'site-reviews' ), [ |
|
| 131 | 131 | 'class' => 'button', |
| 132 | 132 | 'href' => Trustalyze::WEB_URL, |
| 133 | 133 | 'target' => '_blank', |
| 134 | - ]); |
|
| 134 | + ] ); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | /** |
| 138 | 138 | * @return bool |
| 139 | 139 | */ |
| 140 | - protected function canPostResponse(Review $review) |
|
| 140 | + protected function canPostResponse( Review $review ) |
|
| 141 | 141 | { |
| 142 | 142 | $requiredValues = [ |
| 143 | - glsr(Database::class)->get($review->ID, 'trustalyze'), |
|
| 143 | + glsr( Database::class )->get( $review->ID, 'trustalyze' ), |
|
| 144 | 144 | $review->response, |
| 145 | 145 | $review->review_id, |
| 146 | 146 | ]; |
| 147 | - return $this->canProceed($review, 'trustalyze_response') |
|
| 147 | + return $this->canProceed( $review, 'trustalyze_response' ) |
|
| 148 | 148 | && 'publish' === $review->status |
| 149 | - && 3 === count(array_filter($requiredValues)); |
|
| 149 | + && 3 === count( array_filter( $requiredValues ) ); |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | /** |
| 153 | 153 | * @return bool |
| 154 | 154 | */ |
| 155 | - protected function canPostReview(Review $review) |
|
| 155 | + protected function canPostReview( Review $review ) |
|
| 156 | 156 | { |
| 157 | 157 | $requiredValues = [ |
| 158 | 158 | $review->author, |
@@ -161,60 +161,60 @@ discard block |
||
| 161 | 161 | $review->review_id, |
| 162 | 162 | $review->title, |
| 163 | 163 | ]; |
| 164 | - return $this->canProceed($review) |
|
| 164 | + return $this->canProceed( $review ) |
|
| 165 | 165 | && 'publish' === $review->status |
| 166 | - && 5 === count(array_filter($requiredValues)); |
|
| 166 | + && 5 === count( array_filter( $requiredValues ) ); |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | /** |
| 170 | 170 | * @param string $metaKey |
| 171 | 171 | * @return bool |
| 172 | 172 | */ |
| 173 | - protected function canProceed(Review $review, $metaKey = 'trustalyze') |
|
| 173 | + protected function canProceed( Review $review, $metaKey = 'trustalyze' ) |
|
| 174 | 174 | { |
| 175 | - return glsr(OptionManager::class)->getBool($this->enabledKey) |
|
| 176 | - && $this->isReviewPostId($review->ID) |
|
| 177 | - && !$this->hasMetaKey($review, $metaKey); |
|
| 175 | + return glsr( OptionManager::class )->getBool( $this->enabledKey ) |
|
| 176 | + && $this->isReviewPostId( $review->ID ) |
|
| 177 | + && !$this->hasMetaKey( $review, $metaKey ); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | /** |
| 181 | 181 | * @param string $metaKey |
| 182 | 182 | * @return bool |
| 183 | 183 | */ |
| 184 | - protected function hasMetaKey(Review $review, $metaKey = 'trustalyze') |
|
| 184 | + protected function hasMetaKey( Review $review, $metaKey = 'trustalyze' ) |
|
| 185 | 185 | { |
| 186 | - return '' !== glsr(Database::class)->get($review->ID, $metaKey); |
|
| 186 | + return '' !== glsr( Database::class )->get( $review->ID, $metaKey ); |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | /** |
| 190 | 190 | * @param string $key |
| 191 | 191 | * @return bool |
| 192 | 192 | */ |
| 193 | - protected function isEmptyOrModified($key, array $settings) |
|
| 193 | + protected function isEmptyOrModified( $key, array $settings ) |
|
| 194 | 194 | { |
| 195 | - $oldValue = glsr_get_option($key); |
|
| 196 | - $newValue = Arr::get($settings, $key); |
|
| 195 | + $oldValue = glsr_get_option( $key ); |
|
| 196 | + $newValue = Arr::get( $settings, $key ); |
|
| 197 | 197 | return empty($newValue) || $newValue !== $oldValue; |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | /** |
| 201 | 201 | * @return array |
| 202 | 202 | */ |
| 203 | - protected function sanitizeTrustalyzeSettings(array $settings) |
|
| 203 | + protected function sanitizeTrustalyzeSettings( array $settings ) |
|
| 204 | 204 | { |
| 205 | - $trustalyze = glsr(Trustalyze::class)->activateKey( |
|
| 206 | - Arr::get($settings, $this->apiKey), |
|
| 207 | - Arr::get($settings, $this->emailKey) |
|
| 205 | + $trustalyze = glsr( Trustalyze::class )->activateKey( |
|
| 206 | + Arr::get( $settings, $this->apiKey ), |
|
| 207 | + Arr::get( $settings, $this->emailKey ) |
|
| 208 | 208 | ); |
| 209 | - if ($trustalyze->success) { |
|
| 210 | - update_option($this->trustalyzeKey, Arr::get($trustalyze->response, 'producttype')); |
|
| 209 | + if( $trustalyze->success ) { |
|
| 210 | + update_option( $this->trustalyzeKey, Arr::get( $trustalyze->response, 'producttype' ) ); |
|
| 211 | 211 | } else { |
| 212 | - delete_option($this->trustalyzeKey); |
|
| 213 | - $settings = Arr::set($settings, $this->enabledKey, 'no'); |
|
| 214 | - glsr(Notice::class)->addError(sprintf( |
|
| 215 | - __('Your Trustalyze account details could not be verified, please try again. %s', 'site-reviews'), |
|
| 212 | + delete_option( $this->trustalyzeKey ); |
|
| 213 | + $settings = Arr::set( $settings, $this->enabledKey, 'no' ); |
|
| 214 | + glsr( Notice::class )->addError( sprintf( |
|
| 215 | + __( 'Your Trustalyze account details could not be verified, please try again. %s', 'site-reviews' ), |
|
| 216 | 216 | '('.$trustalyze->message.')' |
| 217 | - )); |
|
| 217 | + ) ); |
|
| 218 | 218 | } |
| 219 | 219 | return $settings; |
| 220 | 220 | } |
@@ -208,7 +208,8 @@ |
||
| 208 | 208 | ); |
| 209 | 209 | if ($trustalyze->success) { |
| 210 | 210 | update_option($this->trustalyzeKey, Arr::get($trustalyze->response, 'producttype')); |
| 211 | - } else { |
|
| 211 | + } |
|
| 212 | + else { |
|
| 212 | 213 | delete_option($this->trustalyzeKey); |
| 213 | 214 | $settings = Arr::set($settings, $this->enabledKey, 'no'); |
| 214 | 215 | glsr(Notice::class)->addError(sprintf( |