Napisałem sobie klasę do generowania RSS 2.0, ale nie działa :/

  1. <?php
  2.  
  3. class RSS{
  4.   #gen - generowanie na bieżąco, file - zapis do pliku
  5.    var $method = 'gen';
  6.    #jeśli method=file zmienna ta określa plik do którego ma zostać zapisana zawartość kanału
  7.    var $file;
  8.    
  9.    # Nagłowki kanału, tytuł, opis i link do strony
  10.    function RSS($title, $description, $link){
  11.        if($method=='gen'){
  12.            echo '<?xml version="1.0" encoding="UTF-8"?>\n';
  13.            echo '<rss version="2.0">\n';
  14.            echo '<channel>\n';
  15.            echo '<title>'.$title.'</title>\n';
  16.            echo '<link>'.$link.'</link>\n';
  17.            echo '<description>'.$description.'</description>\n';
  18.        } elseif($method=='file' and !empty($file) and is_file($file)){
  19.            $h=fopen($file, "w");
  20.            fwrite($h,'<?xml version="1.0" encoding="UTF-8"?>\n
  21.            <rss version="2.0">\n
  22.            <channel>\n
  23.            <title>'.$title.'</title>\n
  24.            <link>'.$link.'</link>\n
  25.            <description>'.$description.'</description>\n');
  26.            fclose($h);
  27.        }
  28.    }
  29.    
  30.    function addNews($newstitle, $pubdate, $newslink, $newsdesc){
  31.        if($method=='gen'){
  32.            echo '<item>\n';
  33.            echo '<title>'.$newstitle.'</title>\n';
  34.            echo '<pubDate>'.$pubdate.'</pubDate>\n';
  35.            echo '<link>'.$newslink.'</link>\n';
  36.            echo '<description>'.$newsdesc.'</description>\n';
  37.            echo '</item>\n';
  38.        } elseif($method=='file' and !empty($file) and is_file($file)){
  39.            $h = fopen($file, "a");
  40.            fwrite($h, '<item>\n
  41.            <title>'.$newstitle.'</title>\n
  42.            <pubDate>'.$pubdate.'</pubDate>\n
  43.            <link>'.$newslink.'</link>\n
  44.            <description>'.$newsdesc.'</description>\n
  45.            </item>\n');
  46.            fclose($h);
  47.        }
  48.    }
  49.    
  50.    function closeFile(){
  51.        if($method=='gen'){
  52.            echo '</channel>\n';
  53.            echo '</rss>\n';
  54.        } elseif($method=='file' and !empty($file) and is_file($file)){
  55.            $h = fopen($file, "a");
  56.            fwrite($h, '</channel>\n
  57.            </rss>\n');
  58.            fclose($h);
  59.        }
  60.    }
  61. }  
  62.  
  63. ?>


Wywołałem tak:
  1. <?php
  2. include "rss.class.php";
  3. $rss = new RSS('Mój kanał RSS', 'Opis kanału', 'http://example.com');
  4. $rss->method='gen';  
  5. $rss->addNews('Nius', '2008-10-07 19:00:00', 'http://example.com/?news_id=6', 'Treść wiadomości.');
  6. $rss->closeFile();
  7. ?>


Nic się nie dzieje, macie jakieś pomysły?