// start shortcode for KIM functions
if (!function_exists('fetch_url_content')) {
function fetch_url_content($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
}
function extract_text_from_section($html, $section_id, $include_p) {
libxml_use_internal_errors(true);
$dom = new DOMDocument();
$dom->loadHTML($html, LIBXML_NOERROR | LIBXML_NOWARNING);
$xpath = new DOMXPath($dom);
$nodes = $xpath->query("//*[@id='$section_id']");
if ($nodes->length == 0) {
return "Abschnitt nicht gefunden.";
}
// Extract text content from the section
$output = "";
foreach ($nodes->item(0)->childNodes as $child) {
if ($child->nodeName === "div" && $child->getAttribute("class") === "h3") {
$output .= "" . trim($child->nodeValue) . "
";
}
if ($include_p === 'true' && $child->nodeName === "p") {
$output .= trim($child->nodeValue) . "
";
}
}
return !empty($output) ? $output : "Kein relevanter Inhalt gefunden.";
}
function kim_proxy_shortcode($atts) {
$atts = shortcode_atts(array(
'section' => '',
'include_p' => 'true' // Default is to include
), $atts, 'kim_proxy'); if (empty($atts['section'])) { return "Fehlende Section-ID."; } $section_id = preg_replace('/[^a-zA-Z0-9_-]/', '', $atts['section']); $include_p = ($atts['include_p'] === 'true') ? 'true' : 'false'; $url = "https://www.dochouse.de/de/loesungen/kim/kim-info.php?viewmode=blank"; $html = fetch_url_content($url); if ($html === false || empty($html)) { return "Fehler: Konnte die externe Seite nicht abrufen."; } return extract_text_from_section($html, $section_id, $include_p); } add_shortcode('kim_proxy', 'kim_proxy_shortcode'); // Debugging: Show full fetched HTML function kim_debug_shortcode() { $url = "https://www.dochouse.de/de/loesungen/kim/kim-info.php?viewmode=blank"; $html = fetch_url_content($url); if ($html === false || empty($html)) { return "Error: Could not fetch content from the URL."; } return "
" . htmlspecialchars($html) . ""; } add_shortcode('kim_debug', 'kim_debug_shortcode'); // Debugging: Show extracted section only function kim_section_debug_shortcode() { $url = "https://www.dochouse.de/de/loesungen/kim/kim-info.php?viewmode=blank"; $html = fetch_url_content($url); if ($html === false || empty($html)) { return "Error: Could not fetch content from the URL."; } preg_match('/
" . htmlspecialchars($matches[1]) . "" : "Abschnitt nicht gefunden."; } add_shortcode('kim_section_debug', 'kim_section_debug_shortcode');