Atom.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 
00023 
00024 
00029 class Atom extends Dynamic
00030 {
00035      var $parameters  = Array(
00036           'folderid'        =>'Id of the folder whose pages should go into the Atom-Feed, default: the root folder',
00037           'feed_url'        =>'Url of the feed, default: blank',
00038           'feed_title'      =>'Title of the feed, default: Name of folder',
00039           'feed_description'=>'Description of the feed, default: Description of folder'
00040           );
00041 
00042      var $folderid     = 0;
00043 
00048      var $description      = 'Creates an Atom-Feed of pages in a folder';
00049      var $api;
00050 
00051      var $feed_url         = '';
00052      var $feed_title       = '';
00053      var $feed_description = '';
00054 
00055      // Erstellen des Hauptmenues
00056      function execute()
00057      {
00058           $feed = array();
00059 
00060           // Lesen des Root-Ordners
00061           if   ( intval($this->folderid) == 0 )
00062                $folder = new Folder( $this->getRootObjectId() );
00063           else
00064                $folder = new Folder( intval($this->folderid) );
00065 
00066           $folder->load();
00067 
00068           if   ( $this->feed_title == '' )
00069                $this->feed_title = $folder->name;
00070 
00071           if   ( $this->feed_description == '' )
00072                $this->feed_description = $folder->desc;
00073 
00074           $feed['title'      ] = $this->feed_title;              
00075           $feed['description'] = $this->feed_description;             
00076           $feed['url'        ] = $this->feed_url;           
00077           $feed['items'      ] = array();              
00078           // Schleife ueber alle Inhalte des Root-Ordners
00079           foreach( $folder->getObjectIds() as $id )
00080           {
00081                if   ( $id == $this->getObjectId() )
00082                     continue;
00083                $o = new Object( $id );
00084                $o->languageid = $this->page->languageid;
00085                $o->load();
00086                if ( $o->isPage ) // Nur wenn Seite
00087                {
00088                     $p = new Page( $id );
00089                     $p->load();
00090 
00091                     $item = array();
00092                     $item['title'      ] = $p->name;
00093                     $item['description'] = $p->desc;
00094                     $item['date'       ] = $p->lastchangeDate;
00095                     if   ( empty($this->feed_url) )
00096                          $item['link'       ] = $this->pathToObject($id);
00097                     else
00098                          $item['link'       ] = $this->feed_url;
00099                     
00100                     $feed['items'][] = $item;
00101                }
00102           }
00103           
00104           $feed = $this->atomFeed($feed);
00105 
00106           $this->output( $feed );
00107      }
00108      
00109      
00110      function atomFeed($input, $stylesheet='')
00111      {
00112           $input["encoding"]  = (empty($input["encoding"] ))?"UTF-8":$input["encoding"];
00113           $input["language"]  = (empty($input["language"] ))?"en-us":$input["language"];
00114           
00115           if   ( empty($input['title'      ])) $input['title'      ] = ''; 
00116           if   ( empty($input['description'])) $input['description'] = ''; 
00117           if   ( empty($input['link'       ])) $input['link'       ] = ''; 
00118           $feed = '<?xml version="1.0" encoding="'.$input["encoding"].'"?>';
00119           $feed .= (!empty($stylesheet))?"\n".'<?xml-stylesheet type="text/xsl" href="'.$stylesheet.'"?>':"";
00120           $feed .= <<<__RSS__
00121           
00122           <feed xmlns="http://www.w3.org/2005/Atom">
00123           <title>{$input["title"]}</title>
00124           
00125 __RSS__;
00126               foreach($input["items"] as $item)
00127               {
00128                     if   ( empty($item['title'      ])) $item['title'      ] = ''; 
00129                     if   ( empty($item['description'])) $item['description'] = ''; 
00130                   $feed .= "\n<entry>\n<title>".$item["title"]."</title>";
00131                   $feed .= "\n<summary><![CDATA[".$item["description"]."]]></summary>";
00132                  $feed .= "\n<updated>".date('Y-m-d\TH:i:s\Z', $item["date"])."</updated>";
00133                  $feed .= "\n<link href=\"".$item["link"]."\" />";
00134                   $feed .= "\n</entry>\n";
00135               }
00136                $feed .= "\n</feed>";
00137           return $feed;
00138      }
00139 }

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