Eléphant du PHP |
303 Messages
15 nov. 2005, 22:40
Ok,
Code du fichier XSLT (provisoire)
Code : Tout sélectionner
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output encoding="iso-8859-1" indent="yes" method="xml" omit-xml-declaration="yes"
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
<xsl:param name="titre"/>
<xsl:template match="/">
<html>
<head>
<title>
<xsl:value-of select="$titre"/>
</title>
<!--
<style media="all" type="text/css">
@import url(../css/nemostyle.css);
</style>-->
</head>
<body>
<xsl:apply-templates select="//item">
<xsl:sort data-type="number" select="guid" order="descending" />
</xsl:apply-templates>
</body>
</html>
</xsl:template>
<xsl:template match="item">
<div>
<xsl:attribute name="id">
<xsl:text>#</xsl:text>
<xsl:value-of select="guid"/>
</xsl:attribute>
<xsl:attribute name="class">
<xsl:text>article</xsl:text>
</xsl:attribute>
<h2>
<xsl:value-of select="title"/>
</h2>
<p>
<xsl:attribute name="lang">
<xsl:text>fr</xsl:text>
</xsl:attribute>
<xsl:value-of select="description"/>
</p>
</div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Code du fichier PHP
<?php
header("Content-Type: text/xml; charset=\"iso-8859-1\"");
echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n<?xml-stylesheet href=\"rss/rss.xsl\" type=\"text/xsl\"?>\n";
include("config/conf.php");
$act = $_GET['act'];
?>
<rss version="2.0">
<channel>
<title>Pcshows : les news, les articles et le forum</title>
<link><? echo $url; ?></link>
<description>Site de tunning PC, overclocking, watercooling, tests ...</description>
<managingeditor><? echo $email_admin; ?></managingeditor>
<webmaster><? echo $email_admin; ?></webmaster>
<language>fr</language>
<lastbuilddate><?=date('r')?></lastbuilddate>
<?php
if ($act == "forum") {
// Forum
$requete = mysql_query("SELECT * FROM phpbb_forums",$connexion);
$nombre_forum = mysql_num_rows($requete);
$k = 0;
while ($k<$nombre_forum)
{
$lastpost = mysql_result($requete,$k,"forum_last_post_id");
// Vérification id != 0
if ($lastpost != 0) {
// Dernier post
$requete_post = mysql_query("SELECT * FROM phpbb_posts_text WHERE post_id=\"".$lastpost."\"",$connexion);
$tableau = mysql_fetch_array($requete_post, MYSQL_ASSOC);
$idpost = $tableau['post_id'];
$sujet = $tableau['post_subject'];
$texte = $tableau['post_text'];
// Topic
$requete_topic = mysql_query("SELECT * FROM phpbb_topics WHERE topic_first_post_id=\"".$idpost."\"",$connexion);
$tableau2 = mysql_fetch_array($requete_topic, MYSQL_ASSOC);
$idtopic = $tableau2['topic_id'];
// Affichage flux ...
echo('<item>
<title>'.$sujet.'</title>
<link>'.$url.'/forum/viewtopic.php?t='.$idtopic.'</link>
<description>'.$texte.'</description>
</item>');
}
$k++;
}
}
if ($act == "news") {
// Requête
$requete = mysql_query("SELECT * FROM news WHERE valider=\"1\" ORDER BY id DESC LIMIT 0, 10",$connexion) or die ("Requête invalide") ;
$resultat = mysql_num_rows($requete);
$i = 0;
while ($i<$resultat)
{
$id = mysql_result($requete,$i,"id");
$titre = mysql_result($requete,$i,"titre");
?>
<item>
<title><? echo html_entity_decode($titre, ENT_QUOTES); ?></title>
<link><? echo $url; ?>/site/onenews.php?id=<? echo $id; ?></link>
</item>
<?
$i++;
}
}
if ($act == "articles") {
$j = 1;
while ($j<7)
{
$categ = mysql_query("SELECT * FROM article WHERE valider=\"1\" AND categorie=\"".$j."\" ORDER BY id DESC LIMIT 1",$connexion);
// Vérification présence d'un article dans la catégorie
if (mysql_num_rows($categ) != 0) {
$tableau_categ = mysql_fetch_array($categ, MYSQL_ASSOC);
$id = $tableau_categ['id'];
$titre = $tableau_categ['titre'];
?>
<item>
<title><? echo html_entity_decode($titre, ENT_QUOTES); ?></title>
<link><?=$url?>/site/ article.php?id=<?=$id?>&categorie=<?=$j?>&page=1</link>
</item>
<?
}
$j++;
}
}
mysql_close($connexion);
?>
</channel>
</rss>
Voilà
