admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('accua_theme_helper'), 'pluginCssUrl' => plugins_url('assets/css/frontend.css', ACCUA_FORMS_FILE), 'i18n' => array( 'scanning' => __('Scanning...', 'contact-forms'), 'noConflicts' => __('No CSS conflicts detected!', 'contact-forms'), 'conflictsFound' => __('CSS conflicts found:', 'contact-forms'), 'scanComplete' => __('Scan complete', 'contact-forms'), 'scanError' => __('Error scanning URL', 'contact-forms'), 'enterUrl' => __('Enter a URL to scan', 'contact-forms'), 'fetchingCss' => __('Fetching CSS from URL...', 'contact-forms'), ), // Contact Forms CSS classes to monitor 'monitoredClasses' => accua_forms_get_monitored_css_classes(), // CSS properties that commonly cause layout issues 'criticalProperties' => array( 'padding', 'padding-top', 'padding-right', 'padding-bottom', 'padding-left', 'margin', 'margin-top', 'margin-right', 'margin-bottom', 'margin-left', 'display', 'position', 'visibility', 'overflow', 'width', 'height', 'min-width', 'min-height', 'max-width', 'max-height', 'flex', 'flex-direction', 'flex-wrap', 'align-items', 'justify-content', 'border', 'border-width', 'border-style', 'float', 'clear', 'z-index', 'opacity', ), )); } /** * Get list of Contact Forms CSS classes to monitor for conflicts */ function accua_forms_get_monitored_css_classes() { return array( // Error handling 'pfbc-error', 'pfbc-error-heading', 'pfbc-error-list', 'pfbc-inline-error', 'pfbc-error-message', // Field structure 'pfbc-fieldwrap', 'pfbc-invalid', 'pfbc-element-has-error', 'pfbc-element', 'pfbc-elementbottom', 'pfbc-label', 'pfbc-help', 'pfbc-description', 'pfbc-required', // Form inputs 'pfbc-textbox', 'pfbc-textarea', 'pfbc-select', 'pfbc-checkbox', 'pfbc-buttons', // Color picker 'pfbc-color-wrapper', 'pfbc-color-input', 'pfbc-color-hex', // Inline labels 'pfbc-inline-label-wrapper', 'pfbc-floating-label', // Form layouts 'accua-form', 'accua-form-view-standard', 'accua-form-view-sidebyside', 'accua-form-view-inlinelabel', // Misc 'accua_form_api_throbbler', 'accua_forms_recaptcha2_container', ); } /** * Render Theme Helper admin page */ function accua_forms_theme_helper_page() { if (!current_user_can('manage_options')) { wp_die( esc_html__('You do not have sufficient permissions to access this page.', 'contact-forms') ); } ?>

__('Permission denied', 'contact-forms'))); } $url = isset($_POST['url']) ? esc_url_raw(wp_unslash($_POST['url'])) : ''; if (empty($url)) { wp_send_json_error(array('message' => __('No URL provided', 'contact-forms'))); } // Fetch the HTML page $response = wp_remote_get($url, array( 'timeout' => 30, 'sslverify' => false, )); if (is_wp_error($response)) { wp_send_json_error(array('message' => $response->get_error_message())); } $html = wp_remote_retrieve_body($response); if (empty($html)) { wp_send_json_error(array('message' => __('Empty response from URL', 'contact-forms'))); } // Parse HTML to find stylesheet URLs $stylesheets = array(); // Match preg_match_all('/]+rel=["\']stylesheet["\'][^>]+href=["\']([^"\']+)["\'][^>]*>/i', $html, $matches); if (!empty($matches[1])) { $stylesheets = array_merge($stylesheets, $matches[1]); } // Also match href before rel preg_match_all('/]+href=["\']([^"\']+)["\'][^>]+rel=["\']stylesheet["\'][^>]*>/i', $html, $matches); if (!empty($matches[1])) { $stylesheets = array_merge($stylesheets, $matches[1]); } $stylesheets = array_unique($stylesheets); // Fetch each stylesheet and combine content $css_data = array(); $base_url = trailingslashit(dirname($url)); $site_url = trailingslashit(wp_parse_url($url, PHP_URL_SCHEME) . '://' . wp_parse_url($url, PHP_URL_HOST)); foreach ($stylesheets as $stylesheet_url) { // Handle relative URLs if (strpos($stylesheet_url, '//') === 0) { $stylesheet_url = wp_parse_url($url, PHP_URL_SCHEME) . ':' . $stylesheet_url; } elseif (strpos($stylesheet_url, '/') === 0) { $stylesheet_url = rtrim($site_url, '/') . $stylesheet_url; } elseif (strpos($stylesheet_url, 'http') !== 0) { $stylesheet_url = $base_url . $stylesheet_url; } // Skip external CDN stylesheets (Google Fonts, etc.) if (strpos($stylesheet_url, 'fonts.googleapis.com') !== false || strpos($stylesheet_url, 'cdnjs.cloudflare.com') !== false || strpos($stylesheet_url, 'cdn.jsdelivr.net') !== false) { continue; } $css_response = wp_remote_get($stylesheet_url, array( 'timeout' => 15, 'sslverify' => false, )); if (!is_wp_error($css_response)) { $css_content = wp_remote_retrieve_body($css_response); if (!empty($css_content)) { $css_data[] = array( 'url' => $stylesheet_url, 'content' => $css_content, ); } } } // Also look for inline styles preg_match_all('/]*>(.*?)<\/style>/is', $html, $inline_matches); if (!empty($inline_matches[1])) { foreach ($inline_matches[1] as $index => $inline_css) { if (!empty(trim($inline_css))) { $css_data[] = array( 'url' => $url . ' (inline style #' . ($index + 1) . ')', 'content' => $inline_css, ); } } } // Detect Contact Forms version from remote site $remote_cf_version = null; // Check for Contact Forms CSS version in URL params (e.g., frontend.css?ver=69) foreach ($stylesheets as $stylesheet_url) { // Match both old and new CSS paths if (strpos($stylesheet_url, 'contact-forms/assets/css/frontend.css') !== false || strpos($stylesheet_url, 'contact-forms/assets/css/accua-form-api.css') !== false || strpos($stylesheet_url, 'contact-forms/accua-form-api.css') !== false) { // Old path // Extract version from query string $parsed = wp_parse_url($stylesheet_url); if (!empty($parsed['query'])) { parse_str($parsed['query'], $query_params); if (!empty($query_params['ver'])) { $remote_cf_version = $query_params['ver']; break; } } } } // Also try to find version in HTML comments or meta tags if (!$remote_cf_version) { // Look for Contact Forms generator meta or comment if (preg_match('/Contact Forms[^0-9]*([0-9]+\.[0-9]+\.[0-9]+[^"\s]*)/i', $html, $version_match)) { $remote_cf_version = $version_match[1]; } } // Get current plugin version $plugin_data = get_plugin_data(ACCUA_FORMS_FILE); $current_version = $plugin_data['Version']; wp_send_json_success(array( 'stylesheets' => $css_data, 'count' => count($css_data), 'remoteContactFormsVersion' => $remote_cf_version, 'remoteCssVersion' => $remote_cf_version, // CSS version number 'currentVersion' => $current_version, 'currentCssVersion' => ACCUA_FORMS_CSS_VERSION, )); }