Files
igny8/igy8-wp-plugin/admin/settings.php
alorig 8296685fbd asd
2025-11-22 19:46:34 +05:00

772 lines
46 KiB
PHP

<?php
/**
* Settings Page Template
*
* @package Igny8Bridge
*/
// Prevent direct access
if (!defined('ABSPATH')) {
exit;
}
// Get current settings
$email = get_option('igny8_email', '');
$site_id = get_option('igny8_site_id', '');
$access_token = function_exists('igny8_get_secure_option') ? igny8_get_secure_option('igny8_access_token') : get_option('igny8_access_token');
$is_connected = !empty($access_token);
$api_key = function_exists('igny8_get_secure_option') ? igny8_get_secure_option('igny8_api_key') : get_option('igny8_api_key');
$date_format = get_option('date_format');
$time_format = get_option('time_format');
$now = current_time('timestamp');
$token_issued = intval(get_option('igny8_access_token_issued', 0));
$token_age_text = $token_issued ? sprintf(__('%s ago', 'igny8-bridge'), human_time_diff($token_issued, $now)) : __('Not generated yet', 'igny8-bridge');
$token_issued_formatted = $token_issued ? date_i18n($date_format . ' ' . $time_format, $token_issued) : __('—', 'igny8-bridge');
$last_health_check = intval(get_option('igny8_last_api_health_check', 0));
$last_health_check_formatted = $last_health_check ? date_i18n($date_format . ' ' . $time_format, $last_health_check) : __('Never', 'igny8-bridge');
$last_site_sync = intval(get_option('igny8_last_site_sync', 0));
$last_site_sync_formatted = $last_site_sync ? date_i18n($date_format . ' ' . $time_format, $last_site_sync) : __('Never', 'igny8-bridge');
$last_taxonomy_sync = intval(get_option('igny8_last_taxonomy_sync', 0));
$last_taxonomy_sync_formatted = $last_taxonomy_sync ? date_i18n($date_format . ' ' . $time_format, $last_taxonomy_sync) : __('Never', 'igny8-bridge');
$last_keyword_sync = intval(get_option('igny8_last_keyword_sync', 0));
$last_keyword_sync_formatted = $last_keyword_sync ? date_i18n($date_format . ' ' . $time_format, $last_keyword_sync) : __('Never', 'igny8-bridge');
$last_writer_sync = intval(get_option('igny8_last_writer_sync', 0));
$last_writer_sync_formatted = $last_writer_sync ? date_i18n($date_format . ' ' . $time_format, $last_writer_sync) : __('Never', 'igny8-bridge');
$last_full_site_scan = intval(get_option('igny8_last_full_site_scan', 0));
$last_full_site_scan_formatted = $last_full_site_scan ? date_i18n($date_format . ' ' . $time_format, $last_full_site_scan) : __('Never', 'igny8-bridge');
$last_semantic_map = intval(get_option('igny8_last_semantic_map', 0));
$last_semantic_map_formatted = $last_semantic_map ? date_i18n($date_format . ' ' . $time_format, $last_semantic_map) : __('Never', 'igny8-bridge');
$semantic_summary = get_option('igny8_last_semantic_map_summary', array());
$next_site_sync = wp_next_scheduled('igny8_sync_site_data');
$next_site_sync_formatted = $next_site_sync ? date_i18n($date_format . ' ' . $time_format, $next_site_sync) : __('Not scheduled', 'igny8-bridge');
$available_post_types = igny8_get_supported_post_types();
$enabled_post_types = igny8_get_enabled_post_types();
$available_taxonomies = igny8_get_supported_taxonomies();
$enabled_taxonomies = igny8_get_enabled_taxonomies();
$control_mode = igny8_get_control_mode();
$woocommerce_enabled = (int) get_option('igny8_enable_woocommerce', class_exists('WooCommerce') ? 1 : 0);
$woocommerce_detected = class_exists('WooCommerce');
$available_modules = igny8_get_available_modules();
$enabled_modules = igny8_get_enabled_modules();
$connection_enabled = igny8_is_connection_enabled();
$webhook_secret = igny8_get_webhook_secret();
$webhook_url = rest_url('igny8/v1/event');
$link_queue = get_option('igny8_link_queue', array());
$pending_links = array_filter($link_queue, function($item) {
return $item['status'] === 'pending';
});
$webhook_logs = igny8_get_webhook_logs(array('limit' => 10));
$two_way_sync = (int) get_option('igny8_enable_two_way_sync', 1);
?>
<div class="wrap">
<h1><?php echo esc_html(get_admin_page_title()); ?></h1>
<?php settings_errors('igny8_settings'); ?>
<div class="notice notice-info inline" style="margin-top:10px;">
<p>
<strong><?php _e('Integration modes explained:', 'igny8-bridge'); ?></strong><br />
<?php _e('• Enable Sync Operations: controls whether background and manual sync actions occur (cron jobs, webhooks, sync buttons).', 'igny8-bridge'); ?><br />
<?php _e('• Enable Two-Way Sync: controls whether bi-directional syncing (IGNY8 → WordPress and WordPress → IGNY8) is permitted. Disabling this will suppress sync actions but API endpoints remain accessible for discovery and diagnostics.', 'igny8-bridge'); ?>
</p>
</div>
<div class="igny8-settings-container">
<div class="igny8-settings-card">
<h2>
<svg width="20" height="20" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" style="vertical-align: middle; margin-right: 8px; display: inline;">
<path stroke-linecap="round" stroke-linejoin="round" d="M13.828 10.172a4 4 0 00-5.656 0l-4 4a4 4 0 105.656 5.656l1.102-1.101m-.758-4.899a4 4 0 005.658 0l4-4a4 4 0 00-5.656-5.656l-1.1 1.1"/>
</svg>
<?php _e('API Connection', 'igny8-bridge'); ?>
</h2>
<?php if (!$is_connected) : ?>
<div class="igny8-connection-status-display">
<div class="igny8-status-label"><?php _e('Status', 'igny8-bridge'); ?></div>
<div class="igny8-status-value">
<span class="igny8-status-indicator disconnected"></span>
<span style="color: #6B7280;"><?php _e('Not Connected', 'igny8-bridge'); ?></span>
</div>
</div>
<form method="post" action="">
<?php wp_nonce_field('igny8_settings_nonce'); ?>
<div class="igny8-api-form-group">
<label for="igny8_site_id">
<?php _e('Site ID', 'igny8-bridge'); ?>
<span style="color: #EF4444;">*</span>
</label>
<input
type="text"
id="igny8_site_id"
name="igny8_site_id"
value=""
placeholder="<?php _e('e.g., 123', 'igny8-bridge'); ?>"
required
/>
<p class="igny8-api-form-description">
<?php _e('The numeric Site ID from your IGNY8 app. You can find it in several ways:', 'igny8-bridge'); ?>
</p>
<ul style="margin-left: 20px; margin-top: 8px; color: #6B7280;">
<li><?php _e('In the Site Settings page URL: look for a number after "/sites/" (e.g., https://app.igny8.com/sites/123/settings → Site ID is 123)', 'igny8-bridge'); ?></li>
<li><?php _e('In your IGNY8 dashboard: navigate to Settings → Sites, and the Site ID is displayed next to each site', 'igny8-bridge'); ?></li>
<li><?php _e('From your account admin: contact your IGNY8 account administrator if you need help finding your Site ID', 'igny8-bridge'); ?></li>
</ul>
</div>
<div class="igny8-api-form-group">
<label for="igny8_api_key">
<?php _e('API Key', 'igny8-bridge'); ?>
<span style="color: #EF4444;">*</span>
</label>
<input
type="text"
id="igny8_api_key"
name="igny8_api_key"
value=""
placeholder="<?php _e('sk_live_xxxxxxxxxxxxx', 'igny8-bridge'); ?>"
required
/>
<p class="igny8-api-form-description">
<?php printf(
__('Get your API key from the <a href="%s" target="_blank">IGNY8 app integrations page</a>. It starts with "sk_live_" or "sk_test_".', 'igny8-bridge'),
'https://app.igny8.com/sites/5/settings?tab=integrations'
); ?>
</p>
</div>
<div class="igny8-connection-actions">
<?php submit_button(__('Connect to IGNY8', 'igny8-bridge'), 'primary', 'igny8_connect'); ?>
</div>
</form>
<?php else : ?>
<div class="igny8-connection-status-display">
<div class="igny8-status-label"><?php _e('Status', 'igny8-bridge'); ?></div>
<div class="igny8-status-value">
<span class="igny8-status-indicator connected"></span>
<span style="color: var(--igny8-success);"><?php _e('Connected', 'igny8-bridge'); ?></span>
</div>
</div>
<div class="igny8-api-form-group">
<label><?php _e('Active API Key', 'igny8-bridge'); ?></label>
<div class="igny8-api-key-display">
<span class="igny8-api-key-mask"><?php echo esc_html(substr($api_key, 0, 7) . '••••••••••••' . substr($api_key, -7)); ?></span>
<span style="color: #10B981; font-weight: 500;">✓ <?php _e('Verified', 'igny8-bridge'); ?></span>
</div>
</div>
<div class="igny8-api-form-group">
<label><?php _e('Site ID', 'igny8-bridge'); ?></label>
<div style="padding: 10px 12px; background-color: #F9FAFB; border: 1px solid #E5E7EB; border-radius: 4px;">
<strong><?php echo esc_html($site_id ?: __('Not set', 'igny8-bridge')); ?></strong>
</div>
</div>
<div class="igny8-connection-actions" style="margin-top: 20px;">
<form method="post" action="">
<?php wp_nonce_field('igny8_revoke_api_key'); ?>
<button type="submit" name="igny8_revoke_api_key" class="button button-secondary" onclick="return confirm('<?php _e('Are you sure you want to disconnect? This will stop all syncing with IGNY8.', 'igny8-bridge'); ?>');">
<?php _e('Disconnect', 'igny8-bridge'); ?>
</button>
</form>
</div>
<?php endif; ?>
</div>
<?php if ($is_connected) : ?>
<div class="igny8-settings-card">
<h2>
<svg width="20" height="20" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" style="vertical-align: middle; margin-right: 8px; display: inline;">
<path stroke-linecap="round" stroke-linejoin="round" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"/>
</svg>
<?php _e('Communication Settings', 'igny8-bridge'); ?>
</h2>
<form method="post" action="options.php">
<?php settings_fields('igny8_bridge_connection'); ?>
<table class="form-table">
<tr>
<th scope="row">
<label for="igny8_connection_enabled"><?php _e('Enable Communication', 'igny8-bridge'); ?></label>
</th>
<td>
<label class="igny8-toggle-wrapper">
<input
type="checkbox"
id="igny8_connection_enabled"
name="igny8_connection_enabled"
value="1"
<?php checked($connection_enabled, 1); ?>
class="igny8-toggle-input"
/>
<span class="igny8-toggle-slider"></span>
<span class="igny8-toggle-label">
<?php if ($connection_enabled) : ?>
<strong style="color: #10B981;"><?php _e('Connected', 'igny8-bridge'); ?></strong>
<?php else : ?>
<strong style="color: #6B7280;"><?php _e('Disabled', 'igny8-bridge'); ?></strong>
<?php endif; ?>
</span>
</label>
<p class="description">
<?php _e('When enabled, the plugin will sync content and data with IGNY8. Disabling pauses all sync operations but keeps your API key stored.', 'igny8-bridge'); ?>
</p>
</td>
</tr>
</table>
<?php submit_button(__('Save Settings', 'igny8-bridge')); ?>
</form>
<div style="margin-top: 20px; padding-top: 20px; border-top: 1px solid #E5E7EB;">
<button type="button" id="igny8-test-connection" class="button" <?php disabled(!$connection_enabled); ?>>
<?php _e('Test Connection', 'igny8-bridge'); ?>
</button>
<span id="igny8-test-result" class="igny8-test-result"></span>
</div>
<?php if (defined('WP_DEBUG') && WP_DEBUG) : ?>
<p class="description" style="color: #0073aa; margin-top: 10px;">
<strong><?php _e('Debug Mode Active', 'igny8-bridge'); ?>:</strong>
<?php _e('Check wp-content/debug.log for detailed API request/response logs.', 'igny8-bridge'); ?>
</p>
<?php endif; ?>
</div>
<div class="igny8-settings-card">
<h2>
<svg width="20" height="20" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" style="vertical-align: middle; margin-right: 8px; display: inline;">
<path stroke-linecap="round" stroke-linejoin="round" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>
</svg>
<?php _e('Diagnostics', 'igny8-bridge'); ?>
</h2>
<div class="igny8-diagnostics-grid">
<div class="igny8-diagnostic-item">
<div class="igny8-diagnostic-label"><?php _e('Access Token Age', 'igny8-bridge'); ?></div>
<div class="igny8-diagnostic-value"><?php echo esc_html($token_age_text); ?></div>
<p class="description">
<?php echo esc_html($token_issued_formatted); ?>
</p>
</div>
<div class="igny8-diagnostic-item">
<div class="igny8-diagnostic-label"><?php _e('Last API Health Check', 'igny8-bridge'); ?></div>
<div class="igny8-diagnostic-value"><?php echo esc_html($last_health_check_formatted); ?></div>
<p class="description">
<?php _e('Updated when tests succeed', 'igny8-bridge'); ?>
</p>
</div>
<div class="igny8-diagnostic-item">
<div class="igny8-diagnostic-label"><?php _e('Last Site Data Sync', 'igny8-bridge'); ?></div>
<div class="igny8-diagnostic-value"><?php echo esc_html($last_site_sync_formatted); ?></div>
<p class="description">
<?php _e('Triggered automatically after setup', 'igny8-bridge'); ?>
</p>
</div>
<div class="igny8-diagnostic-item">
<div class="igny8-diagnostic-label"><?php _e('Last Full Site Scan', 'igny8-bridge'); ?></div>
<div class="igny8-diagnostic-value"><?php echo esc_html($last_full_site_scan_formatted); ?></div>
<p class="description">
<?php _e('Runs weekly or when requested manually', 'igny8-bridge'); ?>
</p>
</div>
<div class="igny8-diagnostic-item">
<div class="igny8-diagnostic-label"><?php _e('Last Semantic Map', 'igny8-bridge'); ?></div>
<div class="igny8-diagnostic-value"><?php echo esc_html($last_semantic_map_formatted); ?></div>
<p class="description">
<?php
if (!empty($semantic_summary)) {
printf(
/* translators: %1$d: sectors count, %2$d: keywords count */
esc_html__('Sectors: %1$d · Keywords: %2$d', 'igny8-bridge'),
intval($semantic_summary['sectors'] ?? 0),
intval($semantic_summary['keywords'] ?? 0)
);
} else {
_e('Planner semantic map generated after full scan', 'igny8-bridge');
}
?>
</p>
</div>
<div class="igny8-diagnostic-item">
<div class="igny8-diagnostic-label"><?php _e('Last Taxonomy Sync', 'igny8-bridge'); ?></div>
<div class="igny8-diagnostic-value"><?php echo esc_html($last_taxonomy_sync_formatted); ?></div>
<p class="description">
<?php _e('Sectors & clusters imported from Planner', 'igny8-bridge'); ?>
</p>
</div>
<div class="igny8-diagnostic-item">
<div class="igny8-diagnostic-label"><?php _e('Last Keyword Sync', 'igny8-bridge'); ?></div>
<div class="igny8-diagnostic-value"><?php echo esc_html($last_keyword_sync_formatted); ?></div>
<p class="description">
<?php _e('Planner keywords cached to WordPress posts', 'igny8-bridge'); ?>
</p>
</div>
<div class="igny8-diagnostic-item">
<div class="igny8-diagnostic-label"><?php _e('Last Writer Sync', 'igny8-bridge'); ?></div>
<div class="igny8-diagnostic-value"><?php echo esc_html($last_writer_sync_formatted); ?></div>
<p class="description">
<?php _e('New IGNY8 tasks imported automatically', 'igny8-bridge'); ?>
</p>
</div>
<div class="igny8-diagnostic-item">
<div class="igny8-diagnostic-label"><?php _e('Next Scheduled Site Scan', 'igny8-bridge'); ?></div>
<div class="igny8-diagnostic-value"><?php echo esc_html($next_site_sync_formatted); ?></div>
</div>
</div>
</div>
<?php else : ?>
<div class="igny8-settings-card">
<h2><?php _e('Connection Status', 'igny8-bridge'); ?></h2>
<p>
<span class="igny8-status-disconnected">
<?php _e('Not Connected', 'igny8-bridge'); ?>
</span>
</p>
<p class="description">
<?php _e('Enter your IGNY8 credentials above and click "Connect to IGNY8" to establish a connection.', 'igny8-bridge'); ?>
</p>
</div>
<?php endif; ?>
<div class="igny8-settings-card">
<h2>
<svg width="20" height="20" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" style="vertical-align: middle; margin-right: 8px; display: inline;">
<path stroke-linecap="round" stroke-linejoin="round" d="M9 12l2 2 4-4M7.835 4.697a3.42 3.42 0 001.946-.806 3.42 3.42 0 014.438 0 3.42 3.42 0 001.946.806 3.42 3.42 0 013.138 3.138 3.42 3.42 0 00.806 1.946 3.42 3.42 0 010 4.438 3.42 3.42 0 00-.806 1.946 3.42 3.42 0 01-3.138 3.138 3.42 3.42 0 00-1.946.806 3.42 3.42 0 01-4.438 0 3.42 3.42 0 00-1.946-.806 3.42 3.42 0 01-3.138-3.138 3.42 3.42 0 00-.806-1.946 3.42 3.42 0 010-4.438 3.42 3.42 0 00.806-1.946 3.42 3.42 0 013.138-3.138z"/>
</svg>
<?php _e('Automation Settings', 'igny8-bridge'); ?>
</h2>
<form method="post" action="options.php">
<?php settings_fields('igny8_bridge_controls'); ?>
<table class="form-table">
<tr>
<th scope="row"><?php _e('Post Types to Sync', 'igny8-bridge'); ?></th>
<td>
<?php foreach ($available_post_types as $slug => $label) : ?>
<label>
<input
type="checkbox"
name="igny8_enabled_post_types[]"
value="<?php echo esc_attr($slug); ?>"
<?php checked(in_array($slug, $enabled_post_types, true)); ?>
/>
<?php echo esc_html($label); ?>
</label>
<br />
<?php endforeach; ?>
<p class="description">
<?php _e('Select the content types IGNY8 should manage automatically.', 'igny8-bridge'); ?>
</p>
</td>
</tr>
<tr>
<th scope="row"><?php _e('IGNY8 Modules', 'igny8-bridge'); ?></th>
<td>
<?php foreach ($available_modules as $module_key => $module_label) : ?>
<label>
<input
type="checkbox"
name="igny8_enabled_modules[]"
value="<?php echo esc_attr($module_key); ?>"
<?php checked(in_array($module_key, $enabled_modules, true)); ?>
/>
<?php echo esc_html($module_label); ?>
</label>
<br />
<?php endforeach; ?>
<p class="description">
<?php _e('Disable modules temporarily if a feature is not ready in the SaaS app.', 'igny8-bridge'); ?>
</p>
</td>
</tr>
<tr>
<th scope="row"><?php _e('Control Mode', 'igny8-bridge'); ?></th>
<td>
<label>
<input
type="radio"
name="igny8_control_mode"
value="mirror"
<?php checked($control_mode, 'mirror'); ?>
/>
<strong><?php _e('Mirror', 'igny8-bridge'); ?></strong>
<span class="description"><?php _e('IGNY8 is the source of truth; WordPress reflects changes only.', 'igny8-bridge'); ?></span>
</label>
<br />
<label>
<input
type="radio"
name="igny8_control_mode"
value="hybrid"
<?php checked($control_mode, 'hybrid'); ?>
/>
<strong><?php _e('Hybrid', 'igny8-bridge'); ?></strong>
<span class="description"><?php _e('Allow editors to update content in WordPress and sync back to IGNY8.', 'igny8-bridge'); ?></span>
</label>
</td>
</tr>
<tr>
<th scope="row"><?php _e('WooCommerce Products', 'igny8-bridge'); ?></th>
<td>
<label>
<input
type="checkbox"
name="igny8_enable_woocommerce"
value="1"
<?php checked($woocommerce_enabled, 1); ?>
<?php disabled(!$woocommerce_detected); ?>
/>
<?php _e('Sync WooCommerce products and categories.', 'igny8-bridge'); ?>
</label>
<?php if (!$woocommerce_detected) : ?>
<p class="description">
<?php _e('WooCommerce is not active on this site. Enable the plugin to sync product data.', 'igny8-bridge'); ?>
</p>
<?php endif; ?>
</td>
</tr>
<tr>
<th scope="row"><?php _e('Taxonomies to Sync', 'igny8-bridge'); ?></th>
<td>
<?php foreach ($available_taxonomies as $taxonomy_slug => $taxonomy_label) : ?>
<label>
<input
type="checkbox"
name="igny8_enabled_taxonomies[]"
value="<?php echo esc_attr($taxonomy_slug); ?>"
<?php checked(in_array($taxonomy_slug, $enabled_taxonomies, true)); ?>
/>
<?php echo esc_html($taxonomy_label); ?> (<?php echo esc_html($taxonomy_slug); ?>)
</label>
<br />
<?php endforeach; ?>
<p class="description">
<?php _e('Select which taxonomies to synchronize bidirectionally with IGNY8.', 'igny8-bridge'); ?>
</p>
</td>
</tr>
</table>
<?php submit_button(__('Save Automation Settings', 'igny8-bridge')); ?>
</form>
<p class="description">
<?php _e('Once these settings are saved, the bridge schedules automatic jobs that keep IGNY8 in sync without manual actions.', 'igny8-bridge'); ?>
</p>
</div>
<?php if ($is_connected) : ?>
<div class="igny8-settings-card">
<h2>
<svg width="20" height="20" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" style="vertical-align: middle; margin-right: 8px; display: inline;">
<path stroke-linecap="round" stroke-linejoin="round" d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"/>
</svg>
<?php _e('Webhook Configuration', 'igny8-bridge'); ?>
</h2>
<table class="form-table">
<tr>
<th scope="row"><?php _e('Webhook URL', 'igny8-bridge'); ?></th>
<td>
<code><?php echo esc_html($webhook_url); ?></code>
<button type="button" class="button button-small" onclick="navigator.clipboard.writeText('<?php echo esc_js($webhook_url); ?>'); alert('<?php _e('Webhook URL copied to clipboard', 'igny8-bridge'); ?>');">
<?php _e('Copy', 'igny8-bridge'); ?>
</button>
<p class="description">
<?php _e('Configure this URL in your IGNY8 SaaS app settings.', 'igny8-bridge'); ?>
</p>
</td>
</tr>
<tr>
<th scope="row"><?php _e('Webhook Secret', 'igny8-bridge'); ?></th>
<td>
<code style="word-break: break-all;"><?php echo esc_html($webhook_secret); ?></code>
<button type="button" class="button button-small" onclick="navigator.clipboard.writeText('<?php echo esc_js($webhook_secret); ?>'); alert('<?php _e('Secret copied to clipboard', 'igny8-bridge'); ?>');">
<?php _e('Copy', 'igny8-bridge'); ?>
</button>
<form method="post" action="" style="display: inline-block; margin-left: 10px;">
<?php wp_nonce_field('igny8_regenerate_secret'); ?>
<button type="submit" name="igny8_regenerate_secret" class="button button-small" onclick="return confirm('<?php _e('Are you sure? You will need to update the secret in IGNY8 SaaS app.', 'igny8-bridge'); ?>');">
<?php _e('Regenerate', 'igny8-bridge'); ?>
</button>
</form>
<p class="description">
<?php _e('Use this secret to verify webhook requests in IGNY8 SaaS app. Keep it secure.', 'igny8-bridge'); ?>
</p>
</td>
</tr>
</table>
</div>
<?php endif; ?>
<div class="igny8-settings-card">
<h2>
<svg width="20" height="20" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" style="vertical-align: middle; margin-right: 8px; display: inline;">
<path stroke-linecap="round" stroke-linejoin="round" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>
</svg>
<?php _e('About', 'igny8-bridge'); ?>
</h2>
<p>
<?php _e('The IGNY8 WordPress Bridge plugin connects your WordPress site to the IGNY8 API, enabling two-way synchronization of posts, taxonomies, and site data.', 'igny8-bridge'); ?>
</p>
<p>
<strong><?php _e('Version:', 'igny8-bridge'); ?></strong> <?php echo esc_html(IGNY8_BRIDGE_VERSION); ?>
</p>
</div>
<?php if ($is_connected) : ?>
<div class="igny8-settings-card">
<h2>
<svg width="20" height="20" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24" style="vertical-align: middle; margin-right: 8px; display: inline;">
<path stroke-linecap="round" stroke-linejoin="round" d="M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M9 19l3 3m0 0l3-3m-3 3V10"/>
</svg>
<?php _e('Sync Operations', 'igny8-bridge'); ?>
</h2>
<?php if (!$connection_enabled) : ?>
<div class="notice notice-warning inline">
<p>
<strong><?php _e('Connection Disabled', 'igny8-bridge'); ?></strong><br />
<?php _e('Sync operations are currently disabled. Enable "Enable Communication" above to use these features.', 'igny8-bridge'); ?>
</p>
</div>
<?php endif; ?>
<?php
// Get counts for sync operations
$post_count = wp_count_posts('post');
$page_count = wp_count_posts('page');
$product_count = class_exists('WooCommerce') ? wp_count_posts('product') : null;
$total_posts = $post_count->publish + $page_count->publish;
if ($product_count) $total_posts += $product_count->publish;
$taxonomies = get_taxonomies(['public' => true], 'objects');
$taxonomy_count = 0;
foreach ($taxonomies as $taxonomy) {
$taxonomy_count += wp_count_terms(['taxonomy' => $taxonomy->name, 'hide_empty' => false]);
}
?>
<div class="igny8-sync-grid">
<div class="igny8-sync-card">
<div class="igny8-sync-icon">
<svg width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/>
</svg>
</div>
<h3><?php _e('Sync Posts to IGNY8', 'igny8-bridge'); ?></h3>
<p class="igny8-sync-description">
<?php printf(
__('Send %d posts, %d pages%s from WordPress to IGNY8', 'igny8-bridge'),
$post_count->publish,
$page_count->publish,
$product_count ? sprintf(', %d products', $product_count->publish) : ''
); ?>
</p>
<p class="igny8-sync-meta">
<?php if ($last_site_sync) : ?>
<span class="igny8-sync-time">⏱ <?php echo sprintf(__('Last sync: %s', 'igny8-bridge'), human_time_diff($last_site_sync, current_time('timestamp')) . ' ago'); ?></span>
<?php else : ?>
<span class="igny8-sync-time">⏱ <?php _e('Never synced', 'igny8-bridge'); ?></span>
<?php endif; ?>
</p>
<button type="button" id="igny8-sync-posts" class="button button-primary igny8-sync-button" <?php disabled(!$connection_enabled); ?>>
<span class="button-text"><?php _e('Sync Now', 'igny8-bridge'); ?></span>
<span class="button-loading" style="display: none;">
<span class="spinner is-active"></span> <?php _e('Syncing...', 'igny8-bridge'); ?>
</span>
</button>
</div>
<div class="igny8-sync-card">
<div class="igny8-sync-icon">
<svg width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" d="M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A1.994 1.994 0 013 12V7a4 4 0 014-4z"/>
</svg>
</div>
<h3><?php _e('Sync Taxonomies', 'igny8-bridge'); ?></h3>
<p class="igny8-sync-description">
<?php printf(
__('Sync %d taxonomy terms (categories, tags, sectors, clusters) to IGNY8', 'igny8-bridge'),
$taxonomy_count
); ?>
</p>
<p class="igny8-sync-meta">
<?php if ($last_taxonomy_sync) : ?>
<span class="igny8-sync-time">⏱ <?php echo sprintf(__('Last sync: %s', 'igny8-bridge'), human_time_diff($last_taxonomy_sync, current_time('timestamp')) . ' ago'); ?></span>
<?php else : ?>
<span class="igny8-sync-time">⏱ <?php _e('Never synced', 'igny8-bridge'); ?></span>
<?php endif; ?>
</p>
<button type="button" id="igny8-sync-taxonomies" class="button button-primary igny8-sync-button" <?php disabled(!$connection_enabled); ?>>
<span class="button-text"><?php _e('Sync Now', 'igny8-bridge'); ?></span>
<span class="button-loading" style="display: none;">
<span class="spinner is-active"></span> <?php _e('Syncing...', 'igny8-bridge'); ?>
</span>
</button>
</div>
<div class="igny8-sync-card">
<div class="igny8-sync-icon">
<svg width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12"/>
</svg>
</div>
<h3><?php _e('Sync from IGNY8', 'igny8-bridge'); ?></h3>
<p class="igny8-sync-description">
<?php _e('Import new content, tasks, and updates from IGNY8 AI OS to WordPress', 'igny8-bridge'); ?>
</p>
<p class="igny8-sync-meta">
<?php if ($last_writer_sync) : ?>
<span class="igny8-sync-time">⏱ <?php echo sprintf(__('Last sync: %s', 'igny8-bridge'), human_time_diff($last_writer_sync, current_time('timestamp')) . ' ago'); ?></span>
<?php else : ?>
<span class="igny8-sync-time">⏱ <?php _e('Never synced', 'igny8-bridge'); ?></span>
<?php endif; ?>
</p>
<button type="button" id="igny8-sync-from-igny8" class="button button-primary igny8-sync-button" <?php disabled(!$connection_enabled); ?>>
<span class="button-text"><?php _e('Sync Now', 'igny8-bridge'); ?></span>
<span class="button-loading" style="display: none;">
<span class="spinner is-active"></span> <?php _e('Syncing...', 'igny8-bridge'); ?>
</span>
</button>
</div>
<div class="igny8-sync-card igny8-sync-card-highlight">
<div class="igny8-sync-icon">
<svg width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" d="M21 12a9 9 0 01-9 9m9-9a9 9 0 00-9-9m9 9H3m9 9a9 9 0 01-9-9m9 9c1.657 0 3-4.03 3-9s-1.343-9-3-9m0 18c-1.657 0-3-4.03-3-9s1.343-9 3-9m-9 9a9 9 0 019-9"/>
</svg>
</div>
<h3><?php _e('Collect & Send Site Data', 'igny8-bridge'); ?></h3>
<p class="igny8-sync-description">
<?php _e('Perform full site scan: collect structure, links, SEO data, and send comprehensive report to IGNY8', 'igny8-bridge'); ?>
</p>
<p class="igny8-sync-meta">
<?php if ($last_full_site_scan) : ?>
<span class="igny8-sync-time">⏱ <?php echo sprintf(__('Last scan: %s', 'igny8-bridge'), human_time_diff($last_full_site_scan, current_time('timestamp')) . ' ago'); ?></span>
<?php else : ?>
<span class="igny8-sync-time">⏱ <?php _e('Never scanned', 'igny8-bridge'); ?></span>
<?php endif; ?>
</p>
<button type="button" id="igny8-collect-site-data" class="button button-primary igny8-sync-button" <?php disabled(!$connection_enabled); ?>>
<span class="button-text"><?php _e('Start Full Scan', 'igny8-bridge'); ?></span>
<span class="button-loading" style="display: none;">
<span class="spinner is-active"></span> <?php _e('Scanning...', 'igny8-bridge'); ?>
</span>
</button>
</div>
</div>
<div id="igny8-sync-status" class="igny8-sync-status"></div>
</div>
<div class="igny8-settings-card">
<h2><?php _e('Sync Statistics', 'igny8-bridge'); ?></h2>
<div class="igny8-stats-grid">
<div class="igny8-stat-card">
<div class="igny8-stat-icon" style="background-color: #3B82F6;">
<svg width="20" height="20" fill="none" stroke="white" stroke-width="2" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/>
</svg>
</div>
<div class="igny8-stat-content">
<div class="igny8-stat-label"><?php _e('Synced Posts', 'igny8-bridge'); ?></div>
<div class="igny8-stat-value" id="igny8-stat-posts"><?php echo number_format($total_posts); ?></div>
<div class="igny8-stat-meta"><?php printf(__('%d posts · %d pages', 'igny8-bridge'), $post_count->publish, $page_count->publish); ?></div>
</div>
</div>
<div class="igny8-stat-card">
<div class="igny8-stat-icon" style="background-color: #10B981;">
<svg width="20" height="20" fill="none" stroke="white" stroke-width="2" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" d="M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A1.994 1.994 0 013 12V7a4 4 0 014-4z"/>
</svg>
</div>
<div class="igny8-stat-content">
<div class="igny8-stat-label"><?php _e('Taxonomy Terms', 'igny8-bridge'); ?></div>
<div class="igny8-stat-value" id="igny8-stat-taxonomies"><?php echo number_format($taxonomy_count); ?></div>
<div class="igny8-stat-meta"><?php _e('Categories, tags, sectors', 'igny8-bridge'); ?></div>
</div>
</div>
<div class="igny8-stat-card">
<div class="igny8-stat-icon" style="background-color: #F59E0B;">
<svg width="20" height="20" fill="none" stroke="white" stroke-width="2" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"/>
</svg>
</div>
<div class="igny8-stat-content">
<div class="igny8-stat-label"><?php _e('Last Sync', 'igny8-bridge'); ?></div>
<div class="igny8-stat-value" id="igny8-stat-last-sync">
<?php if ($last_site_sync) : ?>
<?php echo human_time_diff($last_site_sync, current_time('timestamp')); ?> <?php _e('ago', 'igny8-bridge'); ?>
<?php else : ?>
<?php _e('Never', 'igny8-bridge'); ?>
<?php endif; ?>
</div>
<div class="igny8-stat-meta">
<?php if ($last_site_sync) : ?>
<?php echo date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $last_site_sync); ?>
<?php else : ?>
<?php _e('No sync performed yet', 'igny8-bridge'); ?>
<?php endif; ?>
</div>
</div>
</div>
<div class="igny8-stat-card">
<div class="igny8-stat-icon" style="background-color: #8B5CF6;">
<svg width="20" height="20" fill="none" stroke="white" stroke-width="2" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" d="M13 10V3L4 14h7v7l9-11h-7z"/>
</svg>
</div>
<div class="igny8-stat-content">
<div class="igny8-stat-label"><?php _e('Connection Status', 'igny8-bridge'); ?></div>
<div class="igny8-stat-value">
<?php if ($connection_enabled) : ?>
<span style="color: #10B981; font-size: 18px; font-weight: 600;"><?php _e('Active', 'igny8-bridge'); ?></span>
<?php else : ?>
<span style="color: #6B7280; font-size: 18px; font-weight: 600;"><?php _e('Disabled', 'igny8-bridge'); ?></span>
<?php endif; ?>
</div>
<div class="igny8-stat-meta">
<?php if ($last_health_check) : ?>
<?php _e('Last checked:', 'igny8-bridge'); ?> <?php echo human_time_diff($last_health_check, current_time('timestamp')); ?> <?php _e('ago', 'igny8-bridge'); ?>
<?php else : ?>
<?php _e('Health check pending', 'igny8-bridge'); ?>
<?php endif; ?>
</div>
</div>
</div>
</div>
<?php if ($last_semantic_map && !empty($semantic_summary)) : ?>
<div class="igny8-semantic-summary">
<h3><?php _e('Latest Site Analysis', 'igny8-bridge'); ?></h3>
<div class="igny8-semantic-stats">
<div class="igny8-semantic-stat">
<span class="value"><?php echo number_format($semantic_summary['sectors'] ?? 0); ?></span>
<span class="label"><?php _e('Sectors', 'igny8-bridge'); ?></span>
</div>
<div class="igny8-semantic-stat">
<span class="value"><?php echo number_format($semantic_summary['keywords'] ?? 0); ?></span>
<span class="label"><?php _e('Keywords', 'igny8-bridge'); ?></span>
</div>
<div class="igny8-semantic-stat">
<span class="value"><?php echo human_time_diff($last_semantic_map, current_time('timestamp')); ?></span>
<span class="label"><?php _e('ago', 'igny8-bridge'); ?></span>
</div>
</div>
</div>
<?php endif; ?>
</div>
<?php endif; ?>
</div>
</div>