MCMS
[ class tree: MCMS ] [ index: MCMS ] [ all elements ]

Source for file rss.php

Documentation is available at rss.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | MCMS: a PHP Content Management System for creating accessible sites. |
  5. // | Copyright (C) 2005  Silvio Moioli                                    |
  6. // |                                                                      |
  7. // | This program is free software; you can redistribute it and/or modify |
  8. // | it under the terms of the GNU General Public License as published by |
  9. // | the Free Software Foundation; either version 2 of the License, or    |
  10. // | (at your option) any later version.                                  |
  11. // |                                                                      |
  12. // | This program is distributed in the hope that it will be useful,      |
  13. // | but WITHOUT ANY WARRANTY; without even the implied warranty of       |
  14. // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        |
  15. // | GNU General Public License for more details.                         |
  16. // |                                                                      |
  17. // | You should have received a copy of the GNU General Public License    |
  18. // | along with this program; if not, write to the Free Software          |
  19. // | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 |
  20. // +----------------------------------------------------------------------+
  21. // | Authors: Silvio Moioli <silvio at moioli dot net> www.moioli.net     |
  22. // +----------------------------------------------------------------------+
  23. //
  24. //$Id:
  25. /**
  26.  * Classe per l'aggiunta di un feed RSS 2 al sito.
  27.  *
  28.  * @package  MCMS
  29.  * @version  2
  30.  * @author   Silvio Moioli <silvio at moioli dot net>
  31.  */
  32.  
  33. /** Carica la classe base di MCMS per l'interfacciamento al Database */
  34. require_once $_SERVER["DOCUMENT_ROOT"]."/admin/lib/model/Engine.php";
  35.  
  36. /**
  37.  *  Classe per l'aggiunta di un feed RSS 2 al sito.
  38.  *
  39.  *
  40.  * @package  MCMS
  41.  * @version  2
  42.  * @author   Silvio Moioli <silvio at moioli dot net>
  43.  */
  44. class rss extends Component
  45. {
  46.     /**
  47.      * Scritto solo per la concatenazione dei costruttori.
  48.      *
  49.      */
  50.     function rss()
  51.     {
  52.         $this->Component();
  53.     }
  54.  
  55.     /**
  56.      * Ritorna il nome di questo componente.
  57.      *
  58.      * @return string il nome del componente
  59.      */
  60.     function getName()
  61.     {
  62.         return "Feed RSS";
  63.     }
  64.  
  65.     /**
  66.      *
  67.      * Questo componente non ha bisogno di inizializzazione,
  68.      * perciņ questo metodo č vuoto.
  69.      *
  70.      * @param Engine $engine il motore di MCMS
  71.      */
  72.     function init($engine)
  73.     {
  74.     }
  75.  
  76.     /**
  77.      *
  78.      * Aggiunge la voce di menu per la mappa del sito (a tutte le
  79.      * pagine).
  80.      *
  81.      * @param string $contents i contenuti della pagina da modificare
  82.      * @param array $menuEntries il menu della pagina
  83.      * @param string $title il titolo della pagina da modificare
  84.      * @param Site $site il sito corrente
  85.      */
  86.     function applyComponent(&$contents&$menuEntries&$title,
  87.         &$description$site)
  88.     {
  89.         $siteID $site->getID();
  90.         $menuEntries ["<p><a type=\"application/rss+xml\"".
  91.         " href=\"/feed.rss\">Feed RSS</a> per restare sempre aggiornato!</p>";
  92.     }
  93.     
  94.     /**
  95.      * Salva il feed RSS 2.0 del sito
  96.      *
  97.      * @param Site $site il sito corrente
  98.      * @param Compiler $compiler l'oggetto per il salvataggio dei file
  99.      * @see Component
  100.      */
  101.     function saveFiles($site$compiler)
  102.     {
  103.         $siteName $site->getURL();
  104.         $result "<?xml version=\"1.0\" encoding='ISO-8859-1'?>
  105.             <rdf:RDF 
  106.             xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"
  107.             xmlns=\"http://purl.org/rss/1.0/\"
  108.             xmlns:dc=\"http://purl.org/dc/elements/1.1/\"
  109.             >
  110.             <channel rdf:about=\"http://www.moioli.net/feed.rss\">
  111.             <title>moioli.net</title>
  112.             <link>$siteName</link>
  113.             <description>Sito di Silvio Moioli</description>
  114.             <items>
  115.             <rdf:Seq>
  116.                 <rdf:li resource=\"$siteName/?1#notizia1\"/>
  117.                 <rdf:li resource=\"$siteName/?2#notizia2\"/>
  118.                 <rdf:li resource=\"$siteName/?3#notizia3\"/>
  119.                 <rdf:li resource=\"$siteName/?4#notizia4\"/>
  120.                 <rdf:li resource=\"$siteName/?5#notizia5\"/>
  121.             </rdf:Seq>
  122.             </items>
  123.             </channel>";
  124.         $news $site->getNews();
  125.         $newscount 0;
  126.         foreach ($news as $i{
  127.             //Massimo 5 notizie sul feed
  128.             if ($newscount >= 5{
  129.                 break;
  130.             }
  131.             $newscount++;
  132.             $newsTitle strip_tags($i->getTitle());
  133.             $content strip_tags($i->getContents());
  134.             $content str_replace($content,"&","&amp;");
  135.             $date $i->getDate();
  136.             $result .= "<item rdf:about=\"$siteName/?$newscount#$newscount\">
  137.                 <title>$newsTitle</title>
  138.                 <link>$siteName/?$newscount#$newscount</link>
  139.                 <description>$content</description>
  140.                 <dc:date>$date</dc:date>
  141.                 </item>";
  142.         }
  143.         $result .="</rdf:RDF>";
  144.         $compiler->fileSave("feed.rss"$resultfalse);
  145.     }
  146. }
  147. ?>

Documentation generated on Wed, 26 Jul 2006 21:44:56 +0200 by phpDocumentor 1.3.0RC6