| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 
 | <?php
 
function &init_news_rss(&$xml_file)
{
        $root = $xml_file->createElement("rss"); // création de l'élément
        $root->setAttribute("version", "2.0"); // on lui ajoute un attribut
        $root = $xml_file->appendChild($root); // on l'insère dans le noeud parent (ici root, qui est "rss")
 
        $channel = $xml_file->createElement("channel");
        $channel = $root->appendChild($channel);
 
        $desc = $xml_file->createElement("description");
        $desc = $channel->appendChild($desc);
        $text_desc = $xml_file->createTextNode("madescription"); // on insère du texte entre les balises <description></description>
        $text_desc = $desc->appendChild($text_desc);
 
        $link = $xml_file->createElement("link");
        $link = $channel->appendChild($link);
        $text_link = $xml_file->createTextNode("http://www.site.com");
        $text_link = $link->appendChild($text_link);
 
        $title = $xml_file->createElement("title");
        $title = $channel->appendChild($title);
        $text_title = $xml_file->createTextNode("site.com");
        $text_title = $title->appendChild($text_title);
 
        return $channel;
}
 
function add_news_node(&$parent, $root, $id_billet, $auteur, $titre, $resume, $date)
{
        $item = $parent->createElement("item");
        $item = $root->appendChild($item);
 
        $title = $parent->createElement("title");
        $title = $item->appendChild($title);
        $text_title = $parent->createTextNode($titre);
        $text_title = $title->appendChild($text_title);
 
        $link = $parent->createElement("link");
        $link = $item->appendChild($link);
        $text_link = $parent->createTextNode("http://www.site.com/controleur/commentaire/index.php?billets=$id_billet");
        $text_link = $link->appendChild($text_link);
 
        $desc = $parent->createElement("description");
        $desc = $item->appendChild($desc);
        $text_desc = $parent->createTextNode($resume);
        $text_desc = $desc->appendChild($text_desc);
 
        $com = $parent->createElement("comments");
        $com = $item->appendChild($com);
        $text_com = $parent->createTextNode("http://www.site.com/controleur/commentaire/index.php?billets=$id_billet");
        $text_com = $com->appendChild($text_com);
 
        $author = $parent->createElement("author");
        $author = $item->appendChild($author);
        $text_author = $parent->createTextNode($auteur);
        $text_author = $author->appendChild($text_author);
 
        $pubdate = $parent->createElement("pubDate");
        $pubdate = $item->appendChild($pubdate);
        $text_date = $parent->createTextNode($date);
        $text_date = $pubdate->appendChild($text_date);
 
        $guid = $parent->createElement("guid");
        $guid = $item->appendChild($guid);
        $text_guid = $parent->createTextNode("http://www.site.com/controleur/commentaire/index.php?billets=$id_billet");
        $text_guid = $guid->appendChild($text_guid);
 
        $src = $parent->createElement("source");
        $src = $item->appendChild($src);
        $text_src = $parent->createTextNode("http://www.site.com");
        $text_src = $src->appendChild($text_src);
}
 
 
function rebuild_rss()
{
        // on se connecte à la BDD
       try 
		{
			$bdd = new PDO('mysql:host=localhost;dbname=mabdd','monidentifiant','mommotdepasse' );
		}
		catch(Exception $e)
		{
			die ('Erreur:'.$e->getMessage());
		}
		$req = $bdd->query('SELECT id_billet, titre, resume,auteur,DATE_FORMAT(date_de_creation,\'%d/%m/%Y à %Hh%imin%ss\') AS date_de_creation_fr FROM tableau ORDER BY date_de_creation DESC LIMIT 0,5');
 
 
        // on crée le fichier XML
        $xml_file = new DOMDocument("1.0");
 
		$channel = init_news_rss($xml_file);
 
 
        // on ajoute chaque news au fichier RSS
       while( $donnees = $req->fetch() )
        {
                add_news_node($xml_file, $channel, utf8__encode($donnees["id_billet"]), utf8__encode($donnees["auteur"]), utf8__encode($donnees["titre"]), 
utf8__encode($donnees["resume"]), utf8__encode($donnees["date_de_creation"]));
        }
 
        // on écrit le fichier
        $xml_file->save("rss.xml");
}
 
 
 
rebuild_rss();
 
 
 
?> | 
Partager