Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> RSS Maker, Klasa, PHP 4 i 5
bela
post
Post #1


Administrator PHPedia.pl


Grupa: Developerzy
Postów: 1 102
Pomógł: 2
Dołączył: 14.09.2003

Ostrzeżenie: (0%)
-----


Dziś popołudniu nie miałem co robić i napisałem klasa do generowania plików rss.
  1. <?php
  2. /**
  3.  * Klasa do generowania pliku RSS
  4.  * @author Piotr 'bela_666' Belina
  5.  * @package belacms
  6.  */
  7.  
  8. /**
  9.  * Klasa do generowania pliku RSS
  10.  */
  11.  
  12. class RSS {
  13.  
  14. /**
  15.  * Zmienna ustawiająca kodowanie znaków
  16.  */
  17. var $strCharset = &#092;"iso-8859-2\";
  18.  
  19. /**
  20.  * Adres pliku
  21.  */
  22. var $strURL;
  23.  
  24. /**
  25.  * Tytuł RSSa
  26.  */
  27. var $strTitle;
  28.  
  29. /**
  30.  * Adres strony
  31.  */
  32. var $strLink;
  33.  
  34. /**
  35.  * Opis kanału
  36.  */
  37. var $strDesc;
  38.  
  39. /**
  40.  * Adres obrazka
  41.  */
  42. var $mixURLImage = 0;
  43.  
  44. /**
  45.  * Adres strony pod obrazkiem
  46.  * Jeżeli $mixURLImage nie jest równy 0, to ta zmienna też musi być
  47.  */
  48. var $strImageLink;
  49.  
  50. /**
  51.  * Tablica z poszczególnymi itemami
  52.  */
  53. var $arrItems = array();
  54.  
  55. /**
  56.  * Konstruktor
  57.  */
  58. function RSS (){
  59. }
  60.  
  61. /**
  62.  * Funkcja wyświetlająca początek pliku
  63.  */
  64. function startRSS(){
  65. header(&#092;"Content-type: text/xml; charset=\" . $this->strCharset);
  66. print('<'.'?xml version=\"1.0\" encoding=\"' . $this->strCharset . '\" ?' . '>'.&#092;"n\");
  67. print('<rdf:RDF
  68. xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"
  69. xmlns=\"http://purl.org/rss/1.0/\">'.&#092;"n\");
  70. print('<channel rdf:about=\"' . $this->strURL .'\">'.&#092;"n\");
  71. print('<title>'. $this->strTitle .'</title>'.&#092;"n\");
  72. print('<link>'. $this->strLink .'</link>'.&#092;"n\");
  73. print('<description>'. $this->strDesc .'</description>'.&#092;"n\");
  74.  
  75. if($this->mixURLImage) {
  76. print('<image rdf:about=\"' . $this->mixURLImage . '\">'.&#092;"n\");
  77. print('<title>'. $strTitle .'</title>'.&#092;"n\");
  78. print('<link>'. $strImageLink .'</link>'.&#092;"n\");
  79. print('<url>'. $mixURLImage .'</url>'.&#092;"n\");
  80. print('</image>'.&#092;"n\");
  81. }
  82. }
  83.  
  84. /**
  85.  * Funkcja dodaje Item do tablicy
  86.  */
  87. function addItem($strItemLink, $strItemTitle, $strItemDesc) {
  88. $this->arrItems[] = '<item rdf:about=\"'. $strItemLink .'\">'.&#092;"n\".
  89. '<title>'.$strItemTitle.'</title>'.&#092;"n\".
  90. '<link>'.$strItemLink.'</link>'.&#092;"n\".
  91. '<description>'.$strItemDesc.'</description>'.&#092;"n\".
  92. '</item>'.&#092;"n\";
  93. }
  94.  
  95. /**
  96.  * Funkcja wyświetlająca wszystkie Itemy
  97.  */
  98. function showAll() {
  99. foreach($this->arrItems as $strItem) {
  100. print($strItem);
  101. }
  102. print('</channel>'.&#092;"n\");
  103. print '</rdf:RDF>'.&#092;"n\";
  104. }
  105. }
  106. ?>


A oto przykład wykorzystania jej
  1. <?php
  2. /* Przykład wykorzystania klasy RSS */
  3. require_once(&#092;"rss_class.php\");
  4.  
  5. $rss = new rss();
  6.  
  7. $rss->strURL = &#092;"http://localhost/rss_class/example.php\";
  8. $rss->strTitle = &#092;"BelaCMS RSS\";
  9. $rss->strLink = &#092;"http://localhost/belacms/index.php\";
  10. $rss->strDesc = &#092;"Na tym kanale będą zamieszczane informacje dotyczące BelaCMS\";
  11.  
  12. $rss->startRSS();
  13.  
  14. $rss->addItem(&#092;"http://localhost/mmcms/index.php\", \"Pierwsza wersja alfa\", \"Właśnie ukazała się pierwsza wersja alfa\");
  15.  
  16. $rss->showAll();
  17. ?>


Klasa ta jest zgodna ze specyfikacją 1.0

Zapraszam do testowania, zgłaszania propozycji zmian.
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 20.09.2025 - 09:41