/**
* Harici resimleri özgünleştirme fonksiyonu (güvenli versiyon)
*/
function harici_resimleri_ozgunlestir($content) {
// Yönetici panelinde veya boş içerikte çalışma
if (empty($content) || is_admin()) {
return $content;
}
// Basit regex yaklaşımı ile img tag'lerini bul
$content = preg_replace_callback('/]+>/i', function($matches) {
$img_tag = $matches[0];
// Src attribute'unu bul
if (preg_match('/src=["\']([^"\']+)["\']/i', $img_tag, $src_matches)) {
$src = $src_matches[1];
// Yerel resimleri atla
if (strpos($src, site_url()) !== false) {
return $img_tag;
}
// 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);
// Orijinal src'yi data-original-src olarak sakla
$img_tag = str_replace($src, $new_src, $img_tag);
$img_tag = preg_replace('/
sanitize_title(get_bloginfo('name')),
'utm_source' => 'internal_mirror',
'v' => substr(time(), -5) // 5 haneli cache buster
));
}
// Filtreleri ekle (orta öncelikle)
add_filter('the_content', 'harici_resimleri_ozgunlestir', 15);
add_filter('content_save_pre', 'harici_resimleri_ozgunlestir', 15);