tigerstyle-heat/includes/modules/class-ecosystem-coordinator.php
Ryan Malloy 0028738e33 Initial commit: TigerStyle Heat v2.0.0
Make your WordPress site irresistible. Natural SEO attraction with:
- robots.txt management
- sitemap.xml generation
- LLMs.txt support
- Google integration (Analytics, Search Console, Tag Manager)
- Schema.org structured data
- Open Graph / Twitter Card meta tags
- AMP support
- Visual elements gallery
- Built-in backup/restore module

Includes build.sh and .distignore for WordPress-installable release ZIPs.
2026-05-27 13:41:35 -06:00

393 lines
14 KiB
PHP

<?php
/**
* TigerStyle Ecosystem Coordinator
*
* Central coordination hub for all TigerStyle plugins
* Handles cross-plugin communication, preferences, and data sharing
*/
// Prevent direct access
if (!defined('ABSPATH')) {
exit;
}
class TigerStyleSEO_EcosystemCoordinator {
/**
* Single instance
*/
private static $instance = null;
/**
* Registered TigerStyle plugins
*/
private $registered_plugins = array();
/**
* Shared user preferences
*/
private $shared_preferences = array();
/**
* Get instance
*/
public static function instance() {
if (is_null(self::$instance)) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Constructor
*/
private function __construct() {
$this->init();
}
/**
* Initialize the coordinator
*/
private function init() {
// Register Heat as the coordinator
$this->register_plugin('heat', array(
'name' => 'TigerStyle Heat',
'version' => TIGERSTYLE_HEAT_VERSION,
'role' => 'coordinator',
'capabilities' => array('analytics', 'seo', 'performance')
));
// Hook into WordPress
add_action('init', array($this, 'discover_ecosystem_plugins'));
add_action('wp_ajax_tigerstyle_sync_preferences', array($this, 'handle_preference_sync'));
add_action('wp_ajax_nopriv_tigerstyle_sync_preferences', array($this, 'handle_preference_sync'));
// Frontend coordination
add_action('wp_head', array($this, 'inject_ecosystem_coordination'), 1);
// Admin coordination
if (is_admin()) {
add_action('admin_enqueue_scripts', array($this, 'enqueue_ecosystem_scripts'));
}
// Plugin communication hooks
add_action('tigerstyle_ecosystem_register_plugin', array($this, 'register_plugin_from_hook'), 10, 2);
add_action('tigerstyle_ecosystem_sync_preferences', array($this, 'sync_preferences_from_hook'));
console.log('🔥 TigerStyle Heat: Ecosystem coordinator initialized!');
}
/**
* Discover other TigerStyle plugins in the ecosystem
*/
public function discover_ecosystem_plugins() {
// Check for TigerStyle Whiskers
if (class_exists('TigerStyleWhiskers')) {
$this->register_plugin('whiskers', array(
'name' => 'TigerStyle Whiskers',
'version' => defined('TIGERSTYLE_WHISKERS_VERSION') ? TIGERSTYLE_WHISKERS_VERSION : '1.0.0',
'role' => 'privacy',
'capabilities' => array('gdpr', 'consent', 'privacy')
));
}
// Check for TigerStyle Dash
if (class_exists('TigerStyleDash')) {
$this->register_plugin('dash', array(
'name' => 'TigerStyle Dash',
'version' => defined('TIGERSTYLE_DASH_VERSION') ? TIGERSTYLE_DASH_VERSION : '1.0.0',
'role' => 'performance',
'capabilities' => array('caching', 'optimization', 'speed')
));
}
// Check for TigerStyle Life9
if (class_exists('TigerStyleLife9')) {
$this->register_plugin('life9', array(
'name' => 'TigerStyle Life9',
'version' => defined('TIGERSTYLE_LIFE9_VERSION') ? TIGERSTYLE_LIFE9_VERSION : '1.0.0',
'role' => 'backup',
'capabilities' => array('backup', 'restore', 'disaster_recovery')
));
}
// Check for TigerStyle Scent
if (class_exists('TigerStyleScent')) {
$this->register_plugin('scent', array(
'name' => 'TigerStyle Scent',
'version' => defined('TIGERSTYLE_SCENT_VERSION') ? TIGERSTYLE_SCENT_VERSION : '1.0.0',
'role' => 'auth',
'capabilities' => array('oauth2', 'api', 'authentication')
));
}
// Allow other plugins to register
do_action('tigerstyle_ecosystem_discovery', $this);
}
/**
* Register a plugin in the ecosystem
*/
public function register_plugin($plugin_id, $plugin_data) {
$this->registered_plugins[$plugin_id] = array_merge(array(
'name' => '',
'version' => '1.0.0',
'role' => 'member',
'capabilities' => array(),
'registered_at' => current_time('timestamp')
), $plugin_data);
// Trigger ecosystem update
do_action('tigerstyle_ecosystem_plugin_registered', $plugin_id, $plugin_data);
}
/**
* Register plugin from hook
*/
public function register_plugin_from_hook($plugin_id, $plugin_data) {
$this->register_plugin($plugin_id, $plugin_data);
}
/**
* Get all registered plugins
*/
public function get_registered_plugins() {
return $this->registered_plugins;
}
/**
* Get specific plugin info
*/
public function get_plugin_info($plugin_id) {
return isset($this->registered_plugins[$plugin_id]) ? $this->registered_plugins[$plugin_id] : null;
}
/**
* Sync user preferences across plugins
*/
public function sync_user_preferences($user_id, $preferences = array()) {
// Get current preferences
$current_prefs = get_user_meta($user_id, 'tigerstyle_ecosystem_preferences', true);
if (!is_array($current_prefs)) {
$current_prefs = array();
}
// Merge new preferences
$updated_prefs = array_merge($current_prefs, $preferences);
// Save updated preferences
update_user_meta($user_id, 'tigerstyle_ecosystem_preferences', $updated_prefs);
// Trigger sync across plugins
do_action('tigerstyle_ecosystem_preferences_updated', $user_id, $updated_prefs);
// Return updated preferences
return $updated_prefs;
}
/**
* Get user preferences
*/
public function get_user_preferences($user_id, $preference_key = null) {
$prefs = get_user_meta($user_id, 'tigerstyle_ecosystem_preferences', true);
if (!is_array($prefs)) {
$prefs = array();
}
if ($preference_key) {
return isset($prefs[$preference_key]) ? $prefs[$preference_key] : null;
}
return $prefs;
}
/**
* Handle AJAX preference sync
*/
public function handle_preference_sync() {
// Verify nonce
if (!wp_verify_nonce($_POST['nonce'], 'tigerstyle_ecosystem_sync')) {
wp_die(json_encode(array('success' => false, 'message' => 'Invalid nonce')));
}
$user_id = get_current_user_id();
if (!$user_id) {
wp_die(json_encode(array('success' => false, 'message' => 'User not logged in')));
}
$preferences = isset($_POST['preferences']) ? $_POST['preferences'] : array();
// Sanitize preferences
$sanitized_prefs = array();
foreach ($preferences as $key => $value) {
$sanitized_prefs[sanitize_key($key)] = sanitize_text_field($value);
}
// Sync preferences
$updated_prefs = $this->sync_user_preferences($user_id, $sanitized_prefs);
wp_die(json_encode(array(
'success' => true,
'preferences' => $updated_prefs,
'ecosystem' => $this->get_registered_plugins()
)));
}
/**
* Sync preferences from hook
*/
public function sync_preferences_from_hook($preferences) {
$user_id = get_current_user_id();
if ($user_id) {
$this->sync_user_preferences($user_id, $preferences);
}
}
/**
* Inject ecosystem coordination script
*/
public function inject_ecosystem_coordination() {
$ecosystem_data = array(
'plugins' => $this->get_registered_plugins(),
'ajaxurl' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('tigerstyle_ecosystem_sync'),
'user_id' => get_current_user_id()
);
// Get user preferences if logged in
if (get_current_user_id()) {
$ecosystem_data['user_preferences'] = $this->get_user_preferences(get_current_user_id());
}
echo "\n<!-- TigerStyle Ecosystem Coordination -->\n";
echo '<script>' . "\n";
echo 'window.tigerstyleEcosystem = ' . json_encode($ecosystem_data) . ';' . "\n";
echo '
// TigerStyle Ecosystem JavaScript API
window.tigerstyleEcosystem.syncPreferences = function(preferences, callback) {
if (!window.tigerstyleEcosystem.user_id) {
console.warn("🐅 TigerStyle Ecosystem: User not logged in, cannot sync preferences");
return;
}
var xhr = new XMLHttpRequest();
xhr.open("POST", window.tigerstyleEcosystem.ajaxurl);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
try {
var response = JSON.parse(xhr.responseText);
if (response.success) {
window.tigerstyleEcosystem.user_preferences = response.preferences;
console.log("🐅 TigerStyle Ecosystem: Preferences synced!", response.preferences);
// Trigger ecosystem update event
if (typeof window.CustomEvent === "function") {
document.dispatchEvent(new CustomEvent("tigerstyleEcosystemUpdated", {
detail: response
}));
}
if (callback) callback(response);
}
} catch (e) {
console.error("🐅 TigerStyle Ecosystem: Error parsing sync response", e);
}
}
};
var params = "action=tigerstyle_sync_preferences&nonce=" + encodeURIComponent(window.tigerstyleEcosystem.nonce);
for (var key in preferences) {
params += "&preferences[" + encodeURIComponent(key) + "]=" + encodeURIComponent(preferences[key]);
}
xhr.send(params);
};
// Get user preference
window.tigerstyleEcosystem.getPreference = function(key, defaultValue) {
if (!window.tigerstyleEcosystem.user_preferences) return defaultValue;
return window.tigerstyleEcosystem.user_preferences[key] || defaultValue;
};
// Check if plugin is active in ecosystem
window.tigerstyleEcosystem.hasPlugin = function(pluginId) {
return window.tigerstyleEcosystem.plugins.hasOwnProperty(pluginId);
};
// Get plugin capabilities
window.tigerstyleEcosystem.getPluginCapabilities = function(pluginId) {
return window.tigerstyleEcosystem.plugins[pluginId] ? window.tigerstyleEcosystem.plugins[pluginId].capabilities : [];
};
console.log("🔥 TigerStyle Ecosystem Coordination Active! Plugins: " + Object.keys(window.tigerstyleEcosystem.plugins).join(", "));
';
echo '</script>' . "\n";
echo "<!-- End TigerStyle Ecosystem Coordination -->\n";
}
/**
* Enqueue ecosystem scripts for admin
*/
public function enqueue_ecosystem_scripts($hook) {
// Only load on TigerStyle admin pages
if (strpos($hook, 'tigerstyle') === false) {
return;
}
wp_enqueue_script('jquery');
// Inline ecosystem admin script
$script = '
jQuery(document).ready(function($) {
// Add ecosystem status to admin pages
if (window.tigerstyleEcosystem && Object.keys(window.tigerstyleEcosystem.plugins).length > 1) {
var ecosystemHtml = \'<div class="notice notice-success" style="background: linear-gradient(135deg, #ff6b35 0%, #f7931e 100%); color: white; border: none;">\';
ecosystemHtml += \'<p><strong>🐅 TigerStyle Ecosystem Active!</strong> \';
ecosystemHtml += Object.keys(window.tigerstyleEcosystem.plugins).length + \' plugins coordinating: \';
ecosystemHtml += Object.keys(window.tigerstyleEcosystem.plugins).map(function(id) {
return window.tigerstyleEcosystem.plugins[id].name;
}).join(", ");
ecosystemHtml += \'</p></div>\';
$(".wrap h1").after(ecosystemHtml);
}
});
';
wp_add_inline_script('jquery', $script);
}
/**
* Get ecosystem statistics
*/
public function get_ecosystem_stats() {
return array(
'total_plugins' => count($this->registered_plugins),
'coordinator_version' => TIGERSTYLE_HEAT_VERSION,
'registered_plugins' => $this->registered_plugins,
'capabilities' => $this->get_all_capabilities(),
'last_sync' => get_option('tigerstyle_ecosystem_last_sync', 0)
);
}
/**
* Get all capabilities across the ecosystem
*/
private function get_all_capabilities() {
$all_capabilities = array();
foreach ($this->registered_plugins as $plugin_id => $plugin_data) {
$all_capabilities = array_merge($all_capabilities, $plugin_data['capabilities']);
}
return array_unique($all_capabilities);
}
/**
* Force ecosystem sync
*/
public function force_ecosystem_sync() {
update_option('tigerstyle_ecosystem_last_sync', current_time('timestamp'));
do_action('tigerstyle_ecosystem_force_sync');
}
}