File modules/cms/macros/macro/RSSCreate.class.php

Last commit: Sun Dec 5 20:33:24 2021 +0100	dankert	Cleanup: Removed unusable properties from class 'Value' and 'BaseObject'.
1 <?php 2 namespace cms\macros\macro; 3 // --------------------------------------------------------------------------- 4 // $Id$ 5 // --------------------------------------------------------------------------- 6 // OpenRat Content Management System 7 // Copyright (C) 2002 Jan Dankert, jandankert@jandankert.de 8 // 9 // This program is free software; you can redistribute it and/or 10 // modify it under the terms of the GNU General Public License 11 // as published by the Free Software Foundation; either version 2 12 // of the License, or (at your option) any later version. 13 // 14 // This program is distributed in the hope that it will be useful, 15 // but WITHOUT ANY WARRANTY; without even the implied warranty of 16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 // GNU General Public License for more details. 18 // 19 // You should have received a copy of the GNU General Public License 20 // along with this program; if not, write to the Free Software 21 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 // --------------------------------------------------------------------------- 23 // $Log$ 24 // Revision 1.4 2009-03-16 23:30:02 dankert 25 // Unnötigen Aufruf von pathToObject entfernt. 26 // 27 // Revision 1.3 2007-11-17 02:19:29 dankert 28 // Erg?nzung der Version (Default: 0.91), Korrektur, Anpassung an neue API. 29 // 30 // Revision 1.2 2004/12/28 22:57:56 dankert 31 // Korrektur Vererbung, "api" ausgebaut 32 // 33 // Revision 1.1 2004/10/14 21:14:52 dankert 34 // Erzeugen eines RSS-Feeds aus einem Ordner 35 // 36 // --------------------------------------------------------------------------- 37 use cms\model\Folder; 38 use cms\model\Page; 39 use util\Macro; 40 41 42 /** 43 * Erstellen eines Hauptmenues 44 * @author Jan Dankert 45 */ 46 class RSSCreate extends Macro 47 { 48 /** 49 * Bitte immer alle Parameter in dieses Array schreiben, dies ist fuer den Web-Developer hilfreich. 50 * @type String 51 */ 52 var $parameters = Array( 53 'htmlentities' =>'Escape HTML-Tags in RSS-Feed, default: false', 54 'folderid' =>'Id of the folder whose pages should go into the RSS-Feed, default: the root folder', 55 'feed_url' =>'Url of the feed, default: blank', 56 'feed_title' =>'Title of the feed, default: Name of folder', 57 'feed_description'=>'Description of the feed, default: Description of folder' 58 ); 59 60 var $htmlentities = false; 61 var $folderid = 0; 62 63 /** 64 * Bitte immer eine Beschreibung benutzen, dies ist fuer den Web-Developer hilfreich. 65 * @type String 66 */ 67 var $description = 'Creates an RSS-Feed of pages in a folder'; 68 var $api; 69 70 var $feed_version = '0.91'; 71 var $feed_url = ''; 72 var $feed_title = ''; 73 var $feed_description = ''; 74 75 // Erstellen des Hauptmenues 76 function execute() 77 { 78 $feed = array(); 79 80 // Lesen des Root-Ordners 81 if ( intval($this->folderid) == 0 ) 82 $folder = new Folder( $this->getRootObjectId() ); 83 else 84 $folder = new Folder( intval($this->folderid) ); 85 86 $folder->load(); 87 88 if ( $this->feed_title == '' ) 89 $this->feed_title = $folder->getNameForLanguage( $this->pageContext->languageId )->name; 90 91 if ( $this->feed_description == '' ) 92 $this->feed_description = $folder->getNameForLanguage( $this->pageContext->languageId )->description; 93 94 $feed['title' ] = $this->feed_title; 95 $feed['description'] = $this->feed_description; 96 $feed['url' ] = $this->feed_url; 97 $feed['items' ] = array(); 98 99 // Schleife ueber alle Inhalte des Root-Ordners 100 foreach( $folder->getObjectIds() as $id ) 101 { 102 if ( $id == $this->getObjectId() ) 103 continue; 104 $o = new Object( $id ); 105 $o->load(); 106 if ( $o->isPage ) // Nur wenn Seite 107 { 108 $p = new Page( $id ); 109 $p->load(); 110 111 $item = array(); 112 113 $name = $p->getNameForLanguage($this->pageContext->languageId); 114 $item['title' ] = $name->name; 115 $item['description'] = $name->description; 116 $item['pubDate' ] = $p->lastchangeDate; 117 if ( empty($this->feed_url) ) 118 $item['link' ] = $this->pathToObject($id); 119 else 120 $item['link' ] = $this->feed_url; 121 122 $feed['items'][] = $item; 123 } 124 } 125 126 $rss = $this->rss($feed); 127 128 if ( $this->htmlentities ) 129 $rss = htmlentities( $rss ); 130 131 $this->output( $rss ); 132 } 133 134 135 function rss($input, $stylesheet='') 136 { 137 // print_r($input); 138 // Builds the XML RSS schema using the array 139 $input["encoding"] = (empty($input["encoding"] ))?"UTF-8":$input["encoding"]; 140 $input["language"] = (empty($input["language"] ))?"en-us":$input["language"]; 141 142 if ( empty($input['title' ])) $input['title' ] = ''; 143 if ( empty($input['description'])) $input['description'] = ''; 144 if ( empty($input['link' ])) $input['link' ] = ''; 145 $rss = '<?xml version="1.0" encoding="'.$input["encoding"].'"?>'; 146 $rss .= (!empty($stylesheet))?"\n".'<?xml-stylesheet type="text/xsl" href="'.$stylesheet.'"?>':""; 147 $rss .= <<<__RSS__ 148 149 <rss version="{$this->feed_version}"> 150 <channel> 151 <title>{$input["title"]}</title> 152 <description>{$input["description"]}</description> 153 <link>{$input["link"]}</link> 154 <language>{$input["language"]}</language> 155 <generator></generator> 156 157 __RSS__; 158 foreach($input["items"] as $item) 159 { 160 if ( empty($item['title' ])) $item['title' ] = ''; 161 if ( empty($item['description'])) $item['description'] = ''; 162 $data = date("r", $item["pubDate"]); 163 $rss .= "\n<item>\n<title>".$item["title"]."</title>"; 164 $rss .= "\n<description><![CDATA[".$item["description"]."]]></description>"; 165 if (!empty($item["pubDate"])) 166 $rss .= "\n<pubDate>".date("r", $item["pubDate"])."</pubDate>"; 167 if (!empty($item["link"])) 168 $rss .= "\n<link>".$item["link"]."</link>"; 169 $rss .= "\n</item>\n"; 170 } 171 $rss .= "\n</channel>\n</rss>"; 172 return $rss; 173 } 174 }
Download modules/cms/macros/macro/RSSCreate.class.php
History Sun, 5 Dec 2021 20:33:24 +0100 dankert Cleanup: Removed unusable properties from class 'Value' and 'BaseObject'. Sun, 23 Feb 2020 04:49:34 +0100 Jan Dankert Refactoring with Namespaces for the cms modules, part 2. Sun, 23 Feb 2020 04:01:30 +0100 Jan Dankert Refactoring with Namespaces for the cms modules, part 1: moving.