Le 18 / 09 / 2006 – Lundi (23 h 09 min)

Le 18 / 09 / 2006 – Lundi (23 h 09 min)

Bon alors il y a quelque temps je cherchait le moyen d’intégrer les derniers articles de Skyblog à mon site, donc je lancais google.. Et je trouvai un logiciel en perl qui crééait un fil rss. Seul problème : il ne se mettait pas à jour tout seul et il fallait l’uploader tout le temps . Je n’ai pas non plus trouver de code en php qui effectuait cette tâche. J’ai donc fait le miens.

Exemple avec mon blog : http://shameleon.archives.free.fr/skyrss.php?blog=figaronron

Source

1. <?php
2. /*
3. Ce script permet de générer un fil RSS pour les SKYBLOGS
4. En effet les blogs SkyBlogs ne possedent pas de flux RSS, alors ce script vous en fourni un.
5. Utilisation : skyrss.php?blog=nomdublog OU skyrss.php?blog=http://nomdublog.skyblog.com
6. Vous pouvez utiliser celui mis a disposition, de cette façon :
7. http://shameleon.archives.free.fr/skyrss.php?blog=nomdublog
8.
9. Shameleon © 2006 X http://shameleon.archives.free.fr
10. Vous pouvez modifier ce script comme bon vous semble mais laissez ce message
11. Je tiens a être prévenu de toute diffusion éventuelle de ce script.
12.
13. A venir : jump sur les articles (signets type #a-285865492)
14. Contenu des articles
15. */
16. $articles = 0;
17. if(isset($_GET[‘blog’]))
18. {
19. $blog = $_GET[‘blog’];
20. //On test si BLOG est de type "figaronron" ou "http://figaronron.skyblog.com"
21.
22. if (preg_match("!^([0-9a-zA-Z.-])+$!i", $blog))
23. {
24. $titre = $blog;
25. $url = ‘http://’.$blog.’.skyblog.com’;
26. }
27. elseif (preg_match("!^http://([[0-9a-zA-Z.-])+.skyblog.com$!i", $blog))
28. {
29. $test = preg_match_all("!^http://([0-9a-zA-Z.-]*).skyblog.com$!i",$blog,$out);
30. $titre = $out[1][0];
31. $url = $blog;
32. }
33. else
34. {
35. exit();
36. }
37. }
38. else
39. {
40. exit();
41. }
42.
43.
44. $fp = fopen($url,"r"); //lecture du fichier
45.
46. while (!feof($fp)) { //on parcourt toutes les lignes
47. $rep = array();
48. $regs = array();
49. $extract = fgets($fp, 4096);
50. $page .= $extract; // lecture du contenu de la ligne
51. $blogtitre = eregi("<title>(.*)</title>",$extract,$regs); //on isole le titre
52. if($blogtitre)
53. {
54. $blogtitrea = $regs[1];
55. }
56. $first = eregi(‘<div class="article-top-bottom titre" id="[a-zA-Z0-9-]{1,30}">([^<]*)</div>’,$extract,$rep);
57. if((isset($rep[1])) && ($rep[1] !=  »))
58. {
59. $articles++;
60. $article[$articles][0] = $rep[1];
61. }
62. $rep = array();
63. $second = eregi(‘<div> posté le ([^<]*) </div>’,$extract,$rep);
64. if((isset($rep[1])) && ($rep[1] !=  »))
65. {
66. $article[$articles][1] = $rep[1];
67. }
68.
69. }
70.
71. //$titrarticle = eregi("<h1>Date de création :</h1>([0-9]{4})",$page,$regs2); //on isole le titre<div class="article-top-bottom titre" id="a-284271873">Manif 24/11/2005 =D</div>
72.
73.
74. //<div class="article-top-bottom titre" id="a-284271873">titre</div>
75.
76.
77. fclose($fp);
78.
79. //End
80.
81. /* Encodage iso-8859-1 pr les pbs des accents et autres caracs */
82. header("Content-Type: text/xml");
83. $xml = ‘<?xml version="1.0" encoding="iso-8859-1"?>
84. <rss version="0.92">
85. <channel>
86. <title>Blog "’.$titre.’"</title>
87. <link>’.$url.'</link>
88. <description>’.$blogtitrea.'</description>
89. <language>fr</language>’;
90.
91. for($i=1;$i<=$articles;$i++){
92. $articletitre =  ».$article[$i][0].’ (‘.$article[$i][1].’)’;
93.
94. $xml .= ‘<item>
95. <title>’.$articletitre.'</title>
96. <link>’.$url.'</link>
97. <content:encoded>’.$articletitre.'</content:encoded>
98. </item>’;
99. }
100.
101. $xml .= ‘ </channel> </rss>’;
102. echo $xml;
103. ?>