TableFromFile.class.php (2157B)
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\File; 19 20 21 /** 22 * Erstellt eine HTML-Tabelle aus einer CSV-Datei. 23 * 24 * @author Jan Dankert 25 */ 26 class TagCloud extends Macro 27 { 28 /** 29 * Beschreibung dieser Klasse 30 * @type String 31 */ 32 var $description = ''; 33 34 35 public $fileid = 0; 36 public $separator = ','; 37 public $firstlineheader = 1; 38 public $firstcolumnheader = 1; 39 public $ignorefirstline = 0; 40 public $header = 'A,B,C'; 41 public $encodeHtml = 1; 42 43 44 function execute() 45 { 46 $this->output('<table>'); 47 $file = new File( $this->fileid ); 48 $lines = explode("\n",$file->loadValue() ); 49 50 $firstline = true; 51 foreach( $lines as $line ) 52 { 53 if ( $firstline) 54 { 55 $firstline = false; 56 if ( $this->ignorefirstline) 57 continue; 58 elseif ( $this->firstlineheader ) 59 $lcelltag = 'th'; 60 else 61 $lcelltag = 'td'; 62 } 63 else 64 $lcelltag = 'td'; 65 66 $columns = explode($this->separator,$line); 67 68 $this->output('<tr>'); 69 $firstcolumn = true; 70 foreach( $columns as $column ) 71 { 72 if ($firstcolumn) 73 { 74 $firstcolumn = false; 75 if ( $this->firstcolumnheader ) 76 $celltag = 'th'; 77 else 78 $celltag = $lcelltag; 79 80 if ( $this->encodeHtml) $column = encodeHtml($column); 81 $this->output('<'.$celltag.'>'.$column.'</'.$celltag.'>'); 82 } 83 } 84 $this->output('</tr>'); 85 } 86 $this->output('</table>'); 87 } 88 89 }