<?php
set_time_limit(0);
session_start();
function redir(){
header('location: /wp-login.php?redirect_to=http://www.MISITIO.com/postearHUB.php');
die();
}
require('wp-config.php');
if (!is_user_logged_in()){
redir();
}
$USER = wp_get_current_user();
if($USER->data->ID !="1"){
redir();
}
$TAMANIO = "300x240"; //tamaño de las imagenes destacadas! colocar el tamaño para que queen las destacadas bien
$MAX = "5"; //cantidad de videos maximo... -1 = TODOS!
$URL[] = "http://www.pornhub.com/feed/amateur.xml";
$URL[] = "http://www.pornhub.com/feed/anal.xml";
$URL[] = "http://www.pornhub.com/feed/babe.xml";
$URL[] = "http://www.pornhub.com/feed/blonde.xml";
$URL[] = "http://www.pornhub.com/feed/bbw.xml";
$URL[] = "http://www.pornhub.com/feed/big-tits.xml";
$URL[] = "http://www.pornhub.com/feed/latina.xml";
$URL[] = "http://www.pornhub.com/feed/lesbian.xml";
$URL[] = "http://www.pornhub.com/feed/milf.xml";
$URL[] = "http://www.pornhub.com/feed/pornstar.xml";
$URL[] = "http://www.pornhub.com/feed/teen.xml";
$URL[] = "http://www.pornhub.com/feed/webcam.xml";
$URL[] = "http://www.pornhub.com/feed/celebrity.xml";
$URL[] = "http://www.pornhub.com/feed/college.xml";
$URL[] = "http://www.pornhub.com/feed/red-head.xml";
$i = array_rand($URL,1); //una url al azar...
$A = file_get_contents($URL[$i]);
preg_match_all("|<item>(.*)</item>|sU",$A,$CONTE);
$CONTAV = 0;
foreach($CONTE[1] as $DTO){
if($MAX == $CONTAV) die("Fin por cantidad maxima de videos!");
$P = DameD($DTO);
if(file_exists("posteado/".$P['id'])) continue;
if(!$P['valido']) continue;
file_put_contents("posteado/".$P['id'],'');
$TIT = Limpiame(trim(strip_tags($P['caption'])));
$my_post = array(
'post_title' => $TIT,
'post_content' => $P['video_url'].'<p>'.$TIT.' | '.$P['tags'].'</p>',
'post_status' => 'publish',
'post_type' => 'post',
'post_author' => 1,
'post_category' => array(0),
'tags_input' => $P['tags'],
);
//Postear
$post_id = wp_insert_post( $my_post );
//Obtener Captura
require_once(ABSPATH . 'wp-admin/includes/media.php');
require_once(ABSPATH . 'wp-admin/includes/file.php');
require_once(ABSPATH . 'wp-admin/includes/image.php');
$image = media_sideload_image($P['thumbnail_url'], $post_id, $TIT,'src');
//La imagen es corrupta o no se pudo descargar!
if(!is_wp_error($image)){
$filename = str_replace(get_option('home'),"", $image);
$filename = substr($filename,0,strlen($filename)-4)."-".$TAMANIO.".jpg";
$wp_filetype = wp_check_filetype(basename($filename), null );
$wp_upload_dir = wp_upload_dir();
$attachment = array(
'guid' => $wp_upload_dir['url'] . '/' . basename( $filename ),
'post_mime_type' => $wp_filetype['type'],
'post_title' => trim(strip_tags($P['caption'])),
'post_content' => '',
'post_status' => 'inherit'
);
$attach_id = wp_insert_attachment( $attachment, $filename, $post_id );
$attach_data = wp_generate_attachment_metadata( $attach_id, $filename );
wp_update_attachment_metadata( $attach_id, $attach_data );
add_post_meta($post_id, '_thumbnail_id', $attach_id, true);
}else{
echo "<br/>(Error descargando archivo==".$post_id.")[".$image->get_error_message()."]<br/>\n";
}
$URLPOST = get_post_permalink($post_id, true);
echo $post_id." (".$TIT.")<br/>";
if($TEST) die();
$CONTAV++;
}
function DameD($D){
preg_match("|<title><!\[CDATA\[(.*)\]\]></title>|sU",$D,$TIT);
preg_match("|<link>(.*)</link>|sU",$D,$LNK);
preg_match("|<thumb_large>(.*)</thumb_large>|sU",$D,$IMG);
preg_match("|<keywords><!\[CDATA\[(.*)\]\]></keywords>|sU",$D,$KEY);
if($KEY[1]=="") $KEY[1] = "video,porno";
if(!preg_match('/[^\w ]/u',$TIT[1])) $P['valido'] = 0; else $P['valido'] = 1;
$P['id'] = str_replace('http://www.pornhub.com/view_video.php?viewkey=','',$LNK[1]);
$P['caption'] = $TIT[1];
$P['video_url'] = '<div class="videoWrapper"><iframe src="http://www.pornhub.com/embed/'.$P['id'].'" width="100%" id="videoi" scrolling="no" seamless="seamless"></iframe></div>';
$P['thumbnail_url'] = $IMG[1];
$P['tags'] = str_replace('-',' ',$KEY[1]);
return $P;
}
function Limpiame($T){
if($T!=""){
$A = explode(":",$T);
if($A[0]!=""){
$I = count($A) -1;
$T = $A[$I];
}
}
return $T;
}
?>