вопрос
Например к постеру, скринам, описанию, самому торрент файлу.
Как я понимаю тут идет забивка сразу в базу
Как я понимаю тут идет забивка сразу в базу
<?php
// Only support cli
if( 'cli' !== PHP_SAPI ) {
//exit(1);
}
echo 'Starting...';
include('config.php');
// Constants
define('DS', DIRECTORY_SEPARATOR);
define('PS', PATH_SEPARATOR);
define('TMP_PATH', 'bucket');
if(!is_dir(TMP_PATH)) {
mkdir (TMP_PATH, 0777);
}
// Define full application path
define('APPLICATION_PATH', dirname(__FILE__));
define ( 'DATALIFEENGINE', true );
define ( 'ENGINE_DIR', $parser_config['site_path'] . '/engine' );
if( function_exists('ini_set') ) {
ini_set('memory_limit', '100M');
ini_set("max_execution_time", "450");
}
include($parser_config['site_path'] . 'engine/classes/mysql.php');
include($parser_config['site_path'] . 'engine/data/dbconfig.php');
set_include_path(
APPLICATION_PATH . DS . 'libs' . DS .
get_include_path()
);
include('libs/Zend/Dom/Query.php');
$db->query("SET NAMES UTF8");
$db->query( "SELECT * FROM `" . PREFIX . "_parser_rutor_settings`" );
$category = array();
$sort_film_cat = array();
$sort_serial_cat = array();
while ( $row = $db->get_array() ) {
if($row['state'] == 1) {
if($row['cat_id_rutor_parent'] == 1 && $row['regex'] != '') {
$sort_film_cat[$row['cat_id_site']] = $row['regex'];
} else if($row['cat_id_rutor_parent'] == 4 && $row['regex'] != '') {
$sort_serial_cat[$row['cat_id_site']] = $row['regex'];
} else {
$category[] = $row;
}
}
}
function init() {
$content = getContent();
$content = sortContent($content);
}
function getContent() {
global $category;
$contents = array();
foreach($category as $k => $cat) {
$content = getContentUrl('http://mirror-rutor.org/rss.php?full='.$cat['cat_id_rutor']);
/*if($cat['cat_id_rutor'] == 7) {
$content = file_put_contents('123.txt', str_replace("5","", $content));
}*/
if($cat['cat_id_rutor'] == 7) {
$content = str_replace(chr(0),"", $content);
}
$dom = new Zend_Dom_Query($content);
try {
$results = $dom->queryXpath("//channel//item");
} catch(Exception $e) {
unset($category[$k]);
continue;
}
foreach ($results as $key => $r) {
if($key == 0) continue;
$children = $r->childNodes;
$news = array();
$counter = 0;
foreach($children as $c) {
$textContent = trim($c->textContent);
if(!empty($textContent)) {
$news[$counter] = $textContent;
++$counter;
}
}
$news[1] = substr($news[1], 7);
$id = preg_replace('/[^\d]/', '', $news[3]);
$contents[$cat['cat_id_site']][$id] = $news;
}
}
return $contents;
}
function sortContent(array $content)
{
global $db, $parser_config;
$k = 0;
foreach($content as $catId => $c) {
foreach($c as $id => $val) {
$row = $db->super_query( "SELECT count(tid) AS count FROM `" . PREFIX . "_parser_rutor_log` WHERE `tid` = $id" );
if($row['count'] != 0) {
//unset($content[$catId][$id]);
continue;
}
$torrentFile = downloadTorrentFile('http://mirror-rutor.org/download/'.$id, 'http://mirror-rutor.org');
addNews($val[1], $val[0], sortingCategory( $catId, $val[0]), $torrentFile);
$db->query( "INSERT INTO `" . PREFIX . "_parser_rutor_log` (`tid`, `time`) VALUES ($id, ".time().")" );
}
$k++;
}
//return $content;
return true;
}
function getContentUrl($uri)
{
sleep(rand(1, 3));
$ch = curl_init($uri);
curl_setopt ($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; rv:8.0.1) Gecko/20100101 Firefox/8.0.1');
curl_setopt ($ch, CURLOPT_REFERER, 'http://mirror-rutor.org');
curl_setopt ($ch, CURLOPT_POST, 0);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_ENCODING, 'gzip');
$result = curl_exec ($ch);
if($result == false) {
exit(PHP_EOL . 'Connection problem.' . PHP_EOL);
}
$content = curl_multi_getcontent ($ch);
curl_close ($ch);
return $content;
}
function downloadTorrentFile($url, $reffer) {
global $parser_config;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; rv:8.0.1) Gecko/20100101 Firefox/8.0.1');
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_exec($ch);
$header = curl_multi_getcontent($ch);
preg_match('/filename="(.*)"/', $header, $matches);
$fileName = str_replace(" ", "_", $matches[1]);
$fileName = totranslit( $fileName, false, false );
$fileName = str_replace('[mirror-rutor.org]', $parser_config['torrent_prefix'], $fileName);
curl_close($ch);
$fp = fopen(APPLICATION_PATH . '/'.TMP_PATH.'/'.$fileName, 'w');
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; rv:8.0.1) Gecko/20100101 Firefox/8.0.1');
curl_setopt($ch, CURLOPT_REFERER, $reffer);
sleep(1);
curl_exec($ch);
curl_close($ch);
fclose($fp);
return $fileName;
}
function addNews($html, $title, $catId, $torrentFile) {
global $parser_config, $authors, $db;
$author = $authors[array_rand($authors)];
$thistime = date( "Y-m-d H:i:s", time() );
$db->query( "INSERT INTO `" . PREFIX. "_post` (`autor`, `date`) VALUES ('$author', '$thistime')" );
$newsId = $db->insert_id();
$file_prefix = time() + mt_rand( 1, 100 ).'_';
rename(APPLICATION_PATH . '/'.TMP_PATH.'/' . $torrentFile, $parser_config['site_path'].'uploads/files/'.$file_prefix.$torrentFile);
$db->query( "INSERT INTO `" . PREFIX. "_files` (news_id, name, onserver, author, date) values ('$newsId', '$torrentFile', '{$file_prefix}{$torrentFile}', '$author', ".time().")" );
$attachment_id = $db->insert_id();
$html = $db->safesql($html).'<br /><br />[attachment='.$attachment_id.']';
$title = $db->safesql($title);
$tags = '';
$alt_name = totranslit( stripslashes( $title ), true, false );
$db->query( "UPDATE `" . PREFIX . "_post` SET short_story='$html', full_story='$html', title='$title', category='$catId', alt_name='$alt_name', allow_br=1, tags='$tags', metatitle = '$title' WHERE id=$newsId" );
$db->query( "UPDATE `" . PREFIX . "_users` SET news_num=news_num+1 WHERE name='$author'" );
echo '.';
}
function totranslit($var, $lower = true, $punkt = true) {
global $langtranslit;
if ( is_array($var) ) return "";
if (!is_array ( $langtranslit ) OR !count( $langtranslit ) ) {
$langtranslit = array(
'а' => 'a', 'б' => 'b', 'в' => 'v',
'г' => 'g', 'д' => 'd', 'е' => 'e',
'ё' => 'e', 'ж' => 'zh', 'з' => 'z',
'и' => 'i', 'й' => 'y', 'к' => 'k',
'л' => 'l', 'м' => 'm', 'н' => 'n',
'о' => 'o', 'п' => 'p', 'р' => 'r',
'с' => 's', 'т' => 't', 'у' => 'u',
'ф' => 'f', 'х' => 'h', 'ц' => 'c',
'ч' => 'ch', 'ш' => 'sh', 'щ' => 'sch',
'ь' => '', 'ы' => 'y', 'ъ' => '',
'э' => 'e', 'ю' => 'yu', 'я' => 'ya',
"ї" => "yi", "є" => "ye",
'А' => 'A', 'Б' => 'B', 'В' => 'V',
'Г' => 'G', 'Д' => 'D', 'Е' => 'E',
'Ё' => 'E', 'Ж' => 'Zh', 'З' => 'Z',
'И' => 'I', 'Й' => 'Y', 'К' => 'K',
'Л' => 'L', 'М' => 'M', 'Н' => 'N',
'О' => 'O', 'П' => 'P', 'Р' => 'R',
'С' => 'S', 'Т' => 'T', 'У' => 'U',
'Ф' => 'F', 'Х' => 'H', 'Ц' => 'C',
'Ч' => 'Ch', 'Ш' => 'Sh', 'Щ' => 'Sch',
'Ь' => '', 'Ы' => 'Y', 'Ъ' => '',
'Э' => 'E', 'Ю' => 'Yu', 'Я' => 'Ya',
"Ї" => "yi", "Є" => "ye",
);
}
$var = trim( strip_tags( $var ) );
$var = preg_replace( "/\s+/ms", "-", $var );
$var = strtr($var, $langtranslit);
if ( $punkt ) $var = preg_replace( "/[^a-z0-9\_\-\[\]].]+/mi", "", $var );
else $var = preg_replace( "/[^a-z0-9\_\-\[\]\.]+/mi", "", $var );
$var = preg_replace( '#[\-]+#i', '-', $var );
if ( $lower ) $var = strtolower( $var );
$var = str_ireplace( ".php", "", $var );
$var = str_ireplace( ".php", ".ppp", $var );
if( strlen( $var ) > 200 ) {
$var = substr( $var, 0, 200 );
if( ($temp_max = strrpos( $var, '-' )) ) $var = substr( $var, 0, $temp_max );
}
return $var;
}
function sortingCategory($cat, $title) {
global $category, $sort_film_cat, $sort_serial_cat, $db;
$row = $db->super_query( "SELECT cat_id_rutor FROM `" . PREFIX . "_parser_rutor_settings` WHERE cat_id_site=$cat LIMIT 1" );
if($row['cat_id_rutor'] == 1 || $row['cat_id_rutor'] == 5) {
foreach($sort_film_cat as $key => $value) {
if(strpos($title, $value)) {
return $key;
}
}
}
if($row['cat_id_rutor'] == 4) {
foreach($sort_serial_cat as $key => $value) {
if(strpos($title, $value)) {
return $key;
}
}
}
return $cat;
}
init();
$db->query( "DELETE FROM `" . PREFIX . "_parser_rutor_log` WHERE time < ".time()."-604800");
echo PHP_EOL . 'Complete!' . PHP_EOL;