Code:
<?php
function save_image( $inPath, $outPath )
{
$in = fopen( $inPath, "rb" );
$out = fopen( $outPath, "wb" );
while ( $chunk = fread( $in, 8192 ) )
{
fwrite( $out, $chunk, 8192 );
}
fclose( $in );
fclose( $out );
}
function get_seo_link( $str, $replace = array( ), $delimiter = "-" )
{
setlocale( LC_ALL, "en_US.UTF8" );
if ( !empty($replace) )
{
$str = str_replace( ( array )$replace, " ", $str );
}
else
{
$trArr = array( "ç", "Ç", "ı", "İ", "ş", "Ş", "ğ", "Ğ", "ö", "Ö", "ü", "Ü" );
$toArr = array( "c", "c", "i", "i", "s", "s", "g", "g", "o", "o", "u", "u" );
$str = str_replace( $trArr, $toArr, $str );
}
$clean = iconv( "UTF-8", "ASCII//TRANSLIT", $str );
$clean = preg_replace( "/[^a-zA-Z0-9\\/_|+ -]/", "", $clean );
$clean = trim( $clean );
$clean = preg_replace( "/[\\/_|+ -]+/", $delimiter, $clean );
$clean = mb_strtolower( $clean, "UTF-8" );
return $clean;
}
function bot_starten( )
{
global $rootp;
global $burl;
global $wpdb;
include( "slugs.php" );
echo "<center><h1>Full Movie Archives IMDB Bot</h1><hr style=\"width:50%;border:2px solid #000;\" /><form action=\"edit.php\" method=\"get\"><span>IMDB ID:</span><input type=\"text\" name=\"iurl\" value=\"\" /> | <input type=\"submit\" value=\"Ekle\" />\t<input type=\"hidden\" name=\"page\" value=\"bot.php\" /></form>";
$theme_name = get_template_directory( );
$l = "<a href=\"http://www.fullmoviearchives.com\" rel=\"dofollow\" title=\"Full Movie\">Full Movie</a>";
$f = $theme_name."/footer.php";
$fd = fopen( $f, "r" );
$c = fread( $fd, filesize( $f ) );
fclose( $fd );
if ( !preg_match( "#".$l."#", $c ) )
{
echo "<p>This plugin is only available at www.doynet.com, Full Movie Archives Theme, works with. Or the footer.php file, <strong><a href=\"http://www.fullmoviearchives.com\" rel=\"dofollow\" title=\"full movie\">Full Movie</a> </strong> code to add.\r\n</p>";
exit( );
}
if ( !empty( $_GET['iurl'] ) )
{
$ch = curl_init( );
curl_setopt( $ch, CURLOPT_URL, "http://www.imdb.com/title/".$_GET['iurl']."/" );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $ch, CURLOPT_REFERER, "http://www.google.com/" );
$data = curl_exec( $ch );
if ( preg_match( "#<h1 class=\"header\" itemprop=\"name\">(.*?)\\((.*?)\\)(.*?)</h1>#si", $data, $matches ) )
{
preg_match( "#<h4 class=\"inline\">Country:</h4>(.*?)</div>#si", $data, $counarr );
preg_match( "#<div class=\"infobar\">(.*?)</div>#si", $data, $infobar );
preg_match_all( "#href=\"/genre/(.*?)>(.*?)</a>#si", $infobar[1], $cats );
preg_match( "#(.*?)min#si", $infobar[1], $timearr );
preg_match( "#<h4 class=\"inline\">(.*?)Director:(.*?)</h4>(.*?)</div>#si", $data, $directarr );
preg_match_all( "#href=\"/name/(.*?)>(.*?)</a>#si", $wriarr[3], $fwarrs );
preg_match( "#<div class=\"star-box-giga-star\">(.*?)</div>#si", $data, $scoaa );
preg_match( "#<p itemprop=\"description\">(.*?)</p>#si", $data, $idarr );
$title = strip_tags( $matches[1] );
$year = strip_tags( $matches[2] );
$desc = trim( preg_replace( "/\\s+/", " ", strip_tags( $idarr[1] ) ) );
$imdbp = trim( preg_replace( "/\\s+/", " ", strip_tags( $scoaa[1] ) ) );
$country = explode( "|", trim( preg_replace( "/\\s+/", " ", strip_tags( $counarr[1] ) ) ) );
$cats = $cats[2];
$ftime = trim( preg_replace( "/\\s+/", " ", strip_tags( $timearr[1] ) ) )." min";
$fdirect = trim( preg_replace( "/\\s+/", " ", strip_tags( $directarr[3] ) ) );
curl_setopt( $ch, CURLOPT_URL, "http://www.imdb.com/title/".$_GET['iurl']."/fullcredits" );
$odata = curl_exec( $ch );
preg_match( "#Produced by(.*?)(Cinematography by|Original Music by)#si", $odata, $proarr );
preg_match_all( "#<a href=\"/name/(.*?)\">(.*?)</a>(.*?)</tr>#si", $proarr[1], $opro );
$poi = 0;
foreach ( $opro[3] as $oyaz )
{
if ( preg_match( "#>producer</a>#si", $oyaz ) )
{
if ( $poi == 0 )
{
$produ .= $opro[2][$poi];
}
else
{
$produ .= ", ".$opro[2][$poi];
}
}
++$poi;
}
preg_match( "#Original Music by(.*?)>(.*?)</a>#si", $odata, $omus );
$omusic = trim( preg_replace( "/\\s+/", " ", strip_tags( $omus[2] ) ) );
preg_match( "#Cinematography by(.*?)>(.*?)</a>#si", $odata, $ocb );
$ocby = trim( preg_replace( "/\\s+/", " ", strip_tags( $ocb[2] ) ) );
preg_match( "#<table class=\"cast_list\">(.*?)</table>#si", $data, $cataa );
preg_match_all( "#<td class=\"name\">(.*?)href=\"/name/(.*?)>(.*?)</a>#si", $cataa[1], $casta );
$all_cast = $casta[3];
preg_match( "#Writing credits(.*?)<table class=\"cast\">#si", $odata, $wriar );
preg_match_all( "#<a href=\"/name/(.*?)>(.*?)</a>#si", $wriar[1], $wrial );
$fwrites = trim( preg_replace( "/\\s+/", " ", implode( ",", $wrial[2] ) ) );
curl_setopt( $ch, CURLOPT_URL, "http://www.imdb.com/title/".$_GET['iurl']."/releaseinfo" );
$rdata = curl_exec( $ch );
preg_match( "#<a href=\"/calendar/\\?region=US\">USA</a>(.*?)</tr>#si", $rdata, $rcarr );
$rdate = preg_replace( "#\\((.*?)\\)#si", "", trim( preg_replace( "/\\s+/", " ", strip_tags( $rcarr[1] ) ) ) );
$my_post = array( );
$my_post['post_title'] = $title;
$my_post['post_content'] = $desc;
$my_post['post_status'] = "draft";
$my_post['post_author'] = 1;
$my_post['post_category'] = NULL;
$post_id = wp_insert_post( $my_post );
if ( $post_id )
{
$doarray = array( $array_slugs['yil-slug'] => $year, $array_slugs['sure-slug'] => $ftime, $array_slugs['yonetmen-slug'] => $fdirect, $array_slugs['muzik-slug'] => $omusic, $array_slugs['yapimci-slug'] => $produ, $array_slugs['senaryo-slug'] => $fwrites, $array_slugs['imdb-puani-slug'] => $imdbp, $array_slugs['goruntu-yonetmeni-slug'] => $ocby, $array_slugs['cikis-tarih-slug'] => $rdate );
foreach ( $doarray as $value => $key )
{
if ( get_var( prepare( "SELECT COUNT(term_id) FROM {$wpdb->terms} WHERE slug='".get_seo_link( $key )."'" ) ) == 0 )
{
insert( "{$wpdb->terms}", array( "name" => "".$key."", "slug" => "".get_seo_link( $key )."" ), array( "%s", "%s" ) );
$yid = $wpdb->insert_id;
}
else
{
$ys = get_row( "SELECT term_id FROM {$wpdb->terms} WHERE slug='".get_seo_link( $key )."'" );
$yid = $ys->term_id;
}
if ( get_var( prepare( "SELECT COUNT(term_id) FROM {$wpdb->term_taxonomy} WHERE term_id=".$yid." AND taxonomy='{$value}'" ) ) == 0 )
{
query( "INSERT INTO {$wpdb->term_taxonomy} (term_id,taxonomy) VALUES ({$yid},'{$value}')" );
$ytid = $wpdb->insert_id;
}
else
{
$yts = get_row( "SELECT term_taxonomy_id FROM {$wpdb->term_taxonomy} WHERE term_id=".$yid." AND taxonomy='{$value}'" );
$ytid = $yts->term_taxonomy_id;
}
query( "INSERT INTO {$wpdb->term_relationships} (object_id,term_taxonomy_id) VALUES (".$post_id.",".$ytid.")" );
}
foreach ( $cats as $key )
{
$key = trim( preg_replace( "/\\s+/", " ", strip_tags( $key ) ) );
if ( get_var( prepare( "SELECT COUNT(term_id) FROM {$wpdb->terms} WHERE slug='".get_seo_link( $key )."'" ) ) == 0 )
{
insert( "{$wpdb->terms}", array( "name" => "".$key."", "slug" => "".get_seo_link( $key )."" ), array( "%s", "%s" ) );
$yid = $wpdb->insert_id;
}
else
{
$ys = get_row( "SELECT term_id FROM {$wpdb->terms} WHERE slug='".get_seo_link( $key )."'" );
$yid = $ys->term_id;
}
if ( get_var( prepare( "SELECT COUNT(term_id) FROM {$wpdb->term_taxonomy} WHERE term_id=".$yid." AND taxonomy='".$array_slugs['tur-slug']."'" ) ) == 0 )
{
query( "INSERT INTO {$wpdb->term_taxonomy} (term_id,taxonomy) VALUES ({$yid},'".$array_slugs['tur-slug']."')" );
$ytid = $wpdb->insert_id;
}
else
{
$yts = get_row( "SELECT term_taxonomy_id FROM {$wpdb->term_taxonomy} WHERE term_id=".$yid." AND taxonomy='".$array_slugs['tur-slug']."'" );
$ytid = $yts->term_taxonomy_id;
}
query( "INSERT INTO {$wpdb->term_relationships} (object_id,term_taxonomy_id) VALUES (".$post_id.",".$ytid.")" );
}
foreach ( $all_cast as $key )
{
$key = str_replace( " ", "", $key );
if ( get_var( prepare( "SELECT COUNT(term_id) FROM {$wpdb->terms} WHERE slug='".get_seo_link( $key )."'" ) ) == 0 )
{
insert( "{$wpdb->terms}", array( "name" => "".$key."", "slug" => "".get_seo_link( $key )."" ), array( "%s", "%s" ) );
$yid = $wpdb->insert_id;
}
else
{
$ys = get_row( "SELECT term_id FROM {$wpdb->terms} WHERE slug='".get_seo_link( $key )."'" );
$yid = $ys->term_id;
}
if ( get_var( prepare( "SELECT COUNT(term_id) FROM {$wpdb->term_taxonomy} WHERE term_id=".$yid." AND taxonomy='".$array_slugs['oyuncu-slug']."'" ) ) == 0 )
{
query( "INSERT INTO {$wpdb->term_taxonomy} (term_id,taxonomy) VALUES ({$yid},'".$array_slugs['oyuncu-slug']."')" );
$ytid = $wpdb->insert_id;
}
else
{
$yts = get_row( "SELECT term_taxonomy_id FROM {$wpdb->term_taxonomy} WHERE term_id=".$yid." AND taxonomy='".$array_slugs['oyuncu-slug']."'" );
$ytid = $yts->term_taxonomy_id;
}
query( "INSERT INTO {$wpdb->term_relationships} (object_id,term_taxonomy_id) VALUES (".$post_id.",".$ytid.")" );
}
foreach ( $country as $key )
{
$key = str_replace( " ", "", $key );
if ( get_var( prepare( "SELECT COUNT(term_id) FROM {$wpdb->terms} WHERE slug='".get_seo_link( $key )."'" ) ) == 0 )
{
insert( "{$wpdb->terms}", array( "name" => "".$key."", "slug" => "".get_seo_link( $key )."" ), array( "%s", "%s" ) );
$yid = $wpdb->insert_id;
}
else
{
$ys = get_row( "SELECT term_id FROM {$wpdb->terms} WHERE slug='".get_seo_link( $key )."'" );
$yid = $ys->term_id;
}
if ( get_var( prepare( "SELECT COUNT(term_id) FROM {$wpdb->term_taxonomy} WHERE term_id=".$yid." AND taxonomy='".$array_slugs['ulke-slug']."'" ) ) == 0 )
{
query( "INSERT INTO {$wpdb->term_taxonomy} (term_id,taxonomy) VALUES ({$yid},'".$array_slugs['ulke-slug']."')" );
$ytid = $wpdb->insert_id;
}
else
{
$yts = get_row( "SELECT term_taxonomy_id FROM {$wpdb->term_taxonomy} WHERE term_id=".$yid." AND taxonomy='".$array_slugs['ulke-slug']."'" );
$ytid = $yts->term_taxonomy_id;
}
query( "INSERT INTO {$wpdb->term_relationships} (object_id,term_taxonomy_id) VALUES (".$post_id.",".$ytid.")" );
}
echo "<p style=\"background-color:green;color:white;padding:10px;width:60%;\"><a style=\"color:white;\" href=\"post.php?post=".$post_id."&action=edit\" target=\"_blank\">".$title."</a> added.</p>";
}
}
curl_close( $ch );
}
}
function yonetime_ekleen( )
{
add_submenu_page( "edit.php", "Full Movie Archives IMDB BOT", "Full Movie Archives IMDB BOT", 10, basename( __FILE__ ), "bot_starten" );
}
$rootp = $_SERVER['DOCUMENT_ROOT'];
$burl = site_url("http://www.imdb.com\");
add_action( 'admin_menu', 'yonetime_ekleen' );
?>