File modules/cms/action/page/PageShowAction.class.php
Last commit: Sat Jan 28 19:10:47 2023 +0100 Jan Dankert New: Templates may be rendered as Mustache, Script and Script template.
1 <?php 2 namespace cms\action\page; 3 use cms\action\Method; 4 use cms\action\PageAction; 5 use cms\base\Configuration; 6 use cms\generator\PageGenerator; 7 use cms\generator\Producer; 8 use cms\model\Language; 9 use cms\model\Template; 10 use configuration\Config; 11 use logger\Logger; 12 use util\exception\DatabaseException; 13 use util\exception\GeneratorException; 14 use util\Text; 15 16 class PageShowAction extends PageAction implements Method { 17 public function view() { 18 // We must overwrite the CSP here. 19 // The output is only shown in an iframe, so there is no security impact to the CMS. 20 // But if the template is using inline JS or CSS, we would break this with a CSP-header. 21 $pageSettingsConfig = new Config( $this->page->getTotalSettings() ); 22 $this->setContentSecurityPolicy($pageSettingsConfig->get('content-security-policy',[]) ); 23 24 $this->page->load(); 25 26 27 Logger::debug("Preview page: ".$this->page->__toString() ); 28 29 $pageContext = $this->createPageContext( Producer::SCHEME_PREVIEW ); 30 31 // HTTP-Header mit Sprachinformation setzen. 32 $language = new Language( $pageContext->languageId); 33 $language->load(); 34 $this->addHeader('Content-Language',$language->isoCode); 35 36 $generator = new PageGenerator( $pageContext ); 37 38 $this->setContentType( $generator->getMimeType() ); 39 40 41 $template = new Template( $this->page->templateid ); 42 $templateModel = $template->loadTemplateModelFor( $pageContext->modelId ); 43 $templateModel->load(); 44 45 try { 46 // Executing PHP in Pages. 47 // DEPRECATED: Use the script language! 48 $enablePHP = Configuration::subset('publish')->get('enable_php_in_page_content'); 49 if ( ( $enablePHP=='auto' && $templateModel->extension == 'php') || 50 $enablePHP===true ) 51 { 52 ob_start(); 53 require( $generator->getCache()->load()->getFilename() ); 54 $this->setTemplateVar('value',ob_get_contents() ); 55 ob_end_clean(); 56 } 57 else 58 $this->setTemplateVar('value',$generator->getCache()->get()); 59 } catch (GeneratorException $e) { 60 $this->setContentType( 'text/html' ); 61 $this->setTemplateVar('value',Text::getUserFriendlyHTMLErrorMessage($e ) ); 62 } 63 } 64 65 public function post() { 66 } 67 }
Downloadmodules/cms/action/page/PageShowAction.class.php
History Sat, 28 Jan 2023 19:10:47 +0100 Jan Dankert New: Templates may be rendered as Mustache, Script and Script template. 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. Sun, 13 Feb 2022 19:39:49 +0100 dankert Refactoring: Special output type "preview" for previewing pages and files. Sun, 5 Dec 2021 22:26:39 +0100 dankert Fixed a type in template source of new projects. Sun, 5 Dec 2021 20:33:24 +0100 dankert Cleanup: Removed unusable properties from class 'Value' and 'BaseObject'. Thu, 4 Mar 2021 02:24:45 +0100 Jan Dankert New: The calculation of the mime types should be done in the generators. Tue, 17 Nov 2020 23:51:00 +0100 Jan Dankert Refactoring: Every Actionmethod has now its own class.