n/oldblog
Archived
1
0
Fork 0
This repository has been archived on 2024-02-13. You can view files and clone it, but cannot push or open issues or pull requests.
oldblog/tmp/genbackend.php
2023-04-30 21:50:11 +02:00

204 lines
7.1 KiB
PHP

<?php
/*
Name : backend.php
Author : NicoSoft
Création: 18/09/01
MAJ : 04/08/05
*/
require_once "include/standard.inc.php";
require_once "include/news.inc.php";
//require_once "include/lang.inc.php";
extract(parse_ini_file("/web/website/config/pip.ini"));
clearstatcache();
// paramètres
$NbMax = 10;
if (isset($_GET["language"]))
$language = $_GET["language"];
if (!isset($language))
$language = "fr";
$FileNews="news/news.$language";
$totalnews = gettotal("$FileNews","file");
echo "<br />nb total de news:$totalnews";
if (isset($_GET["typebackend"]))
$typebackend = $_GET["typebackend"];
if (!isset($typebackend))
$typebackend = "rss";
switch($typebackend)
{
case "txt":
$outputfile = "../backends/txt/tourmentine.$language.txt";
if ($NbMax > $totalnews)
$NbMax = $totalnews;
if ($totalnews >= 1)
{
$backend = fopen("$outputfile","w");
for($n = 0 ; $n < $NbMax ; $n++)
{
$newsnb = $totalnews-$n;
$MyNews = getnews("$FileNews",$newsnb,"file");
fwrite ($backend," %%\n");
fwrite ($backend,$MyNews["date"]."\n");
fwrite ($backend,$MyNews["titre"]."\n");
#fwrite ($backend,"$urlsite/index.php?modulepage=affnews&File=$FileNews&start=".$newsnb."\n");
fwrite ($backend,"$urlsite/billet.".$newsnb.".".$language.".html\n");
}
fclose($backend);
echo "<br />$outputfile généré.<br />";
}
else echo "fichier non créé : nombre de news insuffisant ($totalnews)<br />";
break;
case "atom":
// entete atom
$entete = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>
<?xml-stylesheet href=\"http://tourmentine.com/css/atom.css\" type=\"text/css\"?>
<?xml-stylesheet type=\"text/xsl\" href=\"/css/atom.xsl\"?>
<feed version=\"0.3\"
xmlns=\"http://purl.org/atom/ns#\"
xml:lang=\"$language\">
<title>$titlesite</title>
<tagline>$descriptionsite</tagline>
<link rel=\"alternate\" type=\"text/html\" href=\"$urlsite\"/>
<generator url=\"http://tourmentine.com/\" version=\"beta\">WebLoom</generator>
<author>
<name>n</name>
<url>http://tourmentine.com/</url>
</author>
<modified>".date("c")."</modified>\n\n";
$outputfile = "../backends/atom/tourmentine.$language.xml";
if ($NbMax > $totalnews)
$NbMax = $totalnews;
if ($totalnews >= 1)
{
$backend = fopen("$outputfile","w");
fwrite($backend,$entete);
for($n = 0 ; $n < $NbMax ; $n++)
{
$newsnb = $totalnews-$n;
$MyNews = getnews("$FileNews",$newsnb,"file");
fwrite ($backend," <entry>\n");
fwrite ($backend," <title>".$MyNews["titre"]."</title>\n");
if (strlen(strip_tags($MyNews["message"])) > 100)
$summary = substr(strip_tags($MyNews["message"]), 0, 100)."...";
else
$summary = strip_tags($MyNews["message"]);
fwrite ($backend," <summary>".$summary."</summary>\n");
fwrite ($backend," <content type=\"text/html\" mode=\"escaped\">\n<![CDATA[\n".$MyNews["message"]."\n]]>\n</content>\n");
fwrite ($backend," <link rel=\"alternate\" type=\"text/html\" href=\"$urlsite/billet.".$newsnb.".".$language.".html\" />\n");
fwrite ($backend," <issued>".date("c",$MyNews["timestamp"])."</issued>\n");
fwrite ($backend," <modified>".date("c",$MyNews["timestamp"])."</modified>\n");
fwrite ($backend," <id>$urlsite/billet.".$newsnb.".html</id>\n");
fwrite ($backend," </entry>\n\n");
}
fwrite ($backend,"</feed>");
fclose($backend);
echo "<br />$outputfile généré.<br />";
}
else echo "fichier non créé : nombre de news insuffisant ($totalnews)<br />";
break;
case "opml":
$entete = "<?xml version=\"1.0\" encoding=\"utf-8\"?>
<!-- generator=\"WebLoom Beta\" -->
<opml xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">
<head>
<title>$titlesite</title>
</head>
<body>\n\n";
$outputfile = "../backends/opml/tourmentine.$language.opml";
if ($NbMax > $totalnews)
$NbMax = $totalnews;
if ($totalnews >= 1)
{
$backend = fopen("$outputfile","w");
fwrite($backend,$entete);
for($n = 0 ; $n < $NbMax ; $n++)
{
$newsnb = $totalnews-$n;
$MyNews = getnews("$FileNews",$newsnb,"file");
fwrite ($backend," <outline type=\"rss\" title=\"".$MyNews["titre"]."\" text=\"".$MyNews["titre"]."\" url=\"$urlsite/billet.".$newsnb.".html\" />\n");
}
fwrite ($backend," </body>\n</opml>");
fclose($backend);
echo "<br />$outputfile généré.<br />";
}
else echo "fichier non créé : nombre de news insuffisant ($totalnews)<br />";
break;
default:
// entete rss
$entete = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>
<?xml-stylesheet href=\"http://tourmentine.com/css/rss.css\" type=\"text/css\"?>
<?xml-stylesheet title=\"gris\" type=\"text/xsl\" href=\"/css/rss.xsl\"?>
<rss version=\"2.0\">
<channel>
<title>$titlesite</title>
<link>$linksite</link>
<description>$descriptionsite</description>
<language>$language</language>
<pubDate>".date("r")."</pubDate>
<lastBuildDate>".date("r")."</lastBuildDate>
<managingEditor>$MailAdr</managingEditor>
<webMaster>$MailAdr</webMaster>
<generator>WebLoom beta</generator>\n\n";
$outputfile = "../backends/xml/tourmentine.$language.rss";
if ($NbMax > $totalnews)
$NbMax = $totalnews;
if ($totalnews >= 1)
{
$backend = fopen("$outputfile","w");
fwrite($backend,$entete);
for($n = 0 ; $n < $NbMax ; $n++)
{
$newsnb = $totalnews-$n;
$MyNews = getnews("$FileNews",$newsnb,"file");
fwrite ($backend," <item>\n");
fwrite ($backend," <title>".$MyNews["titre"]."</title>\n");
fwrite ($backend," <description><![CDATA[\n".$MyNews["message"]."\n]]></description>\n");
fwrite ($backend," <link>$urlsite/billet.".$newsnb.".".$language.".html</link>\n");
fwrite ($backend," <pubDate>".date("r",$MyNews["timestamp"])."</pubDate>\n");
fwrite ($backend," </item>\n\n");
}
fwrite ($backend," </channel>\n\n</rss>");
fclose($backend);
echo "<br /><br />$outputfile généré.<br />";
}
else echo "fichier non créé : nombre de news insuffisant ($totalnews)<br />";
}
?>