openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

TableFromFile.class.php (2201B)


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