WordPress PHP BOT – amerikaninsesi.com
amerikaninsesi.com sitesinde yayınlanan son haberini alır.
$userID = 1; // kullanıcının idsi
$categoryID = ‘1’; // kategori idsi
Neler Yapar
Haber resmini alır ve öne çıkarılmış görsel olarak ekler
Tagları alır ve ekler
Haber İçeriğini başlıkla beraber ekler.
$userID = 1; // kullanıcının idsi
$categoryID = ‘1’; // kategori idsi
Neler Yapar
Haber resmini alır ve öne çıkarılmış görsel olarak ekler
Tagları alır ve ekler
Haber İçeriğini başlıkla beraber ekler.
<?php
// require wp-load.php to use built-in WordPress functions
require_once("wp-load.php");
/*******************************************************
** POST VARIABLES
*******************************************************/
$site = "http://www.amerikaninsesi.com";
$data = file_get_contents($site);
function getData($data,$startTag,$finishTag){
$data= explode($startTag,$data);
$data= $data[1];
$data= explode($finishTag,$data);
$data= $data[0];
return $data;
}
$url_div= getData($data,'<div class="media-block has-img size-2">','<div class="thumb thumb16_9">');
$url = getData($url_div,'<a href="','"');
$url = $site.$url;
$resim_adi = getData($url,'a/','/');
$title = file_get_contents($url);
$baslik= getData($title,'<meta content="','" property="og:title" />');
$resim_tumb= getData($title,'<div class="separator">','</figure>');
$resim = getData($resim_tumb,'<img src="','"');
$resim_format = substr($resim, -4);
$detay = getData($title,'<div class="wsw">','<h3 class="section-head">');
$detay = strip_tags($detay);
$detay = nl2br($detay);
$detay = str_replace('<br />', '', $detay);
$resim_adi = $resim_adi.$resim_format;
$taglar_c = getData($title,'{"@context"','}</script>');
$taglar = getData($taglar_c,'"keywords":"','"');
$postType = 'post'; // set to post or page
$userID = 1; // set to user id
$categoryID = '1'; // set to category id.
$postStatus = 'publish'; // set to future, draft, or publish
$leadTitle = $baslik;
$leadContent = $detay;
//$leadContent .= ' <!--more--> <p>devamı yapmak için kullanılabilir.</p>';
/*******************************************************
** TIME VARIABLES / CALCULATIONS
*******************************************************/
// VARIABLES
$timeStamp = $minuteCounter = 0; // set all timers to 0;
$iCounter = 1; // number use to multiply by minute increment;
$minuteIncrement = 1; // increment which to increase each post time for future schedule
$adjustClockMinutes = 0; // add 1 hour or 60 minutes - daylight savings
// CALCULATIONS
$minuteCounter = $iCounter * $minuteIncrement; // setting how far out in time to post if future.
$minuteCounter = $minuteCounter + $adjustClockMinutes; // adjusting for server timezone
$timeStamp = date('Y-m-d H:i:s', strtotime("+$minuteCounter min")); // format needed for WordPress
/*******************************************************
** WordPress Array and Variables for posting
*******************************************************/
$new_post = array(
'post_title' => wp_strip_all_tags($leadTitle),
'post_content' => $leadContent,
'post_status' => $postStatus,
'post_date' => $timeStamp,
'post_author' => $userID,
'post_type' => $postType,
'tags_input' =>$taglar,
'post_category' => array($categoryID)
);
/*******************************************************
** WordPress Post Function
*******************************************************/
$post_id = wp_insert_post($new_post);
/*******************************************************
** SIMPLE ERROR CHECKING
*******************************************************/
// Add Featured Image to Post
$image_url = $resim; // Define the image URL here
$image_name = $resim_adi;
$upload_dir = wp_upload_dir(); // Set upload folder
$image_data = file_get_contents($image_url); // Get image data
$unique_file_name = wp_unique_filename( $upload_dir['path'], $image_name ); // Generate unique name
$filename = basename( $unique_file_name ); // Create image file name
// Check folder permission and define file location
if( wp_mkdir_p( $upload_dir['path'] ) ) {
$file = $upload_dir['path'] . '/' . $filename;
} else {
$file = $upload_dir['basedir'] . '/' . $filename;
}
// Create the image file on the server
file_put_contents( $file, $image_data );
// Check image file type
$wp_filetype = wp_check_filetype( $filename, null );
// Set attachment data
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_title' => sanitize_file_name( $filename ),
'post_content' => '',
'post_status' => 'inherit'
);
// Create the attachment
$attach_id = wp_insert_attachment( $attachment, $file, $post_id );
// Include image.php
require_once(ABSPATH . 'wp-admin/includes/image.php');
// Define attachment metadata
$attach_data = wp_generate_attachment_metadata( $attach_id, $file );
// Assign metadata to attachment
wp_update_attachment_metadata( $attach_id, $attach_data );
// And finally assign featured image to post
set_post_thumbnail( $post_id, $attach_id );
$finaltext = '';
if($post_id){
$finaltext .= 'Bot Çalıştı.<br>';
} else{
$finaltext .= 'Bot Çalışmadı Bazı Sorunlar Var.<br>';
}
echo $finaltext;
Yorumlar