PluginProbe ʕ •ᴥ•ʔ
Reviews Feed – Add Testimonials and Customer Reviews From Google Reviews, Yelp, TripAdvisor, and More / 2.6.7
Reviews Feed – Add Testimonials and Customer Reviews From Google Reviews, Yelp, TripAdvisor, and More v2.6.7
2.11.0 2.10.0 2.9.0 2.8.0 2.7.0 2.6.7 2.6.8 2.6.5 2.6.4 2.6.3 2.6.2 2.6.0 2.5.5 2.5.4 2.5.3 2.5.2 trunk 1.0 1.0.1 1.0.2 1.0.3 1.1 1.1.1 1.1.2 1.2.0 2.0 2.1.0 2.1.1 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.5.0 2.5.1
reviews-feed / class / Common / AuthorizationStatusCheck.php
reviews-feed / class / Common Last commit date
Admin 2 months ago Builder 2 months ago Customizer 2 months ago Exceptions 2 months ago Helpers 2 months ago Integrations 2 months ago Migrations 2 months ago ReviewAlerts 2 months ago Services 2 months ago Settings 2 months ago Support 2 months ago Traits 2 months ago Utils 2 months ago AuthorizationStatusCheck.php 2 months ago BusinessDataCache.php 2 months ago Clear_Cache.php 2 months ago Container.php 2 months ago DisplayElements.php 2 months ago Email_Notification.php 2 months ago Error_Reporter.php 2 months ago Feed.php 2 months ago FeedCache.php 2 months ago FeedCacheUpdater.php 2 months ago FeedDisplay.php 2 months ago Feed_Locator.php 2 months ago Parser.php 2 months ago PostAggregator.php 2 months ago RemoteRequest.php 2 months ago SBR_Education.php 2 months ago SBR_Settings.php 2 months ago ServiceContainer.php 2 months ago SinglePostCache.php 2 months ago TemplateRenderer.php 2 months ago Tooltip_Wizard.php 2 months ago Util.php 2 months ago
AuthorizationStatusCheck.php
177 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 'airbnb' => 2,
105 'booking' => 2,
106 'aliexpress' => 2,
107 'tripadvisor' => 3,
108 'wordpress.org' => 3
109 ];
110 }
111
112
113 /**
114 * Tier allowed providers
115 *
116 * @return string[]
117 */
118 public function get_tier_allowed_providers()
119 {
120 $allowed = array(
121 'google',
122 'yelp'
123 );
124
125 if (Util::sbr_is_pro()) {
126 if ($this->get_license_tier() >= 2) {
127 $allowed[] = 'facebook';
128 $allowed[] = 'trustpilot';
129 $allowed[] = 'woocommerce';
130 $allowed[] = 'edd';
131 $allowed[] = 'airbnb';
132 $allowed[] = 'booking';
133 $allowed[] = 'aliexpress';
134 }
135 if ($this->get_license_tier() === 3) {
136 $allowed[] = 'tripadvisor';
137 $allowed[] = 'wordpress.org';
138 }
139 }
140 return $allowed;
141 }
142
143 /**
144 * How often, in seconds, feeds can be updated based on license tier
145 *
146 * @return float|int
147 */
148 public function get_update_frequency()
149 {
150 $frequency = 24 * HOUR_IN_SECONDS;
151 if ($this->get_license_tier() === 3) {
152 $frequency = 12 * HOUR_IN_SECONDS;
153 }
154
155 return $frequency;
156 }
157
158 /**
159 * Providers that have an API key saved in settings
160 *
161 * @return array
162 */
163 public function get_providers_with_api_keys()
164 {
165 // look through options for providers with API key supplied
166 return array();
167 }
168
169 public function update_status($status)
170 {
171 $current_status = get_option('sbr_statuses', array());
172 $updated_status = array_merge($current_status, $status);
173
174 return update_option('sbr_statuses', $updated_status);
175 }
176 }
177