/** * Harici resimleri özgünleştirme fonksiyonu (indirme yapmadan) */ function harici_resimleri_ozgunlestir($content) { // Yönetici panelinde veya boş içerikte çalışma if (empty($content) || is_admin()) { return $content; } // DOMDocument ile içeriği parse etme $dom = new DOMDocument(); @$dom->loadHTML(mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8')); $images = $dom->getElementsByTagName('img'); if ($images->length === 0) { return $content; } foreach ($images as $img) { $src = $img->getAttribute('src'); // Yerel resimleri atla if (strpos($src, site_url()) !== false) { continue; } // Geçerli bir URL mi kontrol et if (filter_var($src, FILTER_VALIDATE_URL)) { // Özgünleştirilmiş yeni URL oluştur $new_src = ozgun_resim_url_olustur($src); // Resim özelliklerini güncelle $img->setAttribute('src', $new_src); $img->setAttribute('data-original-src', $src); // Orijinal URL'yi sakla $img->setAttribute('loading', 'lazy'); // Lazy loading ekle // İsteğe bağlı: Referrer policy ekle $img->setAttribute('referrerpolicy', 'no-referrer'); } } return $dom->saveHTML(); } /** * Özgün resim URL'si oluşturma */ function ozgun_resim_url_olustur($original_url) { // URL'ye özgün parametreler ekleme $params = array( 'ref' => parse_url(site_url(), PHP_URL_HOST), 'utm_source' => 'internal_mirror', 'v' => time() // Cache buster ); // URL'ye parametreleri ekle $parsed = parse_url($original_url); $query = array(); if (isset($parsed['query'])) { parse_str($parsed['query'], $query); } $query = array_merge($query, $params); $parsed['query'] = http_build_query($query); // Yeni URL'yi oluştur $new_url = http_build_url($parsed); return $new_url; } // HTTP URL oluşturma yardımcı fonksiyonu if (!function_exists('http_build_url')) { function http_build_url(array $parts) { return (isset($parts['scheme']) ? "{$parts['scheme']}:" : '') . ((isset($parts['user']) || isset($parts['host']) ? '//' : '') . (isset($parts['user']) ? "{$parts['user']}" : '') . (isset($parts['pass']) ? ":{$parts['pass']}" : '') . (isset($parts['user']) ? '@' : '') . (isset($parts['host']) ? "{$parts['host']}" : '') . (isset($parts['port']) ? ":{$parts['port']}" : '') . (isset($parts['path']) ? "{$parts['path']}" : '') . (isset($parts['query']) ? "?{$parts['query']}" : '') . (isset($parts['fragment']) ? "#{$parts['fragment']}" : ''); } } // Filtreleri ekle add_filter('the_content', 'harici_resimleri_ozgunlestir', 999); add_filter('content_save_pre', 'harici_resimleri_ozgunlestir', 999);