File modules/cms/macros/macro/TeaserList.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 // OpenRat Content Management System 4 // Copyright (C) 2002-2012 Jan Dankert, cms@jandankert.de 5 // 6 // This program is free software; you can redistribute it and/or 7 // modify it under the terms of the GNU General Public License 8 // as published by the Free Software Foundation; either version 2 9 // of the License, or (at your option) any later version. 10 // 11 // This program is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU General Public License for more details. 15 // 16 // You should have received a copy of the GNU General Public License 17 // along with this program; if not, write to the Free Software 18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 use cms\generator\ValueContext; 20 use cms\generator\ValueGenerator; 21 use cms\model\Folder; 22 use cms\model\Page; 23 use util\Macro; 24 use util\Text; 25 26 27 /** 28 * Erstellen einer Teaser-Liste. 29 * 30 * @author Jan Dankert 31 */ 32 class TeaserList extends Macro 33 { 34 var $folderid = 0; 35 var $title_html_tag = 'h2'; 36 var $time_html_tag = 'h6'; 37 var $title_css_class = 'teaser'; 38 var $description_css_class = 'teaser'; 39 var $link_css_class = 'teaser'; 40 var $teaserElementId = ''; 41 var $teaserMaxLength = 100; 42 var $plaintext = 'true'; 43 var $linktitle = 'true'; 44 var $linktext = 'true'; 45 var $timeelementid = 0; 46 47 /** 48 * Bitte immer eine Beschreibung benutzen, dies ist fuer den Web-Developer hilfreich. 49 * @type String 50 */ 51 var $description = 'Creates a teaser list of pages in a folder'; 52 53 function execute() 54 { 55 $feed = array(); 56 57 // Lesen des Root-Ordners 58 if ( intval($this->folderid) == 0 ) 59 $folder = new Folder( $this->getRootObjectId() ); 60 else 61 $folder = new Folder( intval($this->folderid) ); 62 63 $folder->load(); 64 65 // Schleife ueber alle Inhalte des Root-Ordners 66 foreach( $folder->getObjects() as $o ) 67 { 68 if ( $o->isPage ) // Nur wenn Ordner 69 { 70 71 72 $p = new Page( $o->objectid ); 73 $p->load(); 74 75 $desc = $p->getNameForLanguage( $this->pageContext->languageId )->description; 76 77 if ( !empty($this->teaserElementId) ) 78 { 79 $valueContext = new ValueContext( $this->pageContext ); 80 $valueContext->elementid = $this->teaserElementId; 81 82 $value = new ValueGenerator($valueContext); 83 84 85 $desc = $value->getCache()->get(); 86 87 if ( filter_var($this->plaintext,FILTER_VALIDATE_BOOLEAN) ) 88 { 89 $desc = strip_tags($desc); 90 // Und nur wenn die Tags raus sind duerfen wir nun den Text kuerzen. 91 // (sonst drohen offene Tags) 92 if ( is_numeric($this->teaserMaxLength) && $this->teaserMaxLength > 0 ) 93 $desc = Text::maxLength($desc,$this->teaserMaxLength); 94 } 95 } 96 97 $time = ''; 98 if ( !empty($this->timeelementid) ) 99 { 100 $valueContext = new ValueContext( $this->pageContext ); 101 $valueContext->elementid = $this->timeelementid; 102 103 $value = new ValueGenerator($valueContext); 104 105 $time = $value->getCache()->get(); 106 } 107 108 $this->output('<'.$this->time_html_tag.'>'.$time.'</'.$this->time_html_tag.'>'); 109 110 $url = $this->pathToObject($o->objectid); 111 112 $this->output( '<'.$this->title_html_tag.' class="'.$this->title_css_class.'">'); 113 if ( filter_var($this->linktitle,FILTER_VALIDATE_BOOLEAN)) 114 $this->output( '<a href="'.$url.'">'.$p->getNameForLanguage( $this->pageContext->languageId )->name.'</a>' ); 115 else 116 $this->output( $p->getNameForLanguage( $this->pageContext->languageId )->name ); 117 $this->output( '</'.$this->title_html_tag.'>' ); 118 119 $this->output( '<p class="'.$this->description_css_class.'">' ); 120 if ( filter_var($this->linktext,FILTER_VALIDATE_BOOLEAN) ) 121 $this->output( '<a href="'.$this->pathToObject($o->objectid).'">'.$desc.'</a>' ); 122 else 123 $this->output( $desc ); 124 125 $this->output( '</p>' ); 126 } 127 } 128 } 129 }
Download modules/cms/macros/macro/TeaserList.class.php
History Sun, 5 Dec 2021 20:33:24 +0100 dankert Cleanup: Removed unusable properties from class 'Value' and 'BaseObject'. Sat, 26 Sep 2020 03:03:47 +0200 Jan Dankert Refactoring: less global functions. Mon, 21 Sep 2020 22:48:59 +0200 Jan Dankert Complexe refactoring: Moving all generation logic from the model (Value,Page,File) to generators classes. 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.