File modules/cms/action/file/FileShowAction.class.php

Last commit: Sat Mar 19 00:09:47 2022 +0100	dankert	Refactoring: Outputs are setting their content-type themself.
1 <?php 2 namespace cms\action\file; 3 use cms\action\FileAction; 4 use cms\action\Method; 5 use cms\base\Configuration; 6 use cms\generator\FileContext; 7 use cms\generator\FileGenerator; 8 use cms\generator\FileHistoryContext; 9 use cms\generator\FileHistoryGenerator; 10 use cms\generator\Producer; 11 use cms\model\File; 12 use cms\model\Value; 13 use util\exception\SecurityException; 14 15 16 class FileShowAction extends FileAction implements Method { 17 18 public function view() { 19 20 $valueId = $this->request->getNumber('valueid'); 21 22 if ( $valueId ) { 23 $value = new Value(); 24 $value->loadWithId( $valueId ); 25 if ( $value->contentid != $this->file->contentid ) 26 throw new SecurityException('Content-Id does not match'); 27 28 $fileHistoryContext = new FileHistoryContext($this->file->objectid, $valueId ); 29 $generator = new FileHistoryGenerator( $fileHistoryContext ); 30 } else { 31 $fileContext = new FileContext($this->file->objectid, Producer::SCHEME_PREVIEW ); 32 $generator = new FileGenerator( $fileContext ); 33 } 34 35 36 $this->lastModified( $this->file->lastchangeDate ); 37 38 if ( $this->file->extension == 'gz' ) 39 { 40 $pos = strrpos($this->file->filename,'.'); 41 if ( $pos === false ) 42 $ext = ''; 43 else 44 $ext = substr($this->file->filename,$pos+1); 45 46 $ext = strtolower($ext); 47 48 $mime_type = File::$MIME_TYPES[$ext]; 49 50 $this->setContentType( $mime_type ); 51 $this->addHeader('Content-Encoding','gzip' ); 52 } 53 else 54 { 55 // Angabe Content-Type 56 $this->setContentType($generator->getMimeType() ); 57 } 58 59 // Image should be displayed inline. 60 // Filename is used if the user agent is saving the file. 61 $this->addHeader('Content-Disposition' ,'inline; filename='.$this->file->filename() ); 62 $this->addHeader('Content-Transfer-Encoding','binary' ); 63 $this->addHeader('Content-Description' ,$this->file->filename() ); 64 65 66 // Groesse des Bildes in Bytes 67 // Der Browser hat so die Moeglichkeit, einen Fortschrittsbalken zu zeigen 68 $this->addHeader('Content-Length',$this->file->size ); 69 70 71 if ( $this->request->getAlphanum('encoding') == 'base64') 72 { 73 $encodingFunction = function($value) { 74 return base64_encode($value); 75 }; 76 $this->setTemplateVar('encoding', 'base64'); 77 } 78 else { 79 $encodingFunction = function($value) { 80 return $value; 81 }; 82 $this->setTemplateVar('encoding', 'none'); 83 } 84 85 86 // Unterscheidung, ob PHP-Code in der Datei ausgefuehrt werden soll. 87 $publishConfig = Configuration::subset('publish'); 88 $phpActive = ( $publishConfig->get('enable_php_in_file_content')=='auto' && $this->file->getRealExtension()=='php') || 89 $publishConfig->get('enable_php_in_file_content' )===true; 90 91 if ( $phpActive ) { 92 93 // PHP-Code ausfuehren 94 ob_start(); 95 require( $generator->getCache()->load()->getFilename() ); 96 $this->setTemplateVar('value',$encodingFunction(ob_get_contents()) ); 97 ob_end_clean(); 98 } 99 else 100 $this->setTemplateVar('value',$encodingFunction( $generator->getCache()->get() ) ); 101 // Maybe we want some gzip-encoding? 102 } 103 104 105 public function post() { 106 } 107 }
Download modules/cms/action/file/FileShowAction.class.php
History Sat, 19 Mar 2022 00:09:47 +0100 dankert Refactoring: Outputs are setting their content-type themself. Sun, 13 Feb 2022 23:35:26 +0100 dankert Refactoring: New class "Response" which stores all output information. Mon, 6 Dec 2021 01:00:00 +0100 dankert New: Show a version from file history; New: Text history. Sun, 5 Dec 2021 20:33:24 +0100 dankert Cleanup: Removed unusable properties from class 'Value' and 'BaseObject'. Thu, 4 Mar 2021 03:39:25 +0100 Jan Dankert New: Separate edit action for images and texts. Fri, 26 Feb 2021 01:06:01 +0100 Jan Dankert Refactoring accessing the request parameter values. Tue, 17 Nov 2020 23:51:00 +0100 Jan Dankert Refactoring: Every Actionmethod has now its own class.