-
-
-
-
.pfbc-invalid, .pfbc-fieldwrap -
.pfbc-element -
.pfbc-inline-error -
.accua-form-view-* -
__('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('/