Admin
1 week ago
Builder
6 hours ago
Customizer
1 week ago
Exceptions
5 months ago
Helpers
1 month ago
Integrations
1 week ago
Migrations
3 years ago
ReviewAlerts
1 week ago
Services
3 weeks ago
Settings
2 months ago
Support
2 months ago
Traits
5 months ago
Utils
3 weeks ago
AuthorizationStatusCheck.php
1 week ago
BusinessDataCache.php
5 months ago
Clear_Cache.php
2 months ago
Container.php
5 months ago
DisplayElements.php
1 month ago
Email_Notification.php
5 months ago
Error_Reporter.php
2 months ago
Feed.php
2 weeks ago
FeedCache.php
4 months ago
FeedCacheUpdater.php
2 months ago
FeedDisplay.php
1 week ago
Feed_Locator.php
5 months ago
Parser.php
3 weeks ago
PostAggregator.php
3 weeks ago
RemoteRequest.php
1 week ago
SBR_Education.php
2 months ago
SBR_Settings.php
5 months ago
ServiceContainer.php
2 weeks ago
SinglePostCache.php
2 weeks ago
TemplateRenderer.php
5 months ago
Tooltip_Wizard.php
2 months ago
Util.php
6 hours ago
AuthorizationStatusCheck.php
183 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Class AuthorizationStatusCheck |
| 5 | * |
| 6 | * @since 1.0 |
| 7 | */ |
| 8 | |
| 9 | namespace SmashBalloon\Reviews\Common; |
| 10 | |
| 11 | class AuthorizationStatusCheck { |
| 12 | /** |
| 13 | * @var array |
| 14 | */ |
| 15 | private $statuses; |
| 16 | |
| 17 | public function __construct() |
| 18 | { |
| 19 | $this->statuses = get_option('sbr_statuses', array()); |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * An associative array with statuses of various authorization related things |
| 24 | * |
| 25 | * @return array |
| 26 | */ |
| 27 | public function get_statuses() |
| 28 | { |
| 29 | $return = array( |
| 30 | 'license_info' => isset($this->statuses['license_info']) ? $this->statuses['license_info'] : [], |
| 31 | 'license_tier' => $this->get_license_tier(), |
| 32 | 'provider_source_limit_reached' => $this->get_provider_source_limit_reached(), |
| 33 | 'tier_allowed_providers' => $this->get_tier_allowed_providers(), |
| 34 | 'update_frequency' => $this->get_update_frequency(), |
| 35 | 'last_cron_update' => ! empty($this->statuses['last_cron_update']) ? $this->statuses['last_cron_update'] : 0, |
| 36 | 'tiers_info' => $this->get_tiers_info(), |
| 37 | 'woocommerce_active' => $this->is_woocommerce_active(), |
| 38 | ); |
| 39 | |
| 40 | return $return; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Check if WooCommerce plugin is active |
| 45 | * |
| 46 | * @return bool |
| 47 | */ |
| 48 | public function is_woocommerce_active() |
| 49 | { |
| 50 | return class_exists('WooCommerce') || function_exists('WC'); |
| 51 | } |
| 52 | |
| 53 | |
| 54 | /** |
| 55 | * The current license tier, 0 for a free tier |
| 56 | * |
| 57 | * @return int |
| 58 | */ |
| 59 | public function get_license_tier() |
| 60 | { |
| 61 | $tier = isset($this->statuses['license_tier']) ? $this->statuses['license_tier'] : 0; |
| 62 | if (isset($this->statuses['license_info']) && isset($this->statuses['license_info']['item_name']) && $this->statuses['license_info']['item_name'] === 'All Access Bundle - All Plugins Unlimited') { |
| 63 | $tier = 3; |
| 64 | } |
| 65 | return intval($tier); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Returns a list of providers that have had the maximum number of non API key supported |
| 70 | * sources connected and also do not have an API key saved in settings |
| 71 | * |
| 72 | * @return array |
| 73 | */ |
| 74 | public function get_provider_source_limit_reached() |
| 75 | { |
| 76 | if (! empty($this->statuses['provider_limit_reached']) && is_array($this->statuses['provider_limit_reached'])) { |
| 77 | $providers_with_keys = $this->get_providers_with_api_keys(); |
| 78 | $return = array(); |
| 79 | foreach ($this->statuses['provider_limit_reached'] as $provider_limit_reached) { |
| 80 | if (! in_array($provider_limit_reached, $providers_with_keys)) { |
| 81 | $return[] = $provider_limit_reached; |
| 82 | } |
| 83 | } |
| 84 | return $return; |
| 85 | } |
| 86 | |
| 87 | return array(); |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Get Tiers Info |
| 92 | * |
| 93 | * @return [] |
| 94 | */ |
| 95 | public function get_tiers_info() |
| 96 | { |
| 97 | return [ |
| 98 | 'google' => 1, |
| 99 | 'yelp' => 1, |
| 100 | 'facebook' => 2, |
| 101 | 'trustpilot' => 2, |
| 102 | 'woocommerce' => 2, |
| 103 | 'edd' => 2, |
| 104 | // SMASH-782 tier split: AliExpress = Plus (e-commerce), Airbnb + |
| 105 | // Booking = Elite (travel). Mirrors relay LicenseTiers::getAllowedProviders(). |
| 106 | 'aliexpress' => 2, |
| 107 | 'airbnb' => 3, |
| 108 | 'booking' => 3, |
| 109 | 'tripadvisor' => 3, |
| 110 | 'wordpress.org' => 3 |
| 111 | ]; |
| 112 | } |
| 113 | |
| 114 | |
| 115 | /** |
| 116 | * Tier allowed providers |
| 117 | * |
| 118 | * @return string[] |
| 119 | */ |
| 120 | public function get_tier_allowed_providers() |
| 121 | { |
| 122 | $allowed = array( |
| 123 | 'google', |
| 124 | 'yelp' |
| 125 | ); |
| 126 | |
| 127 | if (Util::sbr_is_pro()) { |
| 128 | if ($this->get_license_tier() >= 2) { |
| 129 | $allowed[] = 'facebook'; |
| 130 | $allowed[] = 'trustpilot'; |
| 131 | $allowed[] = 'woocommerce'; |
| 132 | $allowed[] = 'edd'; |
| 133 | // SMASH-782 tier split: AliExpress ships on Plus (tier >= 2, |
| 134 | // e-commerce segment). Mirrors relay LicenseTiers::getAllowedProviders(). |
| 135 | // Widening-only — Elite users keep it via this same block. |
| 136 | $allowed[] = 'aliexpress'; |
| 137 | } |
| 138 | if ($this->get_license_tier() === 3) { |
| 139 | $allowed[] = 'tripadvisor'; |
| 140 | $allowed[] = 'wordpress.org'; |
| 141 | // Airbnb + Booking stay Elite-only (tier === 3, travel segment). |
| 142 | $allowed[] = 'airbnb'; |
| 143 | $allowed[] = 'booking'; |
| 144 | } |
| 145 | } |
| 146 | return $allowed; |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * How often, in seconds, feeds can be updated based on license tier |
| 151 | * |
| 152 | * @return float|int |
| 153 | */ |
| 154 | public function get_update_frequency() |
| 155 | { |
| 156 | $frequency = 24 * HOUR_IN_SECONDS; |
| 157 | if ($this->get_license_tier() === 3) { |
| 158 | $frequency = 12 * HOUR_IN_SECONDS; |
| 159 | } |
| 160 | |
| 161 | return $frequency; |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * Providers that have an API key saved in settings |
| 166 | * |
| 167 | * @return array |
| 168 | */ |
| 169 | public function get_providers_with_api_keys() |
| 170 | { |
| 171 | // look through options for providers with API key supplied |
| 172 | return array(); |
| 173 | } |
| 174 | |
| 175 | public function update_status($status) |
| 176 | { |
| 177 | $current_status = get_option('sbr_statuses', array()); |
| 178 | $updated_status = array_merge($current_status, $status); |
| 179 | |
| 180 | return update_option('sbr_statuses', $updated_status); |
| 181 | } |
| 182 | } |
| 183 |