ories', []); if (isset(_POST['rss_importer_save'])) { check_admin_referer('rss_importer_save_settings'); rss_feed_urls = []; for (i=1;i <= 12; i++) { rss_feed_urls[i]=sanitizetextareafield(POST["rss_feed_urli"])??′′;rss_default_categories[i]=intval(POST["rss_default_categoryi"] ?? 0); } update_option('rss_feed_urls', rss_feed_urls); update_option('rss_import_interval', sanitize_text_field(POST[rss_default_categories); update_option('rss_debug_mode', isset(P_POST['rss_import_limit'])); echo '
Ayarlar kaydedildi.
'; } if (isset(_POST['rss_importer_run_now'])) { check_admin_referer('rss_importer_save_settings'); result = rss_importer_process_feeds(); if (result['success']) { echo '
RSS içerikleri başarıyla çekildi. Toplam ' . result['imported'] . ' yeni içerik aktarıldı.
'; if (!empty($result['debug'])) { echo '
Debug bilgisi:
' . esc_html(print_r(result['debug'], true)) . '
'; } } else { echo '
RSS içerikleri çekilirken hata oluştu: ' . esc_html(result['message']) . '
'; } } if (isset(_POST['rss_importer_upload_xml'])) { check_admin_referer('rss_importer_save_settings'); // Dosya yükleme kontrolü if (isset(_FILES['rss_xml_file']) && _FILES['rss_xml_file']['error'] === UPLOAD_ERR_OK) { xml_file = FILES[category_id = intval(result = rss_importer_process_xml(category_id); if (result['imported'] . ' içerik aktarıldı.
'; } else { echo '
Hata: ' . esc_html($result['message']) . '
'; } } } ?>
<h2>XML Dosyası Yükleme</h2>
<table class="form-table">
<tr>
<th scope="row"><label for="rss_xml_file">XML Dosyası</label></th>
<td>
<input type="file" name="rss_xml_file" id="rss_xml_file" accept=".xml">
<p class="description">Yüklemek istediğiniz XML dosyasını seçin.</p>
</td>
</tr>
<tr>
<th scope="row"><label for="rss_xml_default_category">Kategorisi</label></th>
<td>
<select name="rss_xml_default_category" id="rss_xml_default_category">
<?php foreach ($categories as $category): ?>
<option value="<?php echo esc_attr($category->term_id); ?>"><?php echo esc_html($category->name); ?></option>
<?php endforeach; ?>
</select>
<p class="description">İçeriklerin atanacağı kategori.</p>
</td>
</tr>
</table>
<p class="submit">
<input type="submit" name="rss_importer_save" class="button button-primary" value="Ayarları Kaydet">
<input type="submit" name="rss_importer_run_now" class="button button-secondary" value="Şimdi İçeri Aktar">
<input type="submit" name="rss_importer_upload_xml" class="button button-secondary" value="XML Dosyasını Yükle">
</p>
</form>
// Zamanlanmış görev oluştur
add_action('init', function () {
currentinternext_scheduled = wp_next_scheduled('rss_importer_cron');
if (!next_scheduled) {
wp_schedule_event(time(), current_interval, 'rss_importer_cron');
} else {
currentschcurrent_schedule !== current_interval, 'rss_importer_cron');
}
}
});
register_deactivation_hook(FILE, function () {
wp_clear_scheduled_hook('rss_importer_cron');
});
add_action('rss_importer_cron', 'rss_importer_process_feeds');
// CDATA içeriğini temizleme fonksiyonu
function clean_cdata_content(content) {
content = preg_replace('//is', '1′,content);
content=htmlcontent, ENT_QUOTES | ENT_HTML5, 'UTF-8');
content);
content);
return trim($content);
}
// RSS içeriklerini işleyen fonksiyon
function rss_importer_process_feeds() {
if (!class_exists('SimplePie')) {
require_once(ABSPATH . WPINC . '/class-simplepie.php');
}
debugmode=debug_info = [];
default_categories = get_option('rss_default_categories', []);
imported_count = 0;
$errors = [];
foreach (rssfeedurlsasindex => feed_url) {
if (empty(feed_url)) continue; // Boş RSS adresleri atlanacak
$category_id = $default_categories[$index] ?? 0; // İlgili kategori ID'sini al
if ($debug_mode) {
$debug_info[] = "İşlenen Feed: " . $feed_url;
}
$feed = new SimplePie();
$feed->set_feed_url($feed_url);
$feed->enable_cache(false);
$feed->force_feed(true);
$feed->set_timeout(30);
$feed->enable_order_by_date(true);
$success = $feed->init();
if (!$success) {
$error_message = 'Feed yüklenemedi: ' . $feed->error();
$errors[] = $feed_url . ': ' . $error_message;
if ($debug_mode) {
$debug_info[] = $error_message;
}
continue;
}
$items = $feed->get_items();
$items_to_import = array_slice($items, 0, $import_limit);
// En son eklenenden en eskiye doğru sırala
$items_to_import = array_reverse($items_to_import);
foreach ($items_to_import as $item) {
$title = clean_cdata_content($item->get_title());
$content = clean_cdata_content($item->get_content());
$permalink = esc_url($item->get_permalink());
// Görseli çıkar
$image_url = extract_image_from_item($item);
// Eğer görsel yoksa haberi ekleme
if (empty($image_url)) {
if ($debug_mode) {
$debug_info[] = "Görsel eksik: " . $title . " (Eklenmedi)";
}
continue; // Görsel yoksa içeriği atla
}
if ($debug_mode) {
$debug_info[] = "İşlenen Başlık: " . $title;
}
// İçerik zaten var mı kontrol et
if (post_exists($title)) {
if ($debug_mode) {
$debug_info[] = "İçerik zaten mevcut: " . $title;
}
continue;
}
if ($debug_mode && $image_url) {
$debug_info[] = "Bulunan görsel: " . $image_url;
}
// Yazıyı ekle
$post_data = array(
'post_title' => $title,
'post_content' => $content,
'post_status' => 'publish',
'post_author' => 1,
'post_category' => [$category_id], // Kategori ID'sini kullan
'meta_input' => [
'rss_source_url' => $permalink
]
);
$post_id = wp_insert_post($post_data);
if (!is_wp_error($post_id)) {
$imported_count++;
$image_result = set_featured_image_from_url($post_id, $image_url);
if ($debug_mode) {
$debug_info[] = "Görsel yükleme sonucu: " . ($image_result ? "Başarılı" : "Başarısız");
}
if ($debug_mode) {
$debug_info[] = "İçerik başarıyla eklendi. Post ID: " . $post_id;
}
} else {
if ($debug_mode) {
$debug_info[] = "İçerik eklenemedi: " . $post_id->get_error_message();
}
}
}
}
result=[′successerrors) ? 'Başarıyla tamamlandı' : implode("\n", imported_count
];
if (debug_mode) {
result['debug'] = $debug_info;
}
return $result;
}
// XML dosyasını işleyen fonksiyon
// XML dosyasını işleyen fonksiyon
function rss_importer_process_xml(filepath,category_id) {
if (file_exists(file_path)) {
xml = simplexml_load_file(filexml === false) {
return ['success' => false, 'message' => 'XML dosyası okunamadı.'];
}
$imported_count = 0;
foreach ($xml->channel->item as $item) {
$title = clean_cdata_content($item->title);
$content = clean_cdata_content($item->description);
$permalink = esc_url((string)$item->link);
// İçerik zaten var mı kontrol et
if (post_exists($title)) {
continue; // İçerik zaten mevcut, atla
}
// Yazıyı ekle
$post_data = array(
'post_title' => $title,
'post_content' => $content,
'post_status' => 'publish',
'post_author' => 1,
'post_category' => [$category_id], // Kategori ID'sini kullan
'meta_input' => [
'rss_source_url' => $permalink
]
);
$post_id = wp_insert_post($post_data);
if (!is_wp_error($post_id)) {
$imported_count++;
// Öne çıkan görsel (thumbnail) ekleme
if (isset($item->enclosure)) {
$image_url = (string)$item->enclosure['url'];
$image_result = set_featured_image_from_url($post_id, $image_url);
if (is_wp_error($image_result)) {
rss_debug_log('Görsel yüklenemedi: ' . $image_result->get_error_message());
}
}
}
}
return [
'success' => true,
'imported' => $imported_count,
'message' => 'Başarıyla işlendi.'
];
}
return ['success' => false, 'message' => 'Dosya bulunamadı.'];
}
function extract_image_from_item(item) {
image_url = null;
// Görsel alma işlemleri...
// ... (Aynı kod ile devam ediyor)
}
function set_featured_image_from_url(postid,image_url) {
require_once(ABSPATH . 'wp-admin/includes/media.php');
require_once(ABSPATH . 'wp-admin/includes/file.php');
require_once(ABSPATH . 'wp-admin/includes/image.php');
imageurl=escurl(image_url);
image_url, PHP_URL_PATH));
tmp=downloadurl(image_url);
if (is_wp_error(tmp)) {
rss_debug_log('Görsel indirilemedi: ' . tmp->get_error_message());
return false;
}
filearray=array(image_name,
'tmp_name' => $tmp
);
attachmentid=mediahfile_array, $post_id);
@unlink($tmp);
if (is_wp_error(attachment_id)) {
rss_debug_log('Görsel yüklenemedi: ' . attachment_id->get_error_message());
return false;
}
return set_post_thumbnail(postid,attachment_id);
}
// Feed yenileme zamanını sıfırla
function reset_feed_cache() {
global wpdb;wpdb->query("DELETE FROM wpdb−>optionwpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE 'transient_timeout_feed%'");
}
// Admin bar'a debug butonu ekle
add_action('admin_bar_menu', function (admin_bar) {
if (current_user_can('manage_options') && get_option('rss_debug_mode', '0') === '1') {
admin_bar->add_menu(array(
'id' => 'rss-importer-debug',
'title' => 'RSS Debug',
'href' => '#',
'meta' => array(
'onclick' => 'window.location.href = window.location.href + (window.location.href.indexOf("?") > 0 ? "&" : "?") + "rss_debug=1"'
)
));
}
}, 100);
// Feed önbelleğini temizle
add_action('init', function () {
if (isset($_GET['rss_debug']) && current_user_can('manage_options')) {
reset_feed_cache();
}
});
ykarıdakı kodda hersey calısıyor fakat rss adreslerınden bır sefer ıslem yaptıgımda tekrar ıslem yapmıyor kontrol edıp gereklı duzenlemenyı yaptıktan sonra tam kodu yazrmısın bu kodda panele ekleme kısımlarını vs degıstırmemen gereklı cunku o zaman admın panelınde gozukmuyor