|
12.02.2006, 18:04
11. Упрощаем функцию вывода RSS в блоке и автоматического добавления запрограммированных новостей, находим:
PHP код:
function headlines($bid, $cenbox=0) { global $prefix, $db; $bid = intval($bid); $result = $db->sql_query("SELECT title, content, url, refresh, time FROM ".$prefix."_blocks WHERE bid='$bid'"); $row = $db->sql_fetchrow($result); $title = filter($row['title'], nohtml); $content = filter($row['content']); $url = filter($row['url'], nohtml); $refresh = intval($row['refresh']); $otime = $row['time']; $past = time()-$refresh; if ($otime < $past) { $btime = time(); $rdf = parse_url($url); $fp = fsockopen($rdf['host'], 80, $errno, $errstr, 15); if (!$fp) { $content = ""; $db->sql_query("UPDATE ".$prefix."_blocks SET content='$content', time='$btime' WHERE bid='$bid'"); $cont = 0; if ($cenbox == 0) { themesidebox($title, $content); } else { themecenterbox($title, $content); } return; } if ($fp) { if ($rdf['query'] != '') $rdf['query'] = "?" . $rdf['query']; fputs($fp, "GET " . $rdf['path'] . $rdf['query'] . " HTTP/1.0\r\n"); fputs($fp, "HOST: " . $rdf['host'] . "\r\n\r\n"); $string = ""; while(!feof($fp)) { $pagetext = fgets($fp,300); $string .= chop($pagetext); } fputs($fp,"Connection: close\r\n\r\n"); fclose($fp); $items = explode("</item>",$string); $content = "<font class=\"content\">"; for ($i=0;$i<10;$i++) { $link = ereg_replace(".*<link>","",$items[$i]); $link = ereg_replace("</link>.*","",$link); $title2 = ereg_replace(".*<title>","",$items[$i]); $title2 = ereg_replace("</title>.*","",$title2); $title2 = stripslashes($title2); if ($items[$i] == "" AND $cont != 1) { $content = ""; $db->sql_query("UPDATE ".$prefix."_blocks SET content='$content', time='$btime' WHERE bid='$bid'"); $cont = 0; if ($cenbox == 0) { themesidebox($title, $content); } else { themecenterbox($title, $content); } return; } else { if (strcmp($link,$title2) AND $items[$i] != "") { $cont = 1; $content .= "<strong><big>·</big></strong><a href=\"$link\" target=\"new\">$title2</a><br>\n"; } } } } $db->sql_query("UPDATE ".$prefix."_blocks SET content='$content', time='$btime' WHERE bid='$bid'"); } $siteurl = ereg_replace("http://","",$url); $siteurl = explode("/",$siteurl); if (($cont == 1) OR ($content != "")) { $content .= "<br><a href=\"http://$siteurl[0]\" target=\"blank\"><b>"._HREADMORE."</b></a></font>"; } elseif (($cont == 0) OR ($content == "")) { $content = "<font class=\"content\">"._RSSPROBLEM."</font>"; } if ($cenbox == 0) { themesidebox($title, $content); } else { themecenterbox($title, $content); } } function automated_news() { global $prefix, $multilingual, $currentlang, $db; if ($multilingual == 1) { $querylang = "WHERE (alanguage='$currentlang' OR alanguage='')"; /* the OR is needed to display stories who are posted to ALL languages */ } else { $querylang = ""; } $today = getdate(); $day = $today[mday]; if ($day < 10) { $day = "0$day"; } $month = $today[mon]; if ($month < 10) { $month = "0$month"; } $year = $today[year]; $hour = $today[hours]; $min = $today[minutes]; $sec = "00"; $result = $db->sql_query("SELECT anid, time FROM ".$prefix."_autonews $querylang"); while ($row = $db->sql_fetchrow($result)) { $anid = $row['anid']; $time = $row['time']; ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $time, $date); if (($date[1] <= $year) AND ($date[2] <= $month) AND ($date[3] <= $day)) { if (($date[4] < $hour) AND ($date[5] >= $min) OR ($date[4] <= $hour) AND ($date[5] <= $min)) { $result2 = $db->sql_query("SELECT * FROM ".$prefix."_autonews WHERE anid='$anid'"); while ($row2 = $db->sql_fetchrow($result2)) { $num = $db->sql_numrows($db->sql_query("SELECT sid FROM ".$prefix."_stories WHERE title='$row2[title]'")); if ($num == 0) { $title = $row2['title']; $hometext = filter($row2['hometext']); $bodytext = filter($row2['bodytext']); $notes = filter($row2['notes']); $catid2 = intval($row2['catid']); $aid2 = filter($row2['aid'], nohtml); $time2 = $row2['time']; $topic2 = intval($row2['topic']); $informant2 = filter($row2['informant'], nohtml); $ihome2 = intval($row2['ihome']); $alanguage2 = $row2['alanguage']; $acomm2 = intval($row2['acomm']); $associated2 = $row2['associated']; // Prepare and filter variables to be saved $hometext = filter($hometext, "", 1); $bodytext = filter($bodytext, "", 1); $notes = filter($notes, "", 1); $aid2 = filter($aid2, nohtml, 1); $informant2 = filter($informant2, nohtml, 1); $db->sql_query("DELETE FROM ".$prefix."_autonews WHERE anid='$anid'"); $db->sql_query("INSERT INTO ".$prefix."_stories VALUES (NULL, '$catid2', '$aid2', '$title', '$time2', '$hometext', '$bodytext', '0', '0', '$topic2', '$informant2', '$notes', '$ihome2', '$alanguage2', '$acomm2', '0', '0', '0', '0', '0', '$associated2')"); } } } } } }
Заменяем на:
PHP код:
//Copyright Soniks http://mynuke.ru function headlines($blockinfo, $cenbox=0) { global $prefix, $db; $content = $blockinfo['content']; $otime = $blockinfo['time']; $past = time()-$blockinfo['refresh']; if ($otime < $past) { $btime = time(); $rdf = parse_url($blockinfo['url']); $fp = fsockopen($rdf['host'], 80, $errno, $errstr, 15); if (!$fp) { $content = ""; $db->sql_query("UPDATE ".$prefix."_blocks SET content='$content', time='$btime' WHERE bid='".$blockinfo['bid']."'"); $cont = 0; if ($cenbox == 0) { themesidebox($blockinfo['title'], $content); } else { themecenterbox($blockinfo['title'], $content); } return; } if ($fp) { if ($rdf['query'] != '') $rdf['query'] = "?" . $rdf['query']; fputs($fp, "GET " . $rdf['path'] . $rdf['query'] . " HTTP/1.0\r\n"); fputs($fp, "HOST: " . $rdf['host'] . "\r\n\r\n"); $string = ""; while(!feof($fp)) { $pagetext = fgets($fp,300); $string .= chop($pagetext); } fputs($fp,"Connection: close\r\n\r\n"); fclose($fp); $items = explode("</item>",$string); $content = "<font class=\"content\">"; for ($i=0;$i<10;$i++) { $link = ereg_replace(".*<link>","",$items[$i]); $link = ereg_replace("</link>.*","",$link); $title2 = ereg_replace(".*<title>","",$items[$i]); $title2 = ereg_replace("</title>.*","",$title2); $title2 = stripslashes($title2); if ($items[$i] == "" AND $cont != 1) { $content = ""; $db->sql_query("UPDATE ".$prefix."_blocks SET content='$content', time='$btime' WHERE bid='".$blockinfo['bid']."'"); $cont = 0; if ($cenbox == 0) { themesidebox($blockinfo['title'], $content); } else { themecenterbox($blockinfo['title'], $content); } return; } else { if (strcmp($link,$title2) AND $items[$i] != "") { $cont = 1; $content .= "<strong><big>·</big></strong><a href=\"$link\" target=\"new\">$title2</a><br>\n"; } } } } $db->sql_query("UPDATE ".$prefix."_blocks SET content='$content', time='$btime' WHERE bid='".$blockinfo['bid']."'"); } $siteurl = ereg_replace("http://","",$blockinfo['url']); $siteurl = explode("/",$siteurl); if (($cont == 1) OR ($content != "")) { $content .= "<br><a href=\"http://$siteurl[0]\" target=\"blank\"><b>"._HREADMORE."</b></a></font>"; } elseif (($cont == 0) OR ($content == "")) { $content = "<font class=\"content\">"._RSSPROBLEM."</font>"; } if ($cenbox == 0) { themesidebox($blockinfo['title'], $content); } else { themecenterbox($blockinfo['title'], $content); } } //Copyright Soniks http://mynuke.ru function automated_news() { global $prefix, $multilingual, $currentlang, $db; if ($multilingual == 1) { $querylang = "WHERE (alanguage='$currentlang' OR alanguage='')"; /* the OR is needed to display stories who are posted to ALL languages */ } else { $querylang = ""; } $today = getdate(); $day = $today[mday]; if ($day < 10) { $day = "0$day"; } $month = $today[mon]; if ($month < 10) { $month = "0$month"; } $year = $today[year]; $hour = $today[hours]; $min = $today[minutes]; $sec = "00"; $result = $db->sql_query("SELECT * FROM ".$prefix."_autonews $querylang"); while ($row = $db->sql_fetchrow($result)) { $anid = $row['anid']; $time = $row['time']; ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $time, $date); if (($date[1] <= $year) AND ($date[2] <= $month) AND ($date[3] <= $day)) { if (($date[4] < $hour) AND ($date[5] >= $min) OR ($date[4] <= $hour) AND ($date[5] <= $min)) { $num = $db->sql_numrows($db->sql_query("SELECT sid FROM ".$prefix."_stories WHERE title='".$row['title']."' AND hometext='".$row['hometext']."'")); if ($num == 0) { $title = $row['title']; $hometext = filter($row['hometext']); $bodytext = filter($row['bodytext']); $notes = filter($row['notes']); $catid2 = intval($row['catid']); $aid2 = filter($row['aid'], nohtml); $time2 = $row['time']; $topic2 = intval($row['topic']); $informant2 = filter($row['informant'], nohtml); $ihome2 = intval($row['ihome']); $alanguage2 = $row['alanguage']; $acomm2 = intval($row['acomm']); $associated2 = $row['associated']; // Prepare and filter variables to be saved $hometext = filter($hometext, "", 1); $bodytext = filter($bodytext, "", 1); $notes = filter($notes, "", 1); $aid2 = filter($aid2, nohtml, 1); $informant2 = filter($informant2, nohtml, 1); $db->sql_query("DELETE FROM ".$prefix."_autonews WHERE anid='$anid'"); $db->sql_query("INSERT INTO ".$prefix."_stories VALUES (NULL, '$catid2', '$aid2', '$title', '$time2', '$hometext', '$bodytext', '0', '0', '$topic2', '$informant2', '$notes', '$ihome2', '$alanguage2', '$acomm2', '0', '0', '0', '0', '0', '$associated2')"); } } } } }
|
|