| Tuesday 20 March 2012 - 10:30
blocco lettura file RSS: Mi interesserebbe inserire in un sito realizzato con flatnux un blocco per aggregare files rss provenienti da un altro sito.
in rete ho trovato diversi script, ma non vorrei creare problemi di sicurezza al sito.
è possibile trovare uno script sicuro in php che non crei problemi?
grazie Franco
Ho provato a utilizzare questo:
<script language="JavaScript" src="http://feed2js.org//feed2js.php?src=http%3A%2F%2Fwww.flatnux.altervista.org%2Fmisc%2Frss%2Fnews%2Fit%2Fbackend.xml&chan=y&num=5&desc=1&utf=y" charset="UTF-8" type="text/javascript"></script>
<noscript> <a href="http://feed2js.org//feed2js.php?src=http%3A%2F%2Fwww.flatnux.altervista.org%2Fmisc%2Frss%2Fnews%2Fit%2Fbackend.xml&chan=y&num=5&desc=1&utf=y&html=y">View RSS feed</a> </noscript>
-------------------- Funziona perfettamente; un solo dubbio: può creare problemi di sicurezza???
|
| Thursday 29 March 2012 - 12:42
Re: blocco lettura file RSS: In php ce ne sono molti.
uno è questo: http://magpierss.sourceforge.net/
Alessandro
Oppure c'è la vecchia funzione presa da Flatnux 2011:
function parse_RSS($url) { $url = getparam($url, PAR_NULL, SAN_FLAT); if ( $url != "" ) { if ( !preg_match("/http:\\/\\//i", $url) ) { $url = "http://$url"; } $rdf = parse_url($url); $errno = $errstr = null; $fp = fsockopen($rdf['host'], 80, $errno, $errstr, 15); if ( !$fp ) { print(_NORSS); return ""; } if ( $fp ) { $remotecontents = ""; @ fputs($fp, "GET " . $rdf['path'] . "?" . $rdf['query'] . " HTTP/1.0\r\n"); @ fputs($fp, "HOST: " . $rdf['host'] . "\r\n\r\n"); while ( !feof($fp) ) { $pagetext = fgets($fp, 228); $remotecontents .= chop($pagetext); } fputs($fp, "Connection: close\r\n\r\n"); fclose($fp); //-----------------ricava e converte l' encoding-----------> $encoding = 'UTF-8'; $arr_got = array(); if ( preg_match('/encoding="([^"]+)"/iUs', $remotecontents, $arr_got) ) $encoding = strtoupper($arr_got[1]); $string = $remotecontents; $remotecontents = htmlentities($remotecontents, ENT_QUOTES, $encoding); $remotecontents = html_entity_decode($remotecontents, ENT_QUOTES, _CHARSET); if ( $remotecontents != "" ) $string = $remotecontents; echo "<br />"; //-----------------ricava e converte l' encoding-----------< $string = xmldb_removexmlcomments($string); $description = ""; $tmp = explode("</title>", $string); $title = preg_replace("/.*<title>/si", "", $tmp[0]); $tmp = explode("</description>", preg_replace("/<item>.*<\/item>/si", "", $string)); if ( isset($tmp[1]) ) $description = preg_replace("/.*<description>/si", "", $tmp[0]); $items = explode("</item>", $string); $content = "" . "<strong>$title</strong><br /><em>$description</em><hr /><div>"; for ( $i = 0; $i < sizeof($items) - 1; $i++ ) { $link = preg_replace("/.*<link>/si", "", $items[$i]); $link = preg_replace("/<\\/link>.*/si", "", $link); $title2 = preg_replace("/.*<title>/si", "", $items[$i]); $title2 = preg_replace("/<\\/title>.*/si", "", $title2); // some feeds are exposed with CDATA format $title2 = str_replace("<![CDATA[", "", $title2); $title2 = str_replace("]]>", "", trim($title2)); if ( strcmp($link, $title2) and $items[$i] != "" ) { $content .= "<b><big>·</big></b> <a style=\"font-size: 12px;\" href=\"$link\" target=\"new\">" . $title2 . "</a><br />\n"; } } $content .= "</div>"; } } return $content; }
|