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

Last commit: Sat Sep 26 03:03:47 2020 +0200	Jan Dankert	Refactoring: less global functions.
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\PageContext; 20 use cms\generator\ValueContext; 21 use cms\generator\ValueGenerator; 22 use cms\model\BaseObject; 23 use cms\model\Folder; 24 use cms\model\Link; 25 use cms\model\Page; 26 use cms\model\Project; 27 use util\Macro; 28 use util\Text; 29 30 31 /** 32 * Erstellen einer Teaser-Liste. 33 * 34 * @author Jan Dankert 35 */ 36 class LastChanges extends Macro 37 { 38 var $title_html_tag = 'h3'; 39 var $css_class = 'macro-lastchanges'; 40 var $teaserElementId = ''; 41 var $teaserMaxLength = 100; 42 var $plaintext = 'true'; 43 var $linktitle = 'true'; 44 var $linktext = 'true'; 45 var $timeelementid = 0; 46 var $folderid = 0; 47 var $showPages = true; 48 var $showLinks = false; 49 var $includeTemplateIds = array(); 50 var $excludeTemplateIds = array(); 51 var $limit = -1; 52 53 /** 54 * Bitte immer eine Beschreibung benutzen, dies ist fuer den Web-Developer hilfreich. 55 * @type String 56 */ 57 var $description = 'Creates a teaser list of pages in a folder'; 58 59 // 60 function execute() 61 { 62 if ( $this->folderid === 'self' ) 63 { 64 $page = $this->getPage(); 65 $page->load(); 66 $folderid = $page->parentid; 67 $f = new Folder( $folderid ); 68 $changes = $f->getLastChanges(); 69 } 70 elseif ( $this->folderid > 0 ) 71 { 72 $f = new Folder( $this->folderid ); 73 $changes = $f->getLastChanges(); 74 } 75 else 76 { 77 $project = new Project( $this->page->projectid ); 78 $changes = $project->getLastChanges(); 79 } 80 81 82 $count = 0; 83 84 foreach( $changes as $o ) 85 { 86 if ($o['objectid'] == $this->getObjectId() ) 87 continue; 88 89 if ( ($o['typeid']==BaseObject::TYPEID_PAGE && self::isTrue($this->showPages)) || 90 ($o['typeid']==BaseObject::TYPEID_LINK && self::isTrue($this->showLinks)) ) // Nur wenn gewünschter Typ 91 { 92 if ( $o['typeid']==BaseObject::TYPEID_LINK ) { 93 $l = new Link( $o['objectid'] ); 94 $l->load(); 95 96 $p = new Page( $l->linkedObjectId ); 97 } 98 elseif ( $o['typeid']==BaseObject::TYPEID_PAGE ) 99 { 100 $p = new Page( $o['objectid'] ); 101 } 102 else 103 continue; 104 105 $p->load(); 106 107 // Template zulässig? 108 if ( !empty($this->includeTemplateIds) ) 109 if ( !in_array($p->templateid,$this->includeTemplateIds)) 110 continue; 111 112 // Template zulässig? 113 if ( !empty($this->excludeTemplateIds) ) 114 if ( in_array($p->templateid,$this->excludeTemplateIds)) 115 continue; 116 117 $count++; 118 if ( $this->limit >= 0 && $count > $this->limit) 119 break; // Maximale Anzahl erreicht. 120 121 $desc = $p->getNameForLanguage( $this->pageContext->languageId )->description; 122 123 $pageContext = clone $this->pageContext; 124 $pageContext->objectId = $o['objectid']; 125 126 if ( !empty($this->teaserElementId) ) 127 { 128 $valueContext = new ValueContext( $pageContext ); 129 $valueContext->elementid = $this->teaserElementId; 130 131 $value = new ValueGenerator($valueContext); 132 133 134 $desc = $value->getCache()->get(); 135 136 137 if ( self::isTrue($this->plaintext) ) 138 { 139 $desc = strip_tags($desc); 140 // Und nur wenn die Tags raus sind duerfen wir nun den Text kuerzen. 141 // (sonst drohen offene Tags) 142 if ( is_numeric($this->teaserMaxLength) && $this->teaserMaxLength > 0 ) 143 $desc = Text::maxLength($desc,$this->teaserMaxLength); 144 } 145 } 146 147 $time = ''; 148 if ( !empty($this->timeelementid) ) 149 { 150 $valueContext = new ValueContext( $pageContext ); 151 $valueContext->elementid = $this->timeelementid; 152 153 $value = new ValueGenerator($valueContext); 154 155 $time = $value->getCache()->get(); 156 } 157 158 $this->output('<div class="'.$this->css_class.'">'); 159 160 if ( self::isTrue($this->linktitle) ) 161 { 162 $url = $this->pathToObject($o['objectid']); 163 $this->output( '<a href="'.$url.'"><div>' ); 164 } 165 166 $this->output('<h6>'.$time.'</h6>'); 167 168 169 $this->output( '<h3>'); 170 $this->output( $p->getNameForLanguage( $pageContext->languageId )->name ); 171 $this->output( '</h3>' ); 172 173 $this->output( '<p>' ); 174 $this->output( $desc ); 175 $this->output( '</p>' ); 176 177 if ( self::isTrue($this->linktitle) ) 178 { 179 $this->output( '</div></a>' ); 180 } 181 182 $this->output( '</div>' ); 183 } 184 } 185 } 186 187 public static function isTrue( $value ) { 188 return filter_var( $value,FILTER_VALIDATE_BOOLEAN); 189 } 190 }
Download modules/cms/macros/macro/LastChanges.class.php
History 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.