Analytics_Manager.php
8 months ago
Browser_Detector.php
9 months ago
Content_Cache_Manager.php
9 months ago
Data_Collector.php
7 months ago
Email_Reports.php
9 months ago
Export_Manager.php
9 months ago
License_Manager.php
9 months ago
Milestone_Manager.php
9 months ago
Pro_Data_Collector.php
9 months ago
REST_API.php
9 months ago
License_Manager.php
241 lines
| 1 | <?php |
| 2 | |
| 3 | namespace EmbedPress\Includes\Classes\Analytics; |
| 4 | |
| 5 | /** |
| 6 | * EmbedPress Analytics License Manager |
| 7 | * |
| 8 | * Handles license checking for analytics pro features |
| 9 | * |
| 10 | * @package EmbedPress |
| 11 | * @author EmbedPress <help@embedpress.com> |
| 12 | * @copyright Copyright (C) 2023 WPDeveloper. All rights reserved. |
| 13 | * @license GPLv3 or later |
| 14 | * @since 4.2.7 |
| 15 | */ |
| 16 | class License_Manager |
| 17 | { |
| 18 | /** |
| 19 | * Check if user has valid pro license |
| 20 | * |
| 21 | * @return bool |
| 22 | */ |
| 23 | public static function has_pro_license() |
| 24 | { |
| 25 | // First check if EmbedPress Pro plugin is active |
| 26 | if (!is_plugin_active('embedpress-pro/embedpress-pro.php')) { |
| 27 | return false; |
| 28 | } |
| 29 | |
| 30 | // Check if the pro constants are defined (indicates pro is properly loaded) |
| 31 | if (!defined('EMBEDPRESS_SL_ITEM_SLUG')) { |
| 32 | return false; |
| 33 | } |
| 34 | |
| 35 | // For now, if pro is active and constants are defined, consider it valid |
| 36 | // This matches how other parts of EmbedPress check for pro status |
| 37 | return true; |
| 38 | |
| 39 | // TODO: Add actual license validation later if needed |
| 40 | /* |
| 41 | try { |
| 42 | // Check if license manager class exists |
| 43 | if (!class_exists('\Embedpress\Pro\Dependencies\WPDeveloper\Licensing\LicenseManager')) { |
| 44 | return true; // Pro is active, assume valid for now |
| 45 | } |
| 46 | |
| 47 | // Get license manager instance |
| 48 | $license_manager = \Embedpress\Pro\Dependencies\WPDeveloper\Licensing\LicenseManager::get_instance([ |
| 49 | 'plugin_file' => EMBEDPRESS_PRO_PLUGIN_FILE, |
| 50 | 'version' => EMBEDPRESS_PRO_PLUGIN_VERSION, |
| 51 | 'item_id' => EMBEDPRESS_SL_ITEM_ID, |
| 52 | 'item_name' => EMBEDPRESS_SL_ITEM_NAME, |
| 53 | 'item_slug' => EMBEDPRESS_SL_ITEM_SLUG, |
| 54 | 'storeURL' => EMBEDPRESS_STORE_URL, |
| 55 | 'db_prefix' => EMBEDPRESS_SL_DB_PREFIX, |
| 56 | 'textdomain' => 'embedpress-pro', |
| 57 | ]); |
| 58 | |
| 59 | $license_data = $license_manager->get_license_data(); |
| 60 | |
| 61 | return isset($license_data['license_status']) && |
| 62 | $license_data['license_status'] === 'valid'; |
| 63 | |
| 64 | } catch (Exception $e) { |
| 65 | return true; // If license check fails, assume valid since pro is active |
| 66 | } |
| 67 | */ |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Check if specific analytics feature is available |
| 72 | * |
| 73 | * @param string $feature |
| 74 | * @return bool |
| 75 | */ |
| 76 | public static function has_analytics_feature($feature) |
| 77 | { |
| 78 | $free_features = [ |
| 79 | 'total_views', |
| 80 | 'total_clicks', |
| 81 | 'total_impressions', |
| 82 | 'total_unique_viewers', |
| 83 | 'views_over_time_basic', |
| 84 | 'basic_charts' |
| 85 | ]; |
| 86 | |
| 87 | $pro_features = [ |
| 88 | 'per_embed_analytics', |
| 89 | 'unique_viewers_per_embed', |
| 90 | 'views_over_time_advanced', |
| 91 | 'geo_tracking', |
| 92 | 'device_analytics', |
| 93 | 'email_reports', |
| 94 | 'referral_tracking', |
| 95 | 'advanced_charts', |
| 96 | 'export_pdf' |
| 97 | ]; |
| 98 | |
| 99 | // Free features are always available |
| 100 | if (in_array($feature, $free_features)) { |
| 101 | return true; |
| 102 | } |
| 103 | |
| 104 | // Pro features require valid license |
| 105 | if (in_array($feature, $pro_features)) { |
| 106 | return self::has_pro_license(); |
| 107 | } |
| 108 | |
| 109 | return false; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Get upgrade URL for pro features |
| 114 | * |
| 115 | * @return string |
| 116 | */ |
| 117 | public static function get_upgrade_url() |
| 118 | { |
| 119 | return 'https://wpdeveloper.com/in/upgrade-embedpress'; |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Get pro feature notice HTML |
| 124 | * |
| 125 | * @param string $feature_name |
| 126 | * @param string $description |
| 127 | * @return string |
| 128 | */ |
| 129 | public static function get_pro_notice_html($feature_name, $description = '') |
| 130 | { |
| 131 | $upgrade_url = self::get_upgrade_url(); |
| 132 | |
| 133 | return sprintf( |
| 134 | '<div class="embedpress-pro-notice"> |
| 135 | <div class="pro-notice-content"> |
| 136 | <h4>🚀 %s - Pro Feature</h4> |
| 137 | <p>%s</p> |
| 138 | <a href="%s" target="_blank" class="button button-primary"> |
| 139 | Upgrade to Pro <span class="dashicons dashicons-external"></span> |
| 140 | </a> |
| 141 | </div> |
| 142 | </div>', |
| 143 | esc_html($feature_name), |
| 144 | esc_html($description ?: "This feature is available in EmbedPress Pro."), |
| 145 | esc_url($upgrade_url) |
| 146 | ); |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Check if analytics is enabled |
| 151 | * |
| 152 | * @return bool |
| 153 | */ |
| 154 | public static function is_analytics_enabled() |
| 155 | { |
| 156 | // Check if analytics is disabled in settings |
| 157 | $settings = get_option('embedpress_settings', []); |
| 158 | |
| 159 | return !isset($settings['disable_analytics']) || !$settings['disable_analytics']; |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * Get analytics limits for current license |
| 164 | * |
| 165 | * @return array |
| 166 | */ |
| 167 | public static function get_analytics_limits() |
| 168 | { |
| 169 | if (self::has_pro_license()) { |
| 170 | return [ |
| 171 | 'max_tracked_content' => -1, // unlimited |
| 172 | 'data_retention_days' => 365, |
| 173 | 'export_formats' => ['csv', 'pdf'], |
| 174 | 'email_reports' => true, |
| 175 | 'advanced_features' => true |
| 176 | ]; |
| 177 | } |
| 178 | |
| 179 | return [ |
| 180 | 'max_tracked_content' => 100, |
| 181 | 'data_retention_days' => 90, |
| 182 | 'export_formats' => ['csv'], |
| 183 | 'email_reports' => false, |
| 184 | 'advanced_features' => false |
| 185 | ]; |
| 186 | } |
| 187 | |
| 188 | /** |
| 189 | * Check if content tracking limit is reached |
| 190 | * |
| 191 | * @return bool |
| 192 | */ |
| 193 | public static function is_tracking_limit_reached() |
| 194 | { |
| 195 | if (self::has_pro_license()) { |
| 196 | return false; // No limits for pro users |
| 197 | } |
| 198 | |
| 199 | global $wpdb; |
| 200 | $content_table = $wpdb->prefix . 'embedpress_analytics_content'; |
| 201 | |
| 202 | $count = $wpdb->get_var("SELECT COUNT(*) FROM $content_table"); |
| 203 | $limits = self::get_analytics_limits(); |
| 204 | |
| 205 | return $count >= $limits['max_tracked_content']; |
| 206 | } |
| 207 | |
| 208 | /** |
| 209 | * Get feature availability status |
| 210 | * |
| 211 | * @return array |
| 212 | */ |
| 213 | public static function get_feature_status() |
| 214 | { |
| 215 | $has_pro = self::has_pro_license(); |
| 216 | |
| 217 | return [ |
| 218 | 'has_pro_license' => $has_pro, |
| 219 | 'features' => [ |
| 220 | // Free features |
| 221 | 'total_analytics' => true, |
| 222 | 'basic_charts' => true, |
| 223 | 'unique_viewers_total' => true, |
| 224 | 'views_over_time_basic' => true, |
| 225 | |
| 226 | // Pro features |
| 227 | 'per_embed_analytics' => $has_pro, |
| 228 | 'unique_viewers_per_embed' => $has_pro, |
| 229 | 'advanced_charts' => $has_pro, |
| 230 | 'geo_tracking' => $has_pro, |
| 231 | 'device_analytics' => $has_pro, |
| 232 | 'email_reports' => $has_pro, |
| 233 | 'referral_tracking' => $has_pro, |
| 234 | 'export_pdf' => $has_pro |
| 235 | ], |
| 236 | 'limits' => self::get_analytics_limits(), |
| 237 | 'upgrade_url' => self::get_upgrade_url() |
| 238 | ]; |
| 239 | } |
| 240 | } |
| 241 |