openrat-cms

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

RSSCreate.class.php (5586B)


      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 // $Log$
     23 // Revision 1.4  2009-03-16 23:30:02  dankert
     24 // Unnötigen Aufruf von pathToObject entfernt.
     25 //
     26 // Revision 1.3  2007-11-17 02:19:29  dankert
     27 // Erg?nzung der Version (Default: 0.91), Korrektur, Anpassung an neue API.
     28 //
     29 // Revision 1.2  2004/12/28 22:57:56  dankert
     30 // Korrektur Vererbung, "api" ausgebaut
     31 //
     32 // Revision 1.1  2004/10/14 21:14:52  dankert
     33 // Erzeugen eines RSS-Feeds aus einem Ordner
     34 //
     35 // ---------------------------------------------------------------------------
     36 use cms\model\Folder;
     37 
     38 
     39 /**
     40  * Erstellen eines Hauptmenues
     41  * @author Jan Dankert
     42  */
     43 class RSSCreate extends Macro
     44 {
     45 	/**
     46 	 * Bitte immer alle Parameter in dieses Array schreiben, dies ist fuer den Web-Developer hilfreich.
     47 	 * @type String
     48 	 */
     49 	var $parameters  = Array(
     50 		'htmlentities'    =>'Escape HTML-Tags in RSS-Feed, default: false',
     51 		'folderid'        =>'Id of the folder whose pages should go into the RSS-Feed, default: the root folder',
     52 		'feed_url'        =>'Url of the feed, default: blank',
     53 		'feed_title'      =>'Title of the feed, default: Name of folder',
     54 		'feed_description'=>'Description of the feed, default: Description of folder'
     55 		);
     56 
     57 	var $htmlentities = false;
     58 	var $folderid     = 0;
     59 
     60 	/**
     61 	 * Bitte immer eine Beschreibung benutzen, dies ist fuer den Web-Developer hilfreich.
     62 	 * @type String
     63 	 */
     64 	var $description      = 'Creates an RSS-Feed of pages in a folder';
     65 	var $api;
     66 
     67 	var $feed_version     = '0.91';
     68 	var $feed_url         = '';
     69 	var $feed_title       = '';
     70 	var $feed_description = '';
     71 
     72 	// Erstellen des Hauptmenues
     73 	function execute()
     74 	{
     75 		$feed = array();
     76 
     77 		// Lesen des Root-Ordners
     78 		if	( intval($this->folderid) == 0 )
     79 			$folder = new Folder( $this->getRootObjectId() );
     80 		else
     81 			$folder = new Folder( intval($this->folderid) );
     82 
     83 		$folder->load();
     84 
     85 		if	( $this->feed_title == '' )
     86 			$this->feed_title = $folder->name;
     87 
     88 		if	( $this->feed_description == '' )
     89 			$this->feed_description = $folder->desc;
     90 
     91 		$feed['title'      ] = $this->feed_title;			
     92 		$feed['description'] = $this->feed_description;			
     93 		$feed['url'        ] = $this->feed_url;			
     94 		$feed['items'      ] = array();			
     95 
     96 		// Schleife ueber alle Inhalte des Root-Ordners
     97 		foreach( $folder->getObjectIds() as $id )
     98 		{
     99 			if	( $id == $this->getObjectId() )
    100 				continue;
    101 			$o = new Object( $id );
    102 			$o->languageid = $this->page->languageid;
    103 			$o->load();
    104 			if ( $o->isPage ) // Nur wenn Seite
    105 			{
    106 				$p = new Page( $id );
    107 				$p->load();
    108 
    109 				$item = array();
    110 				$item['title'      ] = $p->name;
    111 				$item['description'] = $p->desc;
    112 				$item['pubDate'    ] = $p->lastchangeDate;
    113 				if	( empty($this->feed_url) )
    114 					$item['link'       ] = $this->pathToObject($id);
    115 				else
    116 					$item['link'       ] = $this->feed_url;
    117 				
    118 				$feed['items'][] = $item;
    119 			}
    120 		}
    121 		
    122 		$rss = $this->rss($feed);
    123 
    124 		if	( $this->htmlentities )
    125 			$rss = htmlentities( $rss );
    126 
    127 		$this->output( $rss );
    128 	}
    129 	
    130 	
    131 	function rss($input, $stylesheet='')
    132 	{
    133 //		print_r($input);
    134 		 // Builds the XML RSS schema using the array
    135 		$input["encoding"]  = (empty($input["encoding"] ))?"UTF-8":$input["encoding"];
    136 		$input["language"]  = (empty($input["language"] ))?"en-us":$input["language"];
    137 		
    138 		if	( empty($input['title'      ])) $input['title'      ] = ''; 
    139 		if	( empty($input['description'])) $input['description'] = ''; 
    140 		if	( empty($input['link'       ])) $input['link'       ] = ''; 
    141 		$rss = '<?xml version="1.0" encoding="'.$input["encoding"].'"?>';
    142 		$rss .= (!empty($stylesheet))?"\n".'<?xml-stylesheet type="text/xsl" href="'.$stylesheet.'"?>':"";
    143 		$rss .= <<<__RSS__
    144 		
    145 		<rss version="{$this->feed_version}">
    146 		<channel>
    147 		<title>{$input["title"]}</title>
    148 		<description>{$input["description"]}</description>
    149 		<link>{$input["link"]}</link>
    150 		<language>{$input["language"]}</language>
    151 		<generator></generator>
    152 		
    153 __RSS__;
    154 		    foreach($input["items"] as $item)
    155 		    {
    156 				if	( empty($item['title'      ])) $item['title'      ] = ''; 
    157 				if	( empty($item['description'])) $item['description'] = ''; 
    158 		        $data = date("r", $item["pubDate"]);
    159 		        $rss .= "\n<item>\n<title>".$item["title"]."</title>";
    160 		        $rss .= "\n<description><![CDATA[".$item["description"]."]]></description>";
    161 		        if (!empty($item["pubDate"]))
    162 		            $rss .= "\n<pubDate>".date("r", $item["pubDate"])."</pubDate>";
    163 		        if (!empty($item["link"]))
    164 		            $rss .= "\n<link>".$item["link"]."</link>";
    165 		        $rss .= "\n</item>\n";
    166 		    }
    167 			$rss .= "\n</channel>\n</rss>";
    168 		return $rss;
    169 	}
    170 }