File modules/cms/action/text/TextPreviewAction.class.php

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