|
08.12.2005, 20:27
Вот, как обещал, блок для доступа к rss-каналу, закрытому паролем:
Код:
<?php
/************************************************** **********************/
/* PHP-NUKE: Web Portal System */
/* =========================== */
/* */
/* Copyright (c) 2005 by Francisco Burzi */
/* http://phpnuke.org */
/* */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License. */
/************************************************** **********************/
/* Block to fit perfectly in the center of the site, remember that not all
blocks looks good on Center, just try and see yourself what fits your needs */
if (eregi("block-Consultant_rss-News.php", $_SERVER['PHP_SELF'])) {
Header("Location: index.php");
die();
}
$dir = "http://login:password@www.site.ru/rss/";
$fp = fopen($dir, "r");
if (!$fp) {
$content = "";
$cont = 0;
fclose($fp);
return;
}
if ($fp) {
$string = "";
while(!feof($fp)) {
$pagetext = fgets($fp,300);
$string .= $pagetext;
}
fclose($fp);
$content = explode("\n",$string);
ksort($content);
$lencontent = count($content);
$pos = strpos($content[$lencontent-5],"xml");
$file_name = strip_tags(trim(substr($content[$lencontent-5],43,$pos-11)));
$rssfile = $dir.$file_name;
}
$fp = fopen($rssfile, "r");
if (!$fp) {
$content = "";
$cont = 0;
fclose($fp);
return;
}
if ($fp) {
$string = "";
while(!feof($fp)) {
$pagetext = fgets($fp,300);
$string .= chop($pagetext);
}
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);
$cat = ereg_replace(".*<category>","",$items[$i]);
$cat = ereg_replace("</category>.*","",$cat);
$title2 = ereg_replace(".*<title>","",$items[$i]);
$title2 = ereg_replace("</title>.*","",$title2);
$title2 = stripslashes($title2);
if (strcmp($link,$title2) AND $items[$i] != "") {
$content .= "<div align=\"justify\"><img src=\"../images/pg.gif\" alt=\"\" width=\"11\" height=\"14\" border=\"0\" align=\"middle\" hspace=\"10\"><strong>".$cat.": </strong><a href=\"$link\" target=\"new\">".$title2."</a></div><hr width=\"80%\" size=\"1\">\n";
}
}
}
?>
Учтите, что строка
$file_name = strip_tags(trim(substr($content[$lencontent-5],43,$pos-11)));
индивидуальна для конкретного сайта Консультант+, и для другого сайта её, возможно, придётся изменить.
|
|