openrat-cms

# OpenRat Content Management System
git clone http://git.code.weiherhei.de/openrat-cms.git
Log | Files | Refs

FilebrowserAction.class.php (6832B)


      1 <?php
      2 
      3 namespace cms\action;
      4 
      5 
      6 use Http;
      7 use Session;
      8 use \Html;
      9 
     10 // OpenRat Content Management System
     11 // Copyright (C) 2002-2012 Jan Dankert, cms@jandankert.de
     12 //
     13 // This program is free software; you can redistribute it and/or
     14 // modify it under the terms of the GNU General Public License
     15 // as published by the Free Software Foundation; either version 2
     16 // of the License, or (at your option) any later version.
     17 //
     18 // This program is distributed in the hope that it will be useful,
     19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
     20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     21 // GNU General Public License for more details.
     22 //
     23 // You should have received a copy of the GNU General Public License
     24 // along with this program; if not, write to the Free Software
     25 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
     26 
     27 
     28 /**
     29  * Action-Klasse zum Bearbeiten einer Datei
     30  * @author $Author$
     31  * @version $Revision$
     32  * @package openrat.actions
     33  *
     34  * @deprecated old ckeditor trash
     35  */
     36 class FilebrowserAction extends ObjectAction
     37 {
     38 	public $security = Action::SECURITY_USER;
     39 	
     40 	var $command;
     41 	var $resourceType;
     42 	
     43 	/**
     44 	 * Ordner
     45 	 *
     46 	 * @var String
     47 	 */
     48 	var $currentFolder;
     49 	
     50 	/**
     51 	 * Aktueller Ordner
     52 	 *
     53 	 * @var Object
     54 	 */
     55 	var $folder;
     56 	
     57 	/**
     58 	 * Konstruktor
     59 	 */
     60 	function __construct()
     61 	{
     62 		if	( $this->getRequestId() != 0  )
     63 		{
     64 			$fid = $this->getRequestId();
     65 		}
     66 		else
     67 		{
     68 			$project = Session::getProject();
     69 			$fid = $project->getRootObjectId();
     70 		}
     71 		
     72 		$this->folder = new Folder( $fid );
     73 		$this->folder->load();
     74 		
     75 		
     76 	}
     77 
     78 	
     79 	
     80 	/**
     81 	 * 
     82 	 */
     83 	function show()
     84 	{
     85         throw new \SecurityException('no subaction found');
     86 	}
     87 	
     88 
     89 	/**
     90 	 * Datei-Upload.
     91 	 *
     92 	 */
     93 	public function directuploadPost()
     94 	{
     95 		$upload = new Upload( $this->getRequestVar('name','abc') );
     96 		
     97 		if	( !$upload->isValid() )
     98 		{
     99 			echo 'Upload failed, reason: '.$upload->error; 
    100 		}
    101 		else
    102 		{
    103 			$file = new File();
    104 			$file->parentid  = $this->folder->objectid;
    105 			$file->name      = $upload->filename;
    106 			$file->filename  = $upload->filename;
    107 			$file->extension = $upload->extension;
    108 			$file->value     = $upload->value;
    109 			$file->add();
    110 			
    111 			$newId  = $file->objectid;
    112 			$newUrl = str_replace('&amp;','&',Html::url('file','show',$newId,array('oid'=>'__OID__'.$newId.'__')));
    113 			
    114 			echo '<script type="text/javascript">' ;
    115 			echo 'window.parent.CKEDITOR.tools.callFunction('.$this->getRequestVar('CKEditorFuncNum',OR_FILTER_NUMBER).",'".$newUrl."','');</script>";
    116 			echo '</script>' ;
    117 			echo 'OK' ;
    118 		}
    119 	
    120 	}
    121 
    122 	
    123 	public function browseView()
    124 	{
    125 		global $conf_php;
    126 		$funcNum = $this->getRequestVar('CKEditorFuncNum',OR_FILTER_NUMBER);
    127 
    128 		if   ( ! $this->folder->isRoot )
    129 			$this->setTemplateVar('up_url',Html::url('filebrowser','browse',$this->folder->parentid,array('CKEditorFuncNum'=>$funcNum)));
    130 
    131 		$user = Session::getUser();
    132 		$this->setTemplateVar('writable',$this->folder->hasRight(ACL_WRITE) );
    133 		$this->setTemplateVar('style',$user->style );
    134 		
    135 		$list = array();
    136 
    137 		// Schleife ueber alle Objekte in diesem Ordner
    138 		foreach( $this->folder->getObjects() as $o )
    139 		{
    140 			$id = $o->objectid;
    141 
    142 			if   ( $o->hasRight(ACL_READ) )
    143 			{
    144 				$list[$id]['name']     = Text::maxLaenge( 30,$o->name     );
    145 				$list[$id]['filename'] = Text::maxLaenge( 20,$o->filename );
    146 				$list[$id]['desc']     = Text::maxLaenge( 30,$o->desc     );
    147 				if	( $list[$id]['desc'] == '' )
    148 					$list[$id]['desc'] = lang('NO_DESCRIPTION_AVAILABLE');
    149 				$list[$id]['desc'] = $list[$id]['desc'].' - '.lang('IMAGE').' '.$id; 
    150 
    151 				$list[$id]['type'] = $o->getType();
    152 				
    153 				$list[$id]['icon' ] = $o->getType();
    154 				$list[$id]['class'] = $o->getType();
    155 				if	( $o->isFolder )
    156 					$list[$id]['url' ] = Html::url('filebrowser','browse',$id,array('CKEditorFuncNum'=>$funcNum) );
    157 				else
    158 					$list[$id]['url' ] = "javascript:window.top.opener.CKEDITOR.tools.callFunction($funcNum,'".Html::url('file','show',$id,array('oid'=>'__OID__'.$id.'__'))."','');window.top.close();window.top.opener.focus();";					
    159 				
    160 				
    161 				
    162 				if	( $o->getType() == 'file' )
    163 				{
    164 					$file = new File( $id );
    165 					$file->load();
    166 					$list[$id]['desc'] .= ' - '.intval($file->size/1000).'kB';
    167 
    168 					if	( $file->isImage() )
    169 					{
    170 						$list[$id]['icon' ] = 'image';
    171 						$list[$id]['class'] = 'image';
    172 						//$list[$id]['url' ] = Html::url('file','show',$id) nur sinnvoll bei Lightbox-Anzeige
    173 					}
    174 //					if	( substr($file->mimeType(),0,5) == 'text/' )
    175 //						$list[$id]['icon'] = 'text';
    176 				}
    177 
    178 				$list[$id]['date'] = $o->lastchangeDate;
    179 				$list[$id]['user'] = $o->lastchangeUser;
    180 			}
    181 		}
    182 
    183 		$this->setTemplateVar('object'      ,$list            );
    184 		$this->setTemplateVar('CKEditorFuncNum',$funcNum );
    185 		$this->setTemplateVar('token',token() );
    186 		$this->setTemplateVar('id',$this->folder->objectid );
    187 	}
    188 
    189 
    190 	public function addfolderPost()
    191 	{
    192 		
    193 		$filename = $this->getRequestVar('name');
    194 		
    195 		if ( empty($filename) )
    196 		{
    197 			$this->addNotice('folder',$this->name,'ADDED',OR_NOTICE_ERROR);
    198 		}
    199 		elseif( !$this->folder->hasRight(ACL_CREATE_FOLDER) )
    200 		{
    201 			$this->addNotice('folder',$this->name,'ERROR',OR_NOTICE_ERROR);
    202 		}
    203 		elseif( $this->folder->hasFilename( $filename ) )
    204 		{
    205 			$this->addNotice('folder',$this->name,'ERROR',OR_NOTICE_ERROR);
    206 			
    207 		}
    208 		else
    209 		{
    210 			$newFolder = new Folder();
    211 			$newFolder->parentid = $this->folder->objectid;
    212 			$newFolder->filename = $filename;
    213 			$newFolder->name     = $filename;
    214 			$newFolder->add();
    215 			
    216 			$this->addNotice('folder',$this->folder->name,'ADDED',OR_NOTICE_OK);
    217 		}
    218 	}
    219 	
    220 	
    221 	
    222 	public function uploadPost()
    223 	{
    224 		if	( $this->hasRequestVar('name') )
    225 			$name = $this->getRequestVar('name','abc');
    226 		else
    227 			$name = 'file';
    228 			
    229 		$upload = new Upload($name);
    230 		
    231 		if	( !$upload->isValid() )
    232 		{
    233 			$this->addValidationError('file','COMMON_VALIDATION_ERROR',array(),$upload->error);
    234 			return;
    235 		}
    236 		// Pr�fen der maximal erlaubten Dateigr��e.
    237 		elseif	( $upload->size < 0 )
    238 		{
    239 			// Maximale Dateigr��e ist �berschritten
    240 			$this->addValidationError('file','MAX_FILE_SIZE_EXCEEDED');
    241 			return;
    242 		}
    243 		elseif( $upload->size > 0 )
    244 		{
    245 			$file   = new File();
    246 			$file->desc      = '';
    247 			$file->filename  = $upload->filename;
    248 			$file->name      = $upload->filename;
    249 			$file->extension = $upload->extension;		
    250 			$file->size      = $upload->size;
    251 			$file->parentid  = $this->folder->objectid;
    252 	
    253 			$file->value     = $upload->value;
    254 	
    255 			$file->add(); // Datei hinzufuegen
    256 			$this->folder->setTimestamp();
    257 			$this->addNotice('file',$file->name,'ADDED','ok');
    258 		}
    259 	}
    260 }
    261 
    262 ?>