wordpress auto poster script get reference code
used at freethemesupport.com
<?php
require_once('wp-load.php');
require_once('wp-config.php');
require_once('wp-includes/wp-db.php');
require_once('wp-admin/includes/taxonomy.php');
error_reporting( E_ALL );
class wp_rest{
/* Reference
CreatePost:
AddComment:
ReplyToComment:
UploadMedia:
*/
// Creating WordPress Post
public function CreatePost($title,$content,$category){
// Create post object
$my_post = array(
'post_title' => wp_strip_all_tags( $title ),
'post_content' => $content,
'post_status' => 'publish',
'post_author' => 1,
'post_category' => $category,
'post_date' => date('Y-m-d H:i:s')
);
// Insert the post into the database
return wp_insert_post( $my_post );
}
// Add Comments
public function AddComment($email,$content,$post_id,$reply,$y,$m,$d,$h,$i,$s,$email2){
$agent = $_SERVER['HTTP_USER_AGENT'];
$ax = explode("@",$email);
$data = array(
'comment_post_ID' => $post_id,
'comment_author' => $ax[0],
'comment_author_email' => $email,
'comment_content' => $content,
//'comment_author_IP' => '127.3.1.1',
'comment_agent' => $agent,
'comment_date' => date("$y-$m-$d $h:$i:$s"),
//'comment_date_gmt' => date('Y-m-d H:i:s'),
'comment_approved' => 1,
);
$comment_id = wp_insert_comment($data);
echo $comment_id;
// handling reply to main comment.. only reply when it's empty
if ($reply != ''){
$this->ReplyToComment($comment_id,$reply,date("$y-$m-$d H:i:s"),$post_id,$email2);
}
}
//return $comment_id;
// Add Reply To Comments
function ReplyToComment($id,$reply,$date,$post_id,$email = "filereal@live.com"){
$agent = $_SERVER['HTTP_USER_AGENT'];
$data = array(
'comment_post_ID' => $post_id,
'comment_author' => 'Freethemesupport',
'comment_author_email' => 'filereal@live.com',
'comment_content' => $reply,
//'comment_author_IP' => '127.3.1.1',
'comment_agent' => $agent,
'comment_date' => $date,
'comment_approved' => 1,
'comment_parent' => $id
);
$comment_id = wp_insert_comment($data);
return $comment_id;
}
function S_ReplyToComment($id,$reply,$date,$post_id,$email){
$agent = $_SERVER['HTTP_USER_AGENT'];
$username = explode("@",$email);
if ($username[0] == "filereal"){
$username = "themepedia";
}else{
$username = $username[0];
}
$data = array(
'comment_post_ID' => $post_id,
'comment_author' => $username,
'comment_author_email' => $email,
'comment_content' => $reply,
//'comment_author_IP' => '127.3.1.1',
'comment_agent' => $agent,
'comment_date' => $date,
'comment_approved' => 1,
'comment_parent' => $id
);
$comment_id = wp_insert_comment($data);
return $comment_id;
}
function SetPostImage($attachmentid,$postid){
echo set_post_thumbnail( $postid, $attachmentid );
}
// Upload Media
function UploadMedia($file){
$file = ''.$file;
$filename = basename($file);
$attachment_id = "";
$upload_file = wp_upload_bits($filename, null, file_get_contents($file));
if (!$upload_file['error']) {
$wp_filetype = wp_check_filetype($filename, null );
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_parent' => @$parent_post_id,
'post_title' => preg_replace('/\.[^.]+$/', '', $filename),
'post_content' => '',
'post_status' => 'inherit'
);
$attachment_id = wp_insert_attachment( $attachment, $upload_file['file'], @$parent_post_id );
if (!is_wp_error($attachment_id)) {
require_once(ABSPATH . "wp-admin" . '/includes/image.php');
$attachment_data = wp_generate_attachment_metadata( $attachment_id, $upload_file['file'] );
wp_update_attachment_metadata( $attachment_id, $attachment_data );
}
}
//unlink($file);
return $attachment_id;
}
}
function checkRemoteFile($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
// don't download content
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
if($result !== FALSE)
{
return true;
}
else
{
return false;
}
}
$wp = new wp_rest();
// [TEST]
if (isset($_GET['media'])){
// uploading the media and getting an id for media
echo $wp->UploadMedia($_GET['media']);
exit();
}
if (isset($_GET['attatch_id'])){
$wp->SetPostImage($_GET['attatch_id'],$_GET['post_id']);
}
function exclodeSpecialWords($text){
$ret = 0;
if (strpos($text, 'username') !== false) {
$ret = 1;
}
if (strpos($text, 'email') !== false) {
$ret = 1;
}
if (strpos($text, 'password') !== false) {
$ret = 1;
}
if (strpos($text, 'password') !== false) {
$ret = 1;
}
if (strpos($text, 'Version') !== false) {
$ret = 1;
}
return $ret;
}
function getOnePTagFromTemplate(){
$all_p = file_get_contents('data/p_template.html');
$all_p = explode(";",$all_p);
$random = rand(0,9);
return $all_p[$random];
}
function normalizeString ($str = '')
{
$str = strip_tags($str);
$str = preg_replace('/[\r\n\t ]+/', ' ', $str);
$str = preg_replace('/[\"\*\/\:\<\>\?\'\|]+/', ' ', $str);
$str = preg_replace("/(&)([a-z])([a-z]+;)/i", '$2', $str);
$str = str_replace('%', '-', $str);
return $str;
}
function getLiTags($allLI){
$LiContent="";
$numbers = range(1, count($allLI)-1);
shuffle($numbers);
$countli=0;
for($i=0;$i<count($allLI)-1;$i++){
if(exclodeSpecialWords($allLI[$numbers[$i]])){ //
continue;
}
$LiContent.=$allLI[$numbers[$i]];
if($countli>=10){
break;
}
$countli++;
}
return $LiContent;
}
function getPTags($paragraph){
$para="";
$numbers = range(1, count($paragraph)-1);
shuffle($numbers);
$countli=0;
for($i=0;$i<count($paragraph)-1;$i++){
if(exclodeSpecialWords($paragraph[$numbers[$i]])){ //
continue;
}
$para.=$paragraph[$numbers[$i]];
if($countli>=5){
break;
}
$countli++;
}
return $para;
}
if (isset($_GET['fname'])){
$wp->AddNewUser($_GET['username'],$_GET['pass'],$_GET['email'],$_GET['fname'],$_GET['lname']);
}
if (isset($_POST['ree'])){
$email = $_POST['email'];
$content = $_POST['content'];
$post_id = $_POST['post_id'];
$reply = $_POST['reply'];
$y = $_POST['y'];
$m = $_POST['m'];
$d = $_POST['d'];
$h = $_POST['h'];
$i = $_POST['i'];
$s = $_POST['s'];
$id = $_POST['cid'];
// these are all required fields
// ($email,$content,$post_id,$reply,$y,$m,$d,$h,$i,$s){
// ReplyToComment($id,$reply,$date,$post_id,$email = "filereal@live.com")
$datee = date("$y-$m-$d $h:$i:$s");
$wp->S_ReplyToComment($id,$content,$datee,$post_id,$email);
}
if (isset($_POST['comment'])){
$email = $_POST['email'];
$content = $_POST['content'];
$post_id = $_POST['post_id'];
$reply = $_POST['reply'];
$y = $_POST['y'];
$m = $_POST['m'];
$d = $_POST['d'];
$h = $_POST['h'];
$i = $_POST['i'];
$s = $_POST['s'];
// these are all required fields
// ($email,$content,$post_id,$reply,$y,$m,$d,$h,$i,$s){
$wp->AddComment($email,$content,$post_id,$reply,$y,$m,$d,$h,$i,$s,'filereal@live.com');
//$wp->ReplyToComment($commentid,'thank you for your input..');
}
if (isset($_GET['test'])){
$grav_url = "https://www.gravatar.com/avatar/" . md5( strtolower( trim( $_GET['test'] ) ) ) . "?d=" . urlencode( $default ) . "&s=" . $size."&d=404";
if (!checkRemoteFile($grav_url)){
echo '0';
}else{
echo '1';
}
echo "<img src='".$grav_url."'/>";
}
// 1109 1110
function addWatermark($image_URL){
$image = file_get_contents($image_URL);
$filename="thumbnail.png";
file_put_contents("data/$filename",$image);
sleep(1);
$mime = mime_content_type('data/'.$filename);
$ext="jpg";
if($mime=="image/jpeg"){
$im = imagecreatefromjpeg('data/thumbnail.png');
}else{
$ext="png";
$im = imagecreatefrompng('data/thumbnail.png');
}
$stamp = imagecreatefrompng('data/watermark.png');
if(!$im){
die("issue in creating image try again please ");
}
// Set the margins for the stamp and get the height/width of the stamp image
$marge_right = 0;
$marge_bottom = 0;
$sx = imagesx($stamp);
$sy = imagesy($stamp);
// Copy the stamp image onto our photo using the margin offsets and the photo
// width to calculate positioning of the stamp.
//imagecopy(dst_img, src_im_that_is_fit_on_dest, dst_x, dst_y, src_x, src_y, src_width, src_height) //use to copy two or more images to 1
imagecopy($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp));
if($ext=="png"){
imagepng($im,'data/output.png');
imagedestroy($im);
return "output.png";
}else{
imagejpeg($im,'data/output.png');
imagedestroy($im);
return "output.png";
}
}
function getAllCat($foldername){ // return all cats that have more than 4 files (non empty)
$path = "data/$foldername/categories.txt";
$folderinlower=strtolower($foldername);
$allcatsare=array();
$allCats= file_get_contents($path);
$allCats=explode("\n",$allCats);
foreach($allCats as $cat){
$c= str_replace("https://themeforest.net/category/$folderinlower/","",$cat); //change this also
$dir_path = "data/$foldername"."/".trim($c)."";
$num = scandir($dir_path);
if (count($num) <= 4){
}else{
$allcatsare[]=$c;
}
}
return $allcatsare;
}
function getRandomFileFromFolder($folderName){
$folderName = trim($folderName);
$path ="data/WordPress/$folderName";
$files = array_diff(scandir($path), array('.', '..','ScrapedRowNo.txt','urls.txt'));
if(count($files)>0){
foreach($files as $file){
return trim($file);
die;
}
}else{
return 0;
}
}
##################################################################################
if (isset($_GET['post'])){
$foldername="WordPress";
$allCats = getAllCat($foldername);
print_r($allCats);
############################ To create bulk categories
/* foreach($allCats as $c){
wp_create_category($c, 24 );
}
die; */
######################################################
$pickCategory = (rand(0,count($allCats)-1));; //anyrandom number b-w 0 to n
$catName = trim($allCats[$pickCategory]); //random choose an cat ie apps
$catId = get_cat_ID($catName); //id of selected category
$fileName = getRandomFileFromFolder($catName); //json file
$path ="data/$foldername/$catName/$fileName";
echo $catName."<br/>";
echo $catId."<br/>";
echo $path."<br/>";
if(!$fileName){ echo "file not found";die(); }
$jsondata = json_decode(file_get_contents($path));
$image_URL = $jsondata->imageURL;
////////// save imageimage_URL for uploading
if($image_URL){
///////////////////save image + add watermark
$imagenameReturn = addWatermark($image_URL); // It will create an image with watermark//https://themepedia.net/data/output.png
}
$image = "data/$imagenameReturn";
$titleAppend = array("FREE DOWNLOAD","NULLED THEME", "FREE","FREE THEME", "cracked theme");
$title = normalizeString($jsondata->title)." ".$titleAppend[rand(0,3)];
$author = $jsondata->author;
$price = $jsondata->price;
$saleCount = $jsondata->saleCount;
$demourl = $jsondata->demourl;
$paragraph = $jsondata->paragraph;
$allLI = $jsondata->allLI;
$ourl = $jsondata->url;
$content_random_oneP = getOnePTagFromTemplate();
$content_random_LI = getLiTags($allLI);
$content_random_P = getPTags($paragraph);
$rating = round($jsondata->rating);
$starsYellow = str_repeat('<span class="fa fa-star" style="color:orange;"></span>',$rating);
$starsGray = str_repeat('<span class="fa fa-star" style="color:gray;"></span>',5-$rating);
$finalRating = $starsYellow."".$starsGray;
//echo $content_random_oneP." ".$content_random_LI." ".$content_random_P;
//send request to filesonice me
$url = 'https://filesonic.me/secret_sex.php';
$size = (rand(12,31));
$ch = curl_init($url);
$jsonData = array(
'filename' => $title." + Nulled .rar",
'size' => $size." MB",
'path' => $foldername.'2021/'
);
$jsonDataEncoded = json_encode($jsonData);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
if($result){
$result = json_decode($result);
if(isset($result->status) && $result->status==200){
$uid = $result->u_id;
$template = file_get_contents('data/content.html');
$template = str_replace("[ONEPTAG]",$content_random_oneP,$template);
$template = str_replace("[RATING]",$finalRating,$template);
$template = str_replace("[SALESCOUNT]",$saleCount,$template);
$template = str_replace("[AUTHOR]",$author,$template);
$template = str_replace("[DEMOURL]",$demourl,$template);
$template = str_replace("[DETAILS]",$content_random_P,$template);
$template = str_replace("[LILIST]",$content_random_LI,$template);
$template = str_replace("[FILESONIC]","https://filesonic.me/downloader.php?id=$uid",$template);
$template = str_replace("[TITLE]",$title,$template);
$template = str_replace("[OURL]",$ourl,$template);
$template = str_replace("[description]","Download free ".$title." from Freethemesupport",$template);
$id = $wp->CreatePost($title,$template,array($catId));
$image_id = $wp->UploadMedia($image);
$wp->SetPostImage($image_id,$id);
$descriptionX="Download free ".$title." from Freethemesupport.com having nulled version";
//echo $id;
//$id = $wp->CreatePost($_POST['title'],$_POST['content'],explode(',',$_POST['cat']));
update_post_meta ( $id, 'author', $author );
update_post_meta ( $id, 'themename', $title );
update_post_meta ( $id, 'description', $descriptionX );
//update_post_meta ( $id, 'rating', $_POST['rating'] );
//update_post_meta ( $id, 'totalreviews', $_POST['totalreviews'] );
unlink($path);
echo "done from $path";die;
}
}else{
echo "failed try again";
}
}
##################################################################################
?>