openrat-cms

# OpenRat Content Management System
git clone http://git.code.weiherhei.de/openrat-cms.git
Log | Files | Refs

Atom.class.php (4610B)


      1 <?php
      2 // ---------------------------------------------------------------------------
      3 // $Id$
      4 // ---------------------------------------------------------------------------
      5 // OpenRat Content Management System
      6 // Copyright (C) 2002 Jan Dankert, jandankert@jandankert.de
      7 //
      8 // This program is free software; you can redistribute it and/or
      9 // modify it under the terms of the GNU General Public License
     10 // as published by the Free Software Foundation; either version 2
     11 // of the License, or (at your option) any later version.
     12 //
     13 // This program is distributed in the hope that it will be useful,
     14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 // GNU General Public License for more details.
     17 //
     18 // You should have received a copy of the GNU General Public License
     19 // along with this program; if not, write to the Free Software
     20 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
     21 // ---------------------------------------------------------------------------
     22 use cms\model\Folder;
     23 use cms\model\BaseObject;
     24 use cms\model\Page;
     25 
     26 
     27 /**
     28  * Erstellen eines ATOM-Feeds
     29  * @author Jan Dankert
     30  */
     31 class Atom extends Macro
     32 {
     33 	/**
     34 	 * Bitte immer alle Parameter in dieses Array schreiben, dies ist fuer den Web-Developer hilfreich.
     35 	 * @type String
     36 	 */
     37 	var $parameters  = Array(
     38 		'folderid'        =>'Id of the folder whose pages should go into the Atom-Feed, default: the root folder',
     39 		'feed_url'        =>'Url of the feed, default: blank',
     40 		'feed_title'      =>'Title of the feed, default: Name of folder',
     41 		'feed_description'=>'Description of the feed, default: Description of folder'
     42 		);
     43 
     44 	var $folderid     = 0;
     45 
     46 	/**
     47 	 * Bitte immer eine Beschreibung benutzen, dies ist fuer den Web-Developer hilfreich.
     48 	 * @type String
     49 	 */
     50 	var $description      = 'Creates an Atom-Feed of pages in a folder';
     51 	var $api;
     52 
     53 	var $feed_url         = '';
     54 	var $feed_title       = '';
     55 	var $feed_description = '';
     56 
     57 	// Erstellen des Hauptmenues
     58 	function execute()
     59 	{
     60 		$feed = array();
     61 
     62 		// Lesen des Root-Ordners
     63 		if	( intval($this->folderid) == 0 )
     64 			$folder = new Folder( $this->getRootObjectId() );
     65 		else
     66 			$folder = new Folder( intval($this->folderid) );
     67 
     68 		$folder->load();
     69 
     70 		if	( $this->feed_title == '' )
     71 			$this->feed_title = $folder->name;
     72 
     73 		if	( $this->feed_description == '' )
     74 			$this->feed_description = $folder->desc;
     75 
     76 		$feed['title'      ] = $this->feed_title;			
     77 		$feed['description'] = $this->feed_description;			
     78 		$feed['url'        ] = $this->feed_url;			
     79 		$feed['items'      ] = array();			
     80 		// Schleife ueber alle Inhalte des Root-Ordners
     81 		foreach( $folder->getObjectIds() as $id )
     82 		{
     83 			if	( $id == $this->getObjectId() )
     84 				continue;
     85 			$o = new BaseObject( $id );
     86 			$o->languageid = $this->page->languageid;
     87 			$o->load();
     88 			if ( $o->isPage ) // Nur wenn Seite
     89 			{
     90 				$p = new Page( $id );
     91 				$p->load();
     92 
     93 				$item = array();
     94 				$item['title'      ] = $p->name;
     95 				$item['description'] = $p->desc;
     96 				$item['date'       ] = $p->lastchangeDate;
     97 				if	( empty($this->feed_url) )
     98 					$item['link'       ] = $this->pathToObject($id);
     99 				else
    100 					$item['link'       ] = $this->feed_url;
    101 				
    102 				$feed['items'][] = $item;
    103 			}
    104 		}
    105 		
    106 		$feed = $this->atomFeed($feed);
    107 
    108 		$this->output( $feed );
    109 	}
    110 	
    111 	
    112 	function atomFeed($input, $stylesheet='')
    113 	{
    114 		$input["encoding"]  = (empty($input["encoding"] ))?"UTF-8":$input["encoding"];
    115 		$input["language"]  = (empty($input["language"] ))?"en-us":$input["language"];
    116 		
    117 		if	( empty($input['title'      ])) $input['title'      ] = ''; 
    118 		if	( empty($input['description'])) $input['description'] = ''; 
    119 		if	( empty($input['link'       ])) $input['link'       ] = ''; 
    120 		$feed = '<?xml version="1.0" encoding="'.$input["encoding"].'"?>';
    121 		$feed .= (!empty($stylesheet))?"\n".'<?xml-stylesheet type="text/xsl" href="'.$stylesheet.'"?>':"";
    122 		$feed .= <<<__RSS__
    123 		
    124 		<feed xmlns="http://www.w3.org/2005/Atom">
    125   		<title>{$input["title"]}</title>
    126 		
    127 __RSS__;
    128 		    foreach($input["items"] as $item)
    129 		    {
    130 				if	( empty($item['title'      ])) $item['title'      ] = ''; 
    131 				if	( empty($item['description'])) $item['description'] = ''; 
    132 		        $feed .= "\n<entry>\n<title>".$item["title"]."</title>";
    133 		        $feed .= "\n<summary><![CDATA[".$item["description"]."]]></summary>";
    134 	            $feed .= "\n<updated>".date('Y-m-d\TH:i:s\Z', $item["date"])."</updated>";
    135 	            $feed .= "\n<link href=\"".$item["link"]."\" />";
    136 		        $feed .= "\n</entry>\n";
    137 		    }
    138 			$feed .= "\n</feed>";
    139 		return $feed;
    140 	}
    141 }