-

__('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, )); }