Еще актуален, как то работа с одним человек по поддержке данного скрипта, ушли в разные отросли решил выложить юзайте... PHP: <?php set_time_limit(0); ignore_user_abort(1); class db{} /** * Изменить на свой путь. Нужен конфиг от БД. **/ include('/home/zlowarez/www/engine/data/dbconfig.php'); class grabber{ /** * MySQL Link */ var $link = null; /** * Для сравнения заголовком новостей, чтобы не постить одинаковые */ var $last_titles = array(); /** * Спарсеные новости */ var $news = array(); /** * Временные данные */ var $temp = array(); /** * Имя автора, от котрого будут идти новости */ var $autor_name = 'Admin'; /** * автоматическое добавление в конец новости этой строки */ var $news_footer = '<br><br>Не забудьте зайти еще раз на сайт www.zlowarez.com '; var $sites = array( // варезки // array( 'url' => 'it-warez.com', 'cat' => array( 'my' => 5, 'remote' => 'mobile/' ), 'title_regex' => '<TD height="30" background="/templates/it-warez/images/block2.gif" class=capmain><FONT size=1> [<b> <a href="BOMBTEXT">BOMBTEXT </a> </b>] <B>BOMBNEEDEDTEXT</B></FONT></TD>', // название новости 'title_full_regex' => '<TD height="30" bordercolor="#FFFFFF" background="/templates/it-warez/images/block2.gif" bgcolor="#FFFFFF" class=capmain><FONT size=1> [<b> <a href="BOMBTEXT">BOMBTEXT</a> </b>] <B>BOMBNEEDEDTEXT</B></FONT></TD>', //тоже самое 'link_regex' => '<a href="BOMBNEEDEDTEXT">Подробнее</a>', // ссылка на полную новость 'news_regex' => '<div id=\'news-id-BOMBDIGITAL\'><div align="center"><img src="BOMBNEEDEDTEXT" BOMBTEXT/></div>BOMBNEEDEDTEXT</div> <div class="rating" style="float:left;">', // ссылка на превью 'preview_regex' => '<div id=\'news-id-BOMBDIGITAL\'><div align="center"><img src="BOMBNEEDEDTEXT" BOMBTEXT/></div>BOMBNEEDEDTEXT</div> <div class="rating" style="float:left;">', // на полную 'cookie' => 'PHPSESSID=98bq6uisidvgehjh5vap62pkc5; dle_name=Code+Hunter; dle_password=c5dfba92ac7f51d03e45fdac5bd91b95; dle_newpm=0', ), ); function grabber(){ $this->link = mysql_connect(DBHOST, DBUSER, DBPASS) or die(mysql_error()); mysql_select_db(DBNAME, $this->link) or die(mysql_error()); if(defined('COLLATE')){ mysql_unbuffered_query("SET NAMES " . COLLATE, $this->link); } foreach($this->sites as $array){ $this->grab_news($array); } } function grab_news($array){ $result = mysql_query("SELECT 'title' FROM '" . PREFIX ."_post' WHERE 'category' = '{$array['cat']['my']}' ORDER BY 'id' DESC LIMIT 20", $this->link); $this->chk_result($result); while($data = mysql_fetch_array($result, MYSQL_ASSOC)){ $this->last_titles[$array['cat']['my']][] = $data; } $array['title_regex'] = '/' . str_replace(array('/', 'BOMBNEEDEDTEXT', 'BOMBDIGITAL'), array('\/', '.*?','[\d]*'), preg_quote($array['title_regex'])) .'/i'; $array['preview_regex'] = '/'. str_replace(array('/', 'BOMBNEEDEDTEXT', 'BOMBTEXT', 'BOMBDIGITAL'), array('\/', '(.*?)', '.*?','[\d]*'), preg_quote($array['preview_regex'])) .'/is'; $text = file_get_contents('http://' . $array['url'] . '/' . $array['cat']['remote']); if($text == ''){ return false; } preg_match_all($array['title_regex'], $text, $titles); preg_match_all($array['preview_regex'], $text, $preview); // die(print_r($preview)); foreach($preview[1] as $value){ $p[] = strip_tags($value, '<img><a>'); } $this->temp['title'] = array_map('strip_tags', $titles[0]); $this->temp['preview'] = $p; // print_r ($this->temp['title']); echo '<br><br>'; // die(print_r($this->temp['preview'])); $i = 0; foreach($titles[0] as $title){ $title = strip_tags($title); $find = $this->my_array_search($title, $this->last_titles[$array['cat']['my']]); if($find && $i == 0){ return false; } $i++; } $array['link_regex'] = '/' . str_replace(array('/', 'BOMBNEEDEDTEXT', 'BOMBTEXT'), array('\/', '(.*?)', '.*?'), preg_quote($array['link_regex'])) .'/is'; preg_match_all($array['link_regex'], $text, $links); // die(print_r ($links)); $links_array = array(); for($n=0;$n<sizeof($links[1]);$n++) { if($this->my_array_search(strip_tags($titles[0][$n]), $this->last_titles[$array['cat']['my']]) == false){ $links_array[] = $links[1][$n]; } } // die(print_r ($links_array)); if(sizeof($links_array)){ foreach($links_array as $value){ $this->get_news_text($value, $array); } $this->add_news(); $this->news = $this->temp = array(); } } function get_news_text($link, $data_array){ $fp = fsockopen($data_array['url'], 80, $errno, $errstr, 10); if($fp == false){ return; } $host = trim($data_array['url']);$cookie = trim($data_array['cookie']); $url = parse_url($link); $ww_get_path = $url['path']; if (!empty($url['query'])) { $ww_get_path .= '?'.$url['query']; } $headers = "GET {$ww_get_path} HTTP/1.0\r\n"; $headers.= "Host: {$host}\r\n"; $headers.= "Cookie: {$cookie}\r\n"; $headers.= "Connection: Close\r\n\r\n"; fwrite($fp, $headers); $text = ''; while(!feof($fp)){ $text .= fgets($fp, 128); } fclose($fp); $data_array['news_regex'] = '/'.str_replace(array('BOMBNEEDEDTEXT', 'BOMBDIGITAL', 'BOMBTEXT', '/'), array('(.*?)', '[\d]*', '.*?', '\/'), preg_quote($data_array['news_regex'])).'/is'; $data_array['title_full_regex'] = '/' . str_replace(array('/', 'BOMBNEEDEDTEXT', 'BOMBDIGITAL'), array('\/', '.*?', '[\d]*'), preg_quote($data_array['title_full_regex'])) .'/i'; preg_match($data_array['news_regex'], $text, $out); preg_match($data_array['title_full_regex'], $text, $title); //die (print_r ($out)); $title = trim( strip_tags($title[0]) ); //die (print_r ($title)); $ww_temp_prew = $this->get_preview($title); $ww_temp_out = strip_tags($out[0], '<img><br><p><a><b><u><i>'); $ww_temp_prew = preg_replace ("/(<img .*>)(.*)/isU", "<center> \$1 </center><br /> \$2",$ww_temp_prew); $ww_temp_out = preg_replace ("/(<img .*>)(.*)/isU", "<center> \$1 </center><br /> \$2",$ww_temp_out); $this->news[$data_array['cat']['my']][] = array( 'key' => mt_rand(), 'cat' => $data_array['cat']['my'], 'title' => $title, 'preview' => $ww_temp_prew, 'full' => $ww_temp_out ); } function add_news() { $sql = "INSERT INTO '". PREFIX . "_post' ('id', 'autor', 'date', 'short_story', 'full_story', 'title', 'descr', 'keywords', 'category', 'alt_name', 'approve') VALUES (null, '{AUTOR}', '{TIME}', '{PREVIEW}', '{FULL}', '{TITLE}', '{DESCR}', '{KEYS}', '{CAT}', '{ALT}', 1)"; foreach($this->news as $category){ foreach($category as $array){ $result = mysql_query(str_replace( array('{TIME}', '{AUTOR}', '{PREVIEW}', '{FULL}', '{TITLE}', '{DESCR}', '{KEYS}', '{CAT}', '{ALT}'), array(date ("Y-m-d H:i:s", time()), $this->autor_name , mysql_real_escape_string($array['preview']), mysql_reaL_escape_string($array['full'] . "\n\n" . $this->news_footer), mysql_real_escape_string($array['title']), '', '', $array['cat'], $this->make_alt($array['title'])), $sql), $this->link); $this->chk_result($result, false); } } } function make_alt($str){ return mt_rand(); } function my_array_search($needle, $array){ if(gettype($array) != 'array') return false; foreach($array as $data){ if(trim($needle) == trim($data['title'])){ return $data['title']; } } return false; } function get_preview($title){ foreach($this->temp['title'] as $key=>$value){ if(trim($value) == trim($title)){ return $this->temp['preview'][$key]; } } return false; } function chk_result($result, $die = true){ if($result == false && $die == true){ die(mysql_error()); }elseif($result == false && $die == false){ echo mysql_error() . "\n"; } return; } } new grabber; ?>