openrat-cms

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

TextPreviewAction.class.php (1444B)


      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 }