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