File modules/cms/macros/macro/Atom.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 use cms\model\Folder; 24 use cms\model\BaseObject; 25 use cms\model\Page; 26 use util\Macro; 27 28 29 /** 30 * Erstellen eines ATOM-Feeds 31 * @author Jan Dankert 32 */ 33 class Atom extends Macro 34 { 35 /** 36 * Bitte immer alle Parameter in dieses Array schreiben, dies ist fuer den Web-Developer hilfreich. 37 * @type String 38 */ 39 var $parameters = Array( 40 'folderid' =>'Id of the folder whose pages should go into the Atom-Feed, default: the root folder', 41 'feed_url' =>'Url of the feed, default: blank', 42 'feed_title' =>'Title of the feed, default: Name of folder', 43 'feed_description'=>'Description of the feed, default: Description of folder' 44 ); 45 46 var $folderid = 0; 47 48 /** 49 * Bitte immer eine Beschreibung benutzen, dies ist fuer den Web-Developer hilfreich. 50 * @type String 51 */ 52 var $description = 'Creates an Atom-Feed of pages in a folder'; 53 var $api; 54 55 var $feed_url = ''; 56 var $feed_title = ''; 57 var $feed_description = ''; 58 59 // Erstellen des Hauptmenues 60 function execute() 61 { 62 $feed = array(); 63 64 // Lesen des Root-Ordners 65 if ( intval($this->folderid) == 0 ) 66 $folder = new Folder( $this->getRootObjectId() ); 67 else 68 $folder = new Folder( intval($this->folderid) ); 69 70 $folder->load(); 71 72 if ( $this->feed_title == '' ) 73 $this->feed_title = $folder->getNameForLanguage( $this->pageContext->languageId )->name; 74 75 if ( $this->feed_description == '' ) 76 $this->feed_description = $folder->getNameForLanguage( $this->pageContext->languageId )->description; 77 78 $feed['title' ] = $this->feed_title; 79 $feed['description'] = $this->feed_description; 80 $feed['url' ] = $this->feed_url; 81 $feed['items' ] = array(); 82 // Schleife ueber alle Inhalte des Root-Ordners 83 foreach( $folder->getObjectIds() as $id ) 84 { 85 if ( $id == $this->getObjectId() ) 86 continue; 87 $o = new BaseObject( $id ); 88 $o->load(); 89 if ( $o->isPage ) // Nur wenn Seite 90 { 91 $p = new Page( $id ); 92 $p->load(); 93 94 $item = array(); 95 $item['title' ] = $p->getNameForLanguage( $this->pageContext->languageId )->name; 96 $item['description'] = $p->getNameForLanguage( $this->pageContext->languageId )->description; 97 $item['date' ] = $p->lastchangeDate; 98 if ( empty($this->feed_url) ) 99 $item['link' ] = $this->pathToObject($id); 100 else 101 $item['link' ] = $this->feed_url; 102 103 $feed['items'][] = $item; 104 } 105 } 106 107 $feed = $this->atomFeed($feed); 108 109 $this->output( $feed ); 110 } 111 112 113 function atomFeed($input, $stylesheet='') 114 { 115 $input["encoding"] = (empty($input["encoding"] ))?"UTF-8":$input["encoding"]; 116 $input["language"] = (empty($input["language"] ))?"en-us":$input["language"]; 117 118 if ( empty($input['title' ])) $input['title' ] = ''; 119 if ( empty($input['description'])) $input['description'] = ''; 120 if ( empty($input['link' ])) $input['link' ] = ''; 121 $feed = '<?xml version="1.0" encoding="'.$input["encoding"].'"?>'; 122 $feed .= (!empty($stylesheet))?"\n".'<?xml-stylesheet type="text/xsl" href="'.$stylesheet.'"?>':""; 123 $feed .= <<<__RSS__ 124 125 <feed xmlns="http://www.w3.org/2005/Atom"> 126 <title>{$input["title"]}</title> 127 128 __RSS__; 129 foreach($input["items"] as $item) 130 { 131 if ( empty($item['title' ])) $item['title' ] = ''; 132 if ( empty($item['description'])) $item['description'] = ''; 133 $feed .= "\n<entry>\n<title>".$item["title"]."</title>"; 134 $feed .= "\n<summary><![CDATA[".$item["description"]."]]></summary>"; 135 $feed .= "\n<updated>".date('Y-m-d\TH:i:s\Z', $item["date"])."</updated>"; 136 $feed .= "\n<link href=\"".$item["link"]."\" />"; 137 $feed .= "\n</entry>\n"; 138 } 139 $feed .= "\n</feed>"; 140 return $feed; 141 } 142 }
Download modules/cms/macros/macro/Atom.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.