Бывалый

Профиль
Группа: Участник
Сообщений: 227
Регистрация: 11.12.2006
Репутация: -6 Всего: нет
|
Скрипт работал исправно очень долго время пока я не перехал на другой сервер. После залития скриптов на сервер у меня стала выскакивать ошибка: HTTP 500 Внутреняя ошибка сервера, из за чего она выскакиевает ? Код исправно работал и работает на старом сервере и на локал хосте! | Код | <?
class rss_parsers { public $offset; public $do_update; public $num_to_show; public $rss_url; public $do_update; public $tags = array(); public $content; public $rss = array(); public $feed_title; public $feed_link; public $feed_description; public $quotes; public $my_html; public $data_directory; function __construct($url, $numtoshow, $html = "", $update = TRUE, $offset = 1) { $this->rss_url = $url; $this->num_to_show = $numtoshow; $this->do_update = $update; $this->my_html = preg_replace("/(#{.*?):(.*?})/", "\\1__\\2", $html); $this->offset = --$offset;
$this->content = $this->fetch_feed(); $this->parse_feed($url); $this->interpret_links($url); $this->show(); } function fetch_feed() { $url_parts = parse_url($this->rss_url);
$filename = $url_parts['host']; $this->data_directory = getcwd()."/files/"; if(file_exists($this->data_directory . "/$filename")) { $last = filemtime($this->data_directory . "/$filename"); $create = 0; if(time() - $last > $this->update_interval * 60 || $this->update_interval == 0) { $update = 1; } else { $update = 0; } } else { $create = 1; $update = 1; }
if($create == 1 || ($this->do_update == TRUE && $update == 1)) { $fp = @fsockopen($url_parts['host'], 80, $errno, $errstr, 5); if (!$fp) { echo "Couldn't open rss feed {$this->feed_url} in {$_SERVER['PHP_SELF']}<br />\n"; return; }
fputs($fp, "GET {$this->rss_url} HTTP/1.0\r\n" ."Host: " . $url_parts['host'] . "\r\n" ."User-Agent: RSS Reader Hard&Soft Tecnologies\r\n" ."Connection: Close\r\n\r\n");
while(!feof($fp)) { $rss_data .= @fread($fp, 1024); }
list(, $rss_data) = explode("\r\n\r\n", $rss_data, 2);
$output = @fopen($this->data_directory . "/$filename", "w+b"); if(!$output) { return $rss_data; } else { flock($output, LOCK_EX); fputs($output, $rss_data); flock($output, LOCK_UN); fclose($output); } }
return file_get_contents($this->data_directory . "/$filename"); }
function parse_feed($url) { preg_match("/<title>(.*?)<\/title>/", $this->content, $title); $this->feed_title = @$title[1];
preg_match("/<link>(.*?)<\/link>/", $this->content, $link); $this->feed_link = @$link[1];
preg_match("/<description>(.*?)<\/description>/", $this->content, $description); $this->feed_description = @$description[1];
preg_match_all("/<item[^>]*>(.*?)<\/item>/s", $this->content, $items); if (sizeof($items[0]) == 0) { echo "No item elements found in rss feed. URL:".$url."<br />\n"; }
for($i = 0; $i < sizeof($items[0]); ++$i) { preg_match_all("/(?:<([\w:]*)[^>]*>\s*(?:<!\[CDATA\[)?(.*?)(?:]]>)?\s*<\/\\1>)+?/si", preg_replace("/<item[^>]*>/", "", $items[0][$i]), $elements); for($j = 0; $j < sizeof($elements[0]); ++$j) { $elements[1][$j] = str_replace(":", "__", $elements[1][$j]); $this->rss[$i][$elements[1][$j]] = trim($this->unhtmlentities($elements[2][$j])); } } } function show() { if($this->my_html == "") { $this->show_user_html(); } else { $this->show_user_html(); } }
function show_html() { $show = (sizeof($this->rss) > $this->num_to_show ? $this->num_to_show : sizeof($this->rss)); for($i = $this->offset; $i < $this->offset + $show; ++$i) { echo "- <a href=\"{$this->rss[$i]['link']}\" target=\"_new\">{$this->rss[$i]['title']}</a><br />\n"; } } function interpret_links($host) { $sql = "SELECT * FROM comments WHERE reed = 'yes'"; $bind = db_query($sql); $server = parse_url($host); While($lfx_rows = mysql_fetch_object($bind)) { $get_url = strip_tags($lfx_rows->comm_text); $get_url = str_replace("Скачать: ","",$get_url); $server1 = parse_url($get_url); $get_url = str_replace("www.".$server1['host'],"",strip_tags($get_url)); $get_url = str_replace("http://".$server1['host'],"",strip_tags($get_url)); $get_url = str_replace("www.","",strip_tags($get_url)); $get_url = str_replace("http://","",strip_tags($get_url)); $fp = @fsockopen(str_replace("www.","",$server1["host"]), 80, $errno, $errstr, 600); if (!$fp) { echo "Couldn't open rss feed {$this->feed_url} in {$_SERVER['PHP_SELF']}<br />\n"; return; } $z = "GET ".$get_url." HTTP/1.0\r\n" ."Host: " . str_replace("www.","",$server1["host"]) . "\r\n" ."User-Agent: RSS Reader\r\n" ."Connection: Close\r\n\r\n"; fputs($fp, $z); while(!feof($fp)) { $rss_data .= @fread($fp, 1024); } preg_match_all("/<!--QuoteEBegin-->(.*?)<!--QuoteEnd-->/",$rss_data,$qoutes); fclose($fp); for($i=0;$i<sizeof($qoutes[0]);$i++) { $datass .= str_replace("Внимание! У вас нет прав, для просмотра скрытого текста.","",str_replace("'",'"',$qoutes[0][$i])); $datass .= "<BR>"; } if (strlen($datass) > 3) $textd = "[quote] ".$datass." [/quote]"; $sql = "UPDATE comments SET reed = 'no', comm_text = '".$lfx_rows->comm_text."<hr> $textd' WHERE id = '".$lfx_rows->id."'"; db_query($sql); unset($rss_data); unset($datass); unset($sql); unset($qoutes); } } function show_user_html() { global $content; $show = (sizeof($this->rss) > $this->num_to_show + $this->offset ? $this->num_to_show : sizeof($this->rss)); $show = ($this->offset + $this->num_to_show > sizeof($this->rss) ? sizeof($this->rss) - $this->offset : $this->num_to_show); for($i = $this->offset; $i < $this->offset + $show; ++$i) { $this->rss[$i]['category'] = trim($this->rss[$i]['category']); $this->rss[$i]['description'] = str_replace("'",'',$this->rss[$i]['description']); $this->rss[$i]['description'] = str_replace('"','',$this->rss[$i]['description']); $this->rss[$i]['title'] = str_replace("'",'',$this->rss[$i]['title']); $this->rss[$i]['title'] = str_replace('"','',$this->rss[$i]['title']); if ($this->rss[$i]['category'] == "Фото&Обои" || $this->rss[$i]['category'] == "Обои" || $this->rss[$i]['category'] == "Обоины") $this->rss[$i]['category'] = "Фото & Обои"; if ($this->rss[$i]['category'] == "+18" || $this->rss[$i]['category'] == "---" || $this->rss[$i]['category'] == "XXX(+18)" || $this->rss[$i]['category'] == "Эротика" || $this->rss[$i]['category'] == "XXX | Эротика" || $this->rss[$i]['category'] == "ХХХ" || $this->rss[$i]['category'] == "XXX" || $this->rss[$i]['category'] == "ХХХ, Эротика" || $this->rss[$i]['category'] == "XXX(+18), Эротика" || $this->rss[$i]['category'] == "XXX(+18), Эротика , Видео") $this->rss[$i]['category'] = "Взрослым 18+"; if ($this->rss[$i]['category'] == "Зарубежные исполнители") $this->rss[$i]['category'] = "Зарубежные сборники"; if ($this->rss[$i]['category'] == "software" || $this->rss[$i]['category'] == "Авто / Мото" || $this->rss[$i]['category'] == "Программы") $this->rss[$i]['category'] = "Софт"; if ($this->rss[$i]['category'] == "Мультики" || $this->rss[$i]['category'] == "Сериалы"|| $this->rss[$i]['category'] == "") $this->rss[$i]['category'] = "Фильмы"; if ($this->rss[$i]['category'] == "Разное / Другое" || $this->rss[$i]['category'] == "Интересное в сети" ) $this->rss[$i]['category'] = "Разное"; if ($this->rss[$i]['category'] == "Музыка | Клипы" || $this->rss[$i]['category'] == "Видео" || $this->rss[$i]['category'] == "Зарубежные сборники, Видеоклипы" ) $this->rss[$i]['category'] = "Видео Клипы"; if ($this->rss[$i]['category'] == "Flash игры" ) $this->rss[$i]['category'] = "Игры"; if ($this->rss[$i]['category'] == "Аниме") $this->rss[$i]['category'] = "Аниме / Хентай"; if ($this->rss[$i]['category'] == "Книги | Журналы" || $this->rss[$i]['category'] == "Книги" || $this->rss[$i]['category'] == "Журналы") $this->rss[$i]['category'] = "Журналы и книги"; if ($this->rss[$i]['category'] == "Мобилка" || $this->rss[$i]['category'] == "Всё для Мобильников" || $this->rss[$i]['category'] == "Все для мобильников" || $this->rss[$i]['category'] == "Игры, mobile" ) $this->rss[$i]['category'] = "mobile"; if ($this->rss[$i]['category'] == "JAZZ" || $this->rss[$i]['category'] == "Зарубежные сборники" || $this->rss[$i]['category'] == "Русские Исполнители" || $this->rss[$i]['category'] == "Русские сборники") $this->rss[$i]['category'] = "Музыка"; if ($this->rss[$i]['category'] == "Новости") continue; $sql = "SELECT * FROM cats WHERE name = '".trim($this->rss[$i]['category'])."'"; $bind = db_query($sql); if (!mysql_num_rows($bind)) { $mod = "edit_cats.php"; include("mods/edit_cats.php"); $cats = new edit_cats; $cats->add_cat($this->rss[$i]['category']); } $sql = "SELECT * FROM news WHERE name = '".trim($this->rss[$i]['title'])."'"; $bind = db_query($sql); if (!mysql_num_rows($bind)){ $id = uniqid("news_"); $data = data(); $sql = "INSERT INTO `news` ( `name` , `id` , `arr` , `news_text` , `avtor` , `data` , `public`, `news_cat` ) VALUES ('".trim($this->rss[$i]['title'])."', '$id', 'no', '".str_replace("'",'"',$this->rss[$i]['description'])."', 'Admin', '$data', 'no', '".$this->rss[$i]['category']."');"; db_query($sql); $data = data(); $ids = uniqid("comm_"); $sql = "INSERT INTO `comments` ( `comm_text` , `id` , `idd` , `page` , `avtor` , `data` , `reed` ) VALUES ('<a href=\"".$this->rss[$i]['link']."\" target=_blank>Скачать: ".$this->rss[$i]['link']."</a>', '".$ids."', '".$id."', 'news', 'Admin', '".$data ."', 'yes');"; db_query($sql); add_num("user_4689f7136232d"); $content .= "<b>Получена новая новость</b>: ".$this->rss[$i]['title']."<hr>"; } else $content .= "Новость уже существует ".$this->rss[$i]['title']."<hr>"; } }
function unhtmlentities($string) { $string = preg_replace('~&#x([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $string); $string = preg_replace('~&#([0-9]+);~e', 'chr(\\1)', $string); $trans_tbl = get_html_translation_table(HTML_ENTITIES); $trans_tbl = array_flip($trans_tbl); return strtr($string, $trans_tbl); }
} function add_url($rss) { $sql = "SELECT * FROM rss WHERE url = '".mysql_escape_string($rss)."'"; $bind = db_query($sql); if (!mysql_num_rows($bind)){ $sql = "INSERT INTO `rss` (`id` ,`url`) VALUES ('".uniqid("rss_")."', '".$rss."');"; db_query($sql); } } if (isset($_GET["url_rss"])) add_url($_GET["url_rss"]); $module_news = "disabled"; $sql = "SELECT * FROM rss"; $bind = db_query($sql); $content .= "<a href=\"?mode=news&id=not_public\">Посматреть новости</a><br>"; While($lfx_rows = mysql_fetch_object($bind)){$rss = new rss_parsers($lfx_rows->url, 90002000, "", 1, TRUE);unset($rss);} $content .= "<a href=\"?mode=news&id=not_public\">Посматреть новости</a>"; ?>
|
--------------------
<Вырезана, как не соответствующая правилам форума >
|