Album.class.php (2486B)
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\BaseObject; 19 use cms\model\File; 20 use cms\model\Folder; 21 use cms\model\Image; 22 23 24 /** 25 * Erzeugt eine Bilder-Liste. 26 * 27 * Die Ordner-Id kann als Parameter "folderid" übergeben werden. 28 * Falls nicht, wird der aktuelle Ordner, in dem sich die Seite 29 * befindet, benutzt. 30 * 31 * Es wird eine Definitionsliste mit der CSS-Klasse "album" erzeugt, damit 32 * bequem eine Auszeichnung per CSS erfolgen kann. 33 * 34 * Beispiel: 35 * <dl class="album"> 36 * <dt><img src="bild.jpg" width=".." .. /></dt> 37 * <dd>Beschreibung</dd> 38 * </dl> 39 * 40 * @author Jan Dankert 41 */ 42 class Album extends Macro 43 { 44 45 /** 46 * Bitte immer eine Beschreibung benutzen, dies ist fuer den Web-Developer hilfreich. 47 * @type String 48 */ 49 public $description = 'Creates an album.'; 50 51 public $folderid = 0; 52 53 public $withImages = true; 54 public $withFiles = false; 55 56 /** 57 */ 58 public function execute() 59 { 60 if ( intval($this->folderid)!=0 ) 61 $folderid = $this->folderid; 62 else 63 $folderid = $this->page->parentid; 64 65 $f = new Folder($folderid); 66 $files = []; 67 68 if ( $this->withImages ) 69 $files += $f->getObjectIdsByType(BaseObject::TYPEID_IMAGE); 70 71 if ( $this->withFiles ) 72 $files += $f->getObjectIdsByType(BaseObject::TYPEID_FILE); 73 74 $this->output('<dl class="album">'); 75 76 foreach( $files as $fileid ) 77 { 78 $file = new Image($fileid); 79 $file->load(); 80 81 if ( $file->isImage() ) 82 { 83 $file->getImageSize(); 84 $img = '<img src="'.$this->pathToObject($fileid).'" alt="'.$file->name.'" width="'.$file->width.'" height="'.$file->height.'" />'; 85 $this->output('<dt>'.$img.'</dt><dd>'.$file->desc.'</dd>'); 86 } 87 88 } 89 90 $this->output('</dl>'); 91 } 92 93 } 94 95 ?>