<? 
include 'inc/inc_func_base.php';
$chan_title = "ValnerinaOnLine.it politica";
$chan_desc = "informazioni e propaganda politica dalla Valnerina.";
$chan_link = "http://www.valnerinaonline.it/";
$image_url = "http://www.valnerinaonline.it/images/vol.jpg";
$condizioni="tag LIKE 'politica'";
include 'inc/inc_db.php';
$tabella="notiziedb";
$algiorno = date('Y/m/d', strtotime('-30 day'));
$query="SELECT * FROM ". $tabella ." WHERE (fine >= '" . $algiorno . "') AND (" . $condizioni . ") ORDER by fine asc LIMIT 0, 25";
$result = mysql_query($query) or die(mysql_error());
if (mysql_num_rows($result) < 1) {
    die("No records".$algiorno);
}
$items = '';
while ($row = mysql_fetch_assoc($result)) {
	$item_idcomune = $row["idcomune"];
	$item_id = $row["id"];
    $item_title = $row["titolo"];
    $item_link = "http://www.valnerinaonline.it/notizia/".$item_idcomune."/".$item_id."/".correggitestourl($item_title).".html";
    $item_desc = $row["sottotitolo"];
    $item_file1 = $row["file1"];
	if (strstr ($item_file1,".") <> "0") {
//		$item_file1 = "http://inc-notizie.weekenditalia.net/public/$item_file1";
//		$ch = curl_init($item_file1);
//		curl_setopt($ch, CURLOPT_NOBODY, true);
//		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//		curl_setopt($ch, CURLOPT_HEADER, true);
//		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
//		$data = curl_exec($ch);
//		curl_close($ch);
//			if (preg_match('/Content-Length: (\d+)/', $data, $matches1)) {
//				// Contains file size in bytes
//				$contentLength = (int)$matches1[1];
//				// Contains file type
//				$ch = curl_init($item_file1);
//				curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//				curl_exec($ch);
//				# get the content type
//				$fileType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
//			} 
		$percorsofile = "http://inc-notizie.weekenditalia.net/public/";
		$filesize1 = filesize($_SERVER['DOCUMENT_ROOT'].'/public/'.$item_file1);
		$finfo = finfo_open(FILEINFO_MIME_TYPE);
		$fileType = finfo_file($finfo, dirname(__FILE__)."/public/".$item_file1); 
		$item_file1code = "<enclosure url=\"$percorsofile$item_file1\" length=\"$filesize1\" type=\"$fileType\" />";
	} else {
		$item_file1code = "";
	}
    $items .= <<<ITEM
        <item>
            <title>$item_title</title>
            <link>$item_link</link>
            <guid isPermaLink="true">$item_link</guid>
<description>$item_desc</description>
$item_file1code
        </item>
ITEM;
}
//<?xml version="1.0" encoding="UTF-8"? >
$content = <<<CONTENT
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
>
        <channel>
                <title>$chan_title</title>
		<atom:link href="http://inc-notizie.valnerinaonline.it/vol_politica.xml" rel="self" type="application/rss+xml"/>
                <link>$chan_link</link>
                <description>$chan_desc</description>
                <image>
                        <title>$chan_title</title>
                        <url>$image_url</url>
                        <link>$chan_link</link>
                </image>
$items
        </channel>
</rss>

CONTENT;
?>
<? 
header("Content-Type: application/rss+xml; charset=UTF-8");
print $content;
 ?>