File modules/cms/action/script/ScriptPreviewAction.class.php

Last commit: Sun Jan 29 00:20:21 2023 +0100	Jan Dankert	New node type "Script".
1 <?php 2 namespace cms\action\script; 3 use cms\action\Method; 4 use cms\action\ScriptAction; 5 use cms\action\TextAction; 6 use cms\base\Configuration; 7 use cms\generator\FileContext; 8 use cms\generator\FileGenerator; 9 use cms\generator\Producer; 10 use cms\model\File; 11 12 13 class ScriptPreviewAction extends ScriptAction implements Method { 14 15 16 public function view() 17 { 18 $fileContext = new FileContext($this->script->objectid, Producer::SCHEME_PREVIEW ); 19 20 $generator = new FileGenerator( $fileContext); 21 22 if ( $this->request->getAlphanum('encoding') == 'base64') 23 { 24 $encodingFunction = function($value) { 25 return base64_encode($value); 26 }; 27 $this->setTemplateVar('encoding', 'base64'); 28 } 29 else { 30 $encodingFunction = function($value) { 31 return $value; 32 }; 33 $this->setTemplateVar('encoding', 'none'); 34 } 35 36 37 // Unterscheidung, ob PHP-Code in der Datei ausgefuehrt werden soll. 38 $publishConfig = Configuration::subset('publish'); 39 $phpActive = ( $publishConfig->get('enable_php_in_file_content')=='auto' && $this->file->getRealExtension()=='php') || 40 $publishConfig->get('enable_php_in_file_content' )===true; 41 42 if ( $phpActive ) { 43 44 // PHP-Code ausfuehren 45 ob_start(); 46 require( $generator->getCache()->load()->getFilename() ); 47 $this->setTemplateVar('text',$encodingFunction(ob_get_contents()) ); 48 ob_end_clean(); 49 } 50 else 51 $this->setTemplateVar('text',$encodingFunction( $generator->getCache()->get() ) ); 52 } 53 54 public function post() { 55 } 56 }
Download modules/cms/action/script/ScriptPreviewAction.class.php
History Sun, 29 Jan 2023 00:20:21 +0100 Jan Dankert New node type "Script".