RSSCreate.class.php

gehe zur Dokumentation dieser Datei
00001 <?php
00002 // ---------------------------------------------------------------------------
00003 // $Id$
00004 // ---------------------------------------------------------------------------
00005 // OpenRat Content Management System
00006 // Copyright (C) 2002 Jan Dankert, jandankert@jandankert.de
00007 //
00008 // This program is free software; you can redistribute it and/or
00009 // modify it under the terms of the GNU General Public License
00010 // as published by the Free Software Foundation; either version 2
00011 // of the License, or (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the Free Software
00020 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00021 // ---------------------------------------------------------------------------
00022 // $Log$
00023 // Revision 1.4  2009-03-16 23:30:02  dankert
00024 // Unnötigen Aufruf von pathToObject entfernt.
00025 //
00026 // Revision 1.3  2007-11-17 02:19:29  dankert
00027 // Erg?nzung der Version (Default: 0.91), Korrektur, Anpassung an neue API.
00028 //
00029 // Revision 1.2  2004/12/28 22:57:56  dankert
00030 // Korrektur Vererbung, "api" ausgebaut
00031 //
00032 // Revision 1.1  2004/10/14 21:14:52  dankert
00033 // Erzeugen eines RSS-Feeds aus einem Ordner
00034 //
00035 // ---------------------------------------------------------------------------
00036 
00037 
00038 
00043 class RSSCreate extends Dynamic
00044 {
00049      var $parameters  = Array(
00050           'htmlentities'    =>'Escape HTML-Tags in RSS-Feed, default: false',
00051           'folderid'        =>'Id of the folder whose pages should go into the RSS-Feed, default: the root folder',
00052           'feed_url'        =>'Url of the feed, default: blank',
00053           'feed_title'      =>'Title of the feed, default: Name of folder',
00054           'feed_description'=>'Description of the feed, default: Description of folder'
00055           );
00056 
00057      var $htmlentities = false;
00058      var $folderid     = 0;
00059 
00064      var $description      = 'Creates an RSS-Feed of pages in a folder';
00065      var $api;
00066 
00067      var $feed_version     = '0.91';
00068      var $feed_url         = '';
00069      var $feed_title       = '';
00070      var $feed_description = '';
00071 
00072      // Erstellen des Hauptmenues
00073      function execute()
00074      {
00075           $feed = array();
00076 
00077           // Lesen des Root-Ordners
00078           if   ( intval($this->folderid) == 0 )
00079                $folder = new Folder( $this->getRootObjectId() );
00080           else
00081                $folder = new Folder( intval($this->folderid) );
00082 
00083           $folder->load();
00084 
00085           if   ( $this->feed_title == '' )
00086                $this->feed_title = $folder->name;
00087 
00088           if   ( $this->feed_description == '' )
00089                $this->feed_description = $folder->desc;
00090 
00091           $feed['title'      ] = $this->feed_title;              
00092           $feed['description'] = $this->feed_description;             
00093           $feed['url'        ] = $this->feed_url;           
00094           $feed['items'      ] = array();              
00095 
00096           // Schleife ueber alle Inhalte des Root-Ordners
00097           foreach( $folder->getObjectIds() as $id )
00098           {
00099                if   ( $id == $this->getObjectId() )
00100                     continue;
00101                $o = new Object( $id );
00102                $o->languageid = $this->page->languageid;
00103                $o->load();
00104                if ( $o->isPage ) // Nur wenn Seite
00105                {
00106                     $p = new Page( $id );
00107                     $p->load();
00108 
00109                     $item = array();
00110                     $item['title'      ] = $p->name;
00111                     $item['description'] = $p->desc;
00112                     $item['pubDate'    ] = $p->lastchangeDate;
00113                     if   ( empty($this->feed_url) )
00114                          $item['link'       ] = $this->pathToObject($id);
00115                     else
00116                          $item['link'       ] = $this->feed_url;
00117                     
00118                     $feed['items'][] = $item;
00119                }
00120           }
00121           
00122           $rss = $this->rss($feed);
00123 
00124           if   ( $this->htmlentities )
00125                $rss = htmlentities( $rss );
00126 
00127           $this->output( $rss );
00128      }
00129      
00130      
00131      function rss($input, $stylesheet='')
00132      {
00133 //        print_r($input);
00134            // Builds the XML RSS schema using the array
00135           $input["encoding"]  = (empty($input["encoding"] ))?"UTF-8":$input["encoding"];
00136           $input["language"]  = (empty($input["language"] ))?"en-us":$input["language"];
00137           
00138           if   ( empty($input['title'      ])) $input['title'      ] = ''; 
00139           if   ( empty($input['description'])) $input['description'] = ''; 
00140           if   ( empty($input['link'       ])) $input['link'       ] = ''; 
00141           $rss = '<?xml version="1.0" encoding="'.$input["encoding"].'"?>';
00142           $rss .= (!empty($stylesheet))?"\n".'<?xml-stylesheet type="text/xsl" href="'.$stylesheet.'"?>':"";
00143           $rss .= <<<__RSS__
00144           
00145           <rss version="{$this->feed_version}">
00146           <channel>
00147           <title>{$input["title"]}</title>
00148           <description>{$input["description"]}</description>
00149           <link>{$input["link"]}</link>
00150           <language>{$input["language"]}</language>
00151           <generator></generator>
00152           
00153 __RSS__;
00154               foreach($input["items"] as $item)
00155               {
00156                     if   ( empty($item['title'      ])) $item['title'      ] = ''; 
00157                     if   ( empty($item['description'])) $item['description'] = ''; 
00158                   $data = date("r", $item["pubDate"]);
00159                   $rss .= "\n<item>\n<title>".$item["title"]."</title>";
00160                   $rss .= "\n<description><![CDATA[".$item["description"]."]]></description>";
00161                   if (!empty($item["pubDate"]))
00162                       $rss .= "\n<pubDate>".date("r", $item["pubDate"])."</pubDate>";
00163                   if (!empty($item["link"]))
00164                       $rss .= "\n<link>".$item["link"]."</link>";
00165                   $rss .= "\n</item>\n";
00166               }
00167                $rss .= "\n</channel>\n</rss>";
00168           return $rss;
00169      }
00170 }

Erzeugt am Thu May 14 00:55:48 2009 für OpenRat von  doxygen 1.5.8