| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package FireBox |
| 4 |
* @version 2.1.37 Free |
| 5 |
* |
| 6 |
* @author FirePlugins <info@fireplugins.com> |
| 7 |
* @link https://www.fireplugins.com |
| 8 |
* @copyright Copyright © 2025 FirePlugins All Rights Reserved |
| 9 |
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace FireBox\Core\UsageTracking; |
| 13 |
|
| 14 |
if (!defined('ABSPATH')) |
| 15 |
{ |
| 16 |
exit; // Exit if accessed directly. |
| 17 |
} |
| 18 |
|
| 19 |
class UsageTracking |
| 20 |
{ |
| 21 |
private $settings = []; |
| 22 |
|
| 23 |
private $pluginData = []; |
| 24 |
|
| 25 |
public function __construct() |
| 26 |
{ |
| 27 |
$this->settings = get_option('firebox_sttings', []); |
| 28 |
$this->pluginData = new PluginData(); |
| 29 |
} |
| 30 |
|
| 31 |
public function getData() |
| 32 |
{ |
| 33 |
global $wpdb; |
| 34 |
|
| 35 |
$theme_data = wp_get_theme(); |
| 36 |
|
| 37 |
$payload = [ |
| 38 |
// Generic Data |
| 39 |
'url' => home_url(), |
| 40 |
'email' => get_option('admin_email'), |
| 41 |
'php_version' => PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION, |
| 42 |
'wp_version' => get_bloginfo('version'), |
| 43 |
'database_type' => $this->getDatabaseType(), |
| 44 |
'database_version' => $wpdb->db_version(), |
| 45 |
'server_version' => isset($_SERVER['SERVER_SOFTWARE']) ? sanitize_text_field(wp_unslash($_SERVER['SERVER_SOFTWARE'])) : '', |
| 46 |
'is_debug' => defined('WP_DEBUG') && WP_DEBUG, |
| 47 |
'is_ssl' => is_ssl(), |
| 48 |
'is_multisite' => is_multisite(), |
| 49 |
'is_network_activated' => $this->is_active_for_network(), |
| 50 |
'is_wpcom' => defined('IS_WPCOM') && IS_WPCOM, |
| 51 |
'is_wpcom_vip' => (defined('WPCOM_IS_VIP_ENV') && WPCOM_IS_VIP_ENV) || (function_exists('wpcom_is_vip') && wpcom_is_vip()), |
| 52 |
'is_wp_cache' => defined('WP_CACHE') && WP_CACHE, |
| 53 |
'sites_count' => $this->get_sites_total(), |
| 54 |
'active_plugins' => $this->get_active_plugins(), |
| 55 |
'theme_name' => $theme_data->get('Name'), |
| 56 |
'theme_version' => $theme_data->get('Version'), |
| 57 |
'locale' => get_locale(), |
| 58 |
'timezone_offset' => wp_timezone_string(), |
| 59 |
// FireBox Specific Data |
| 60 |
'firebox_version' => FBOX_VERSION, |
| 61 |
'firebox_license_key' => get_option('firebox_license_key', ''), |
| 62 |
'firebox_license_type' => FBOX_LICENSE_TYPE, |
| 63 |
'firebox_license_status' => get_option('firebox_license_status', ''), |
| 64 |
'firebox_is_pro' => FBOX_LICENSE_TYPE === 'pro', |
| 65 |
'firebox_views' => $this->pluginData->getViews(), |
| 66 |
'firebox_dimensions' => $this->pluginData->getDimensionsData(), |
| 67 |
'firebox_campaigns_published' => $this->pluginData->getCampaigns('publish'), |
| 68 |
'firebox_campaigns_draft' => $this->pluginData->getCampaigns('draft'), |
| 69 |
'firebox_campaigns_trash' => $this->pluginData->getCampaigns('trash'), |
| 70 |
'firebox_submissions' => $this->pluginData->getSubmissions(), |
| 71 |
'firebox_classic_campaigns' => $this->pluginData->getTotalsBySetting('mode', 'popup'), |
| 72 |
'firebox_pageslide_campaigns' => $this->pluginData->getTotalsBySetting('mode', 'pageslide'), |
| 73 |
'firebox_embed_campaigns' => $this->pluginData->getTotalsBySetting('mode', 'embed'), |
| 74 |
'firebox_campaigns_pageready' => $this->pluginData->getTotalsBySetting('triggermethod', 'pageready'), |
| 75 |
'firebox_campaigns_pageload' => $this->pluginData->getTotalsBySetting('triggermethod', 'pageload'), |
| 76 |
'firebox_campaigns_scroll_depth' => $this->pluginData->getTotalsBySetting('triggermethod', 'pageheight'), |
| 77 |
'firebox_campaigns_element_visibility' => $this->pluginData->getTotalsBySetting('triggermethod', 'element'), |
| 78 |
'firebox_campaigns_exit_intent' => $this->pluginData->getTotalsBySetting('triggermethod', 'userleave'), |
| 79 |
'firebox_campaigns_click' => $this->pluginData->getTotalsBySetting('triggermethod', 'onclick'), |
| 80 |
'firebox_campaigns_external_link_click' => $this->pluginData->getTotalsBySetting('triggermethod', 'onexternallink'), |
| 81 |
'firebox_campaigns_hover' => $this->pluginData->getTotalsBySetting('triggermethod', 'elementHover'), |
| 82 |
'firebox_campaigns_adblock_detect' => $this->pluginData->getTotalsBySetting('triggermethod', 'onAdBlockDetect'), |
| 83 |
'firebox_campaigns_idle' => $this->pluginData->getTotalsBySetting('triggermethod', 'onIdle'), |
| 84 |
'firebox_campaigns_floating_button' => $this->pluginData->getTotalsBySetting('triggermethod', 'floatingbutton'), |
| 85 |
'firebox_campaigns_manual' => $this->pluginData->getTotalsBySetting('triggermethod', 'ondemand'), |
| 86 |
'firebox_show_frequency_always' => $this->pluginData->getTotalsBySetting('assign_impressions_param_type', 'always'), |
| 87 |
'firebox_show_frequency_session' => $this->pluginData->getTotalsBySetting('assign_impressions_param_type', 'session'), |
| 88 |
'firebox_show_frequency_day' => $this->pluginData->getTotalsBySetting('assign_impressions_param_type', 'day'), |
| 89 |
'firebox_show_frequency_week' => $this->pluginData->getTotalsBySetting('assign_impressions_param_type', 'week'), |
| 90 |
'firebox_show_frequency_custom' => $this->pluginData->getTotalsBySetting('assign_impressions_param_type', 'custom'), |
| 91 |
'firebox_cookie_never' => $this->pluginData->getTotalsBySetting('assign_cookietype', 'never'), |
| 92 |
'firebox_cookie_ever' => $this->pluginData->getTotalsBySetting('assign_cookietype', 'ever'), |
| 93 |
'firebox_cookie_session' => $this->pluginData->getTotalsBySetting('assign_cookietype', 'session'), |
| 94 |
'firebox_cookie_custom' => $this->pluginData->getTotalsBySetting('assign_cookietype', 'custom'), |
| 95 |
'firebox_auto_close' => $this->pluginData->getTotalsBySetting('box_auto_close', 'yes'), |
| 96 |
'firebox_auto_focus' => $this->pluginData->getTotalsBySetting('autofocus', '1'), |
| 97 |
'firebox_close_with_esc' => $this->pluginData->getTotalsBySetting('close_on_esc', '1'), |
| 98 |
'firebox_display_conditions_all' => $this->pluginData->getTotalsBySetting('display_conditions_type', 'all'), |
| 99 |
'firebox_display_conditions_mirror' => $this->pluginData->getTotalsBySetting('display_conditions_type', 'mirror'), |
| 100 |
'firebox_display_conditions_custom' => $this->pluginData->getTotalsBySetting('display_conditions_type', 'custom'), |
| 101 |
'firebox_campaigns_with_sound' => $this->pluginData->getTotalsBySetting('opening_sound.source', 'cond:not:none'), |
| 102 |
'firebox_cond_date' => $this->pluginData->getTotalsByCondition('Date\Date'), |
| 103 |
'firebox_cond_day_of_week' => $this->pluginData->getTotalsByCondition('Date\Day'), |
| 104 |
'firebox_cond_month' => $this->pluginData->getTotalsByCondition('Date\Month'), |
| 105 |
'firebox_cond_time' => $this->pluginData->getTotalsByCondition('Date\Time'), |
| 106 |
'firebox_cond_user' => $this->pluginData->getTotalsByCondition('WP\UserID'), |
| 107 |
'firebox_cond_menu' => $this->pluginData->getTotalsByCondition('WP\Menu'), |
| 108 |
'firebox_cond_user_group' => $this->pluginData->getTotalsByCondition('WP\UserGroup'), |
| 109 |
'firebox_cond_post' => $this->pluginData->getTotalsByCondition('WP\Posts'), |
| 110 |
'firebox_cond_page' => $this->pluginData->getTotalsByCondition('WP\Pages'), |
| 111 |
'firebox_cond_post_tag' => $this->pluginData->getTotalsByCondition('WP\Tags'), |
| 112 |
'firebox_cond_post_category' => $this->pluginData->getTotalsByCondition('WP\Categories'), |
| 113 |
'firebox_cond_cpt' => $this->pluginData->getTotalsByCondition('WP\CustomPostTypes'), |
| 114 |
'firebox_cond_homepage' => $this->pluginData->getTotalsByCondition('WP\Homepage'), |
| 115 |
'firebox_cond_device' => $this->pluginData->getTotalsByCondition('Device'), |
| 116 |
'firebox_cond_browser' => $this->pluginData->getTotalsByCondition('Browser'), |
| 117 |
'firebox_cond_os' => $this->pluginData->getTotalsByCondition('OS'), |
| 118 |
'firebox_cond_city' => $this->pluginData->getTotalsByCondition('Geo\City'), |
| 119 |
'firebox_cond_country' => $this->pluginData->getTotalsByCondition('Geo\Country'), |
| 120 |
'firebox_cond_region' => $this->pluginData->getTotalsByCondition('Geo\Region'), |
| 121 |
'firebox_cond_continent' => $this->pluginData->getTotalsByCondition('Geo\Continent'), |
| 122 |
'firebox_cond_fb_view_campaign' => $this->pluginData->getTotalsByCondition('FireBox\Popup'), |
| 123 |
'firebox_cond_fb_submitted_form' => $this->pluginData->getTotalsByCondition('FireBox\Form'), |
| 124 |
'firebox_cond_edd_products_in_cart' => $this->pluginData->getTotalsByCondition('EDD\CartContainsProducts'), |
| 125 |
'firebox_cond_edd_cart_items_count' => $this->pluginData->getTotalsByCondition('EDD\CartContainsXProducts'), |
| 126 |
'firebox_cond_edd_amount_in_cart' => $this->pluginData->getTotalsByCondition('EDD\CartValue'), |
| 127 |
'firebox_cond_edd_current_product' => $this->pluginData->getTotalsByCondition('EDD\Product'), |
| 128 |
'firebox_cond_edd_purchased_product' => $this->pluginData->getTotalsByCondition('EDD\PurchasedProduct'), |
| 129 |
'firebox_cond_edd_last_purchased_date' => $this->pluginData->getTotalsByCondition('EDD\LastPurchaseDate'), |
| 130 |
'firebox_cond_edd_current_product_price' => $this->pluginData->getTotalsByCondition('EDD\CurrentProductPrice'), |
| 131 |
'firebox_cond_edd_total_spend' => $this->pluginData->getTotalsByCondition('EDD\TotalSpend'), |
| 132 |
'firebox_cond_edd_current_product_category' => $this->pluginData->getTotalsByCondition('EDD\Category'), |
| 133 |
'firebox_cond_edd_category' => $this->pluginData->getTotalsByCondition('EDD\CategoryView'), |
| 134 |
'firebox_cond_woo_products_in_cart' => $this->pluginData->getTotalsByCondition('WooCommerce\CartContainsProducts'), |
| 135 |
'firebox_cond_woo_cart_items_count' => $this->pluginData->getTotalsByCondition('WooCommerce\CartContainsXProducts'), |
| 136 |
'firebox_cond_woo_amount_in_cart' => $this->pluginData->getTotalsByCondition('WooCommerce\CartValue'), |
| 137 |
'firebox_cond_woo_current_product' => $this->pluginData->getTotalsByCondition('WooCommerce\Product'), |
| 138 |
'firebox_cond_woo_purchased_product' => $this->pluginData->getTotalsByCondition('WooCommerce\PurchasedProduct'), |
| 139 |
'firebox_cond_woo_last_purchased_date' => $this->pluginData->getTotalsByCondition('WooCommerce\LastPurchaseDate'), |
| 140 |
'firebox_cond_woo_current_product_price' => $this->pluginData->getTotalsByCondition('WooCommerce\CurrentProductPrice'), |
| 141 |
'firebox_cond_woo_total_spend' => $this->pluginData->getTotalsByCondition('WooCommerce\TotalSpend'), |
| 142 |
'firebox_cond_woo_current_product_category' => $this->pluginData->getTotalsByCondition('WooCommerce\Category'), |
| 143 |
'firebox_cond_woo_category' => $this->pluginData->getTotalsByCondition('WooCommerce\CategoryView'), |
| 144 |
'firebox_cond_url' => $this->pluginData->getTotalsByCondition('URL'), |
| 145 |
'firebox_cond_referrer' => $this->pluginData->getTotalsByCondition('Referrer'), |
| 146 |
'firebox_cond_ip' => $this->pluginData->getTotalsByCondition('IP'), |
| 147 |
'firebox_cond_pageviews' => $this->pluginData->getTotalsByCondition('Pageviews'), |
| 148 |
'firebox_cond_cookies' => $this->pluginData->getTotalsByCondition('Cookie'), |
| 149 |
'firebox_cond_php' => $this->pluginData->getTotalsByCondition('PHP'), |
| 150 |
'firebox_cond_wpml_language' => $this->pluginData->getTotalsByCondition('Language'), |
| 151 |
'firebox_cond_timeonsite' => $this->pluginData->getTotalsByCondition('TimeOnSite'), |
| 152 |
'firebox_cond_new_returning_visitor' => $this->pluginData->getTotalsByCondition('NewReturningVisitor'), |
| 153 |
'firebox_actions' => $this->pluginData->getTotalsBySetting('actions', 'cond:not:emptyArray'), |
| 154 |
'firebox_php_scripts_on_before' => $this->pluginData->getTotalsBySetting('phpscripts.beforerender', 'cond:not:empty'), |
| 155 |
'firebox_php_scripts_on_after' => $this->pluginData->getTotalsBySetting('phpscripts.afterrender', 'cond:not:empty'), |
| 156 |
'firebox_php_scripts_on_open' => $this->pluginData->getTotalsBySetting('phpscripts.open', 'cond:not:empty'), |
| 157 |
'firebox_php_scripts_on_close' => $this->pluginData->getTotalsBySetting('phpscripts.close', 'cond:not:empty'), |
| 158 |
'firebox_php_scripts_on_form_success' => $this->pluginData->getTotalsBySetting('phpscripts.formsuccess', 'cond:not:empty'), |
| 159 |
'firebox_custom_css' => $this->pluginData->getTotalsBySetting('customcss', 'cond:not:empty'), |
| 160 |
'firebox_custom_javascript' => $this->pluginData->getTotalsBySetting('customcode', 'cond:not:empty'), |
| 161 |
'firebox_test_mode' => $this->pluginData->getTotalsBySetting('testmode', '1'), |
| 162 |
'firebox_prevent_page_scrollling' => $this->pluginData->getTotalsBySetting('preventpagescroll', '1'), |
| 163 |
'firebox_settings' => $this->getSettings() |
| 164 |
]; |
| 165 |
|
| 166 |
return $payload; |
| 167 |
} |
| 168 |
|
| 169 |
private function getDatabaseType() |
| 170 |
{ |
| 171 |
global $wpdb; |
| 172 |
|
| 173 |
if (is_object($wpdb->dbh)) |
| 174 |
{ |
| 175 |
// mysqli or PDO |
| 176 |
$extension = get_class($wpdb->dbh); |
| 177 |
} |
| 178 |
else |
| 179 |
{ |
| 180 |
// Unknown sql extension |
| 181 |
$extension = null; |
| 182 |
} |
| 183 |
|
| 184 |
return $extension; |
| 185 |
} |
| 186 |
|
| 187 |
private function getSettings() |
| 188 |
{ |
| 189 |
return array_diff_key( |
| 190 |
get_option('firebox_settings', []), |
| 191 |
array_flip( |
| 192 |
[ |
| 193 |
'api_key', |
| 194 |
'geo_license_key', |
| 195 |
'license_key', |
| 196 |
'cloudflare_turnstile_site_key', |
| 197 |
'cloudflare_turnstile_secret_key', |
| 198 |
'recaptcha_v2_checkbox_site_key', |
| 199 |
'recaptcha_v2_checkbox_secret_key', |
| 200 |
'recaptcha_v2_invisible_site_key', |
| 201 |
'recaptcha_v2_invisible_secret_key', |
| 202 |
'recaptcha_v3_site_key', |
| 203 |
'recaptcha_v3_secret_key', |
| 204 |
'hcaptcha_site_key', |
| 205 |
'hcaptcha_secret_key', |
| 206 |
'openai_api_key', |
| 207 |
'stripe_test_secret_key', |
| 208 |
'stripe_test_publishable_key', |
| 209 |
'stripe_live_secret_key', |
| 210 |
'stripe_live_publishable_key', |
| 211 |
'stripe_webhooks_secret_test', |
| 212 |
'stripe_webhooks_secret_live', |
| 213 |
'stripe_webhooks_id_test', |
| 214 |
'stripe_webhooks_id_live', |
| 215 |
] |
| 216 |
) |
| 217 |
); |
| 218 |
} |
| 219 |
|
| 220 |
/** |
| 221 |
* Determines whether the plugin is active for the entire network. |
| 222 |
* |
| 223 |
* @return bool |
| 224 |
*/ |
| 225 |
private function is_active_for_network() |
| 226 |
{ |
| 227 |
// Stop if not multisite |
| 228 |
if (!is_multisite()) |
| 229 |
{ |
| 230 |
return false; |
| 231 |
} |
| 232 |
|
| 233 |
// Get all active plugins |
| 234 |
$plugins = get_site_option('active_sitewide_plugins'); |
| 235 |
|
| 236 |
// Stop if the plugin is active for the entire network |
| 237 |
if (isset($plugins[plugin_basename(FBOX_PLUGIN_BASE_FILE)])) |
| 238 |
{ |
| 239 |
return true; |
| 240 |
} |
| 241 |
|
| 242 |
return false; |
| 243 |
} |
| 244 |
|
| 245 |
/** |
| 246 |
* Total number of sites. |
| 247 |
* |
| 248 |
* @return int |
| 249 |
*/ |
| 250 |
private function get_sites_total() |
| 251 |
{ |
| 252 |
return function_exists('get_blog_count') ? (int) get_blog_count() : 1; |
| 253 |
} |
| 254 |
|
| 255 |
/** |
| 256 |
* Get the list of active plugins. |
| 257 |
* |
| 258 |
* @return array |
| 259 |
*/ |
| 260 |
private function get_active_plugins() |
| 261 |
{ |
| 262 |
if (!function_exists('get_plugins')) |
| 263 |
{ |
| 264 |
include ABSPATH . '/wp-admin/includes/plugin.php'; |
| 265 |
} |
| 266 |
|
| 267 |
$active = is_multisite() ? |
| 268 |
array_merge(get_option('active_plugins', []), array_flip(get_site_option('active_sitewide_plugins', []))) : |
| 269 |
get_option('active_plugins', []); |
| 270 |
$plugins = array_intersect_key(get_plugins(), array_flip($active)); |
| 271 |
|
| 272 |
return array_map( |
| 273 |
static function ($plugin) |
| 274 |
{ |
| 275 |
if (isset($plugin['Version'])) |
| 276 |
{ |
| 277 |
return $plugin['Version']; |
| 278 |
} |
| 279 |
|
| 280 |
return 'Not Set'; |
| 281 |
}, |
| 282 |
$plugins |
| 283 |
); |
| 284 |
} |
| 285 |
|
| 286 |
/** |
| 287 |
* Return the User Agent used in the API request. |
| 288 |
* |
| 289 |
* @return string |
| 290 |
*/ |
| 291 |
public function get_user_agent() |
| 292 |
{ |
| 293 |
return 'FireBox/' . FBOX_VERSION . '; ' . get_bloginfo('url'); |
| 294 |
} |
| 295 |
} |