prefix . 'rsskategori'; // table name $charset_collate = $wpdb->get_charset_collate(); if ($wpdb->get_var("show tables like '$db_table_name'") != $db_table_name) { $sql = "CREATE TABLE $db_table_name ( id int(11) NOT NULL auto_increment, rsskategori varchar(250) NOT NULL, sitekategoriid int(11) NOT NULL, UNIQUE KEY id (id) ) $charset_collate;"; require_once ABSPATH . 'wp-admin/includes/upgrade.php'; dbDelta($sql); add_option('test_db_version', $test_db_version); } } register_activation_hook(_FILE_, 'db_olusturrss'); function my_cron_schedules($schedules) { $cronayari = get_option('cronrss'); if ($cronayari == '') { $cronayari = 10; } if (!isset($schedules['ayarcron'])) { $schedules['ayarcron'] = [ 'interval' => $cronayari * 60, 'display' => __('ayarcron'), ]; } return $schedules; } add_filter('cron_schedules', 'my_cron_schedules'); register_deactivation_hook(_FILE_, 'rssotomatikcalistirkapat'); function rssotomatikcalistirkapat() { $timestamp = wp_next_scheduled('rsscalistirotomatik'); wp_unschedule_event($timestamp, 'rsscalistirotomatik'); } register_activation_hook(_FILE_, 'rssotomatikcalistir'); function rssotomatikcalistir() { if (!wp_next_scheduled('rsscalistirotomatik')) { wp_schedule_event(time(), 'ayarcron', 'rsscalistirotomatik'); } add_option('cronrss', '10'); } add_action('rsscalistirotomatik', 'rsshabercekfonk'); function resimyukle($kaynak) { $rescek = file_get_contents($kaynak); $uzantial = explode('.', $kaynak); $uzanti = '.' . end($uzantial); $karistir = '/' . str_shuffle('kGrUTrG' . mt_rand(0, 8646714)); $resimisimi = wp_upload_dir()['basedir'] . '' . $karistir . $uzanti; $indir = fopen($resimisimi, 'a+'); fwrite($indir, $rescek); fclose($indir); return $resimisimi; } // resim yükleme function rsshabercekfonk() { global $wpdb; $url = 'https://www.igfhaber.com/rss-new/'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $data = curl_exec($ch); curl_close($ch); $parse = new SimpleXMLElement($data); foreach ($parse->channel->item as $item) { $baslik = sanitize_post($item->title); $icerik = sanitize_post($item->description); $kategori = sanitize_post($item->category); $resim = $item->image; $detay = "$icerik"; //$habersay = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->prefix}posts WHERE post_title='$baslik' and post_type='post'"); $habersay = post_exists("$baslik", '', '', 'post'); if ($habersay == 0) { $urunsay = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}rsskategori WHERE rsskategori='$kategori'"); $sitekategoriid = $urunsay->sitekategoriid; $sitekategoriid = sanitize_post($sitekategoriid); if (get_page_by_title("$baslik", 'OBJECT', 'post') == null) { $post_id = wp_insert_post([ 'post_author' => 1, 'post_title' => $baslik, 'post_content' => $detay, 'post_status' => 'publish', //'comment_status' => $yorumdurum, 'post_name' => $baslik, 'post_category' => [$sitekategoriid], //'tags_input' => $etiket, //'post_date' => $tarih ], true); if (is_wp_error($post_id)): $json['cevap'] = 'Hata'; else: $getImageFile = resimyukle($resim); $wp_filetype = wp_check_filetype($getImageFile, null); $attachment_data = [ 'post_mime_type' => $wp_filetype['type'], 'post_title' => sanitize_file_name($getImageFile), 'post_content' => '', 'post_status' => 'inherit', ]; $attach_id = wp_insert_attachment($attachment_data, $getImageFile, $post_id); require_once ABSPATH . 'wp-admin/includes/image.php'; $attach_data = wp_generate_attachment_metadata($attach_id, $getImageFile); wp_update_attachment_metadata($attach_id, $attach_data); set_post_thumbnail($post_id, $attach_id); $json['cevap'] = 'Tamam'; echo"
$baslik eklendi.
"; endif; } } else { echo"
$baslik önceden eklenmiş.
"; } } } function admin_page_createrss() { add_menu_page('RSS Genel Ayarlar', 'RSS Genel Ayarlar', 'manage_options', 'ayarlarrss', 'ayarlarrss'); add_menu_page('RSS Manuel Kontrol Et', 'RSS Bot Manuel Çalıştır', 'manage_options', 'rsshabercekfonk', 'rsshabercekfonk'); } add_action('admin_menu', 'admin_page_createrss'); function ayarlarrss() { ?>{ "@context": "https://schema.org", "@type": "BreadcrumbList", "itemListElement": [{ "@type": "ListItem", "position": 1, "item": { "@id": "http://www.tokathaber.com.tr", "name": "Ana Sayfa" } },{ "@type": "ListItem", "position": 2, "item": { "@id": "http://www.tokathaber.com.tr/niksar/", "name": "NİKSAR" } }] }