commit 3f290ef0c26762b1a6d66d7747843ec23e15d45e
parent 7940dcbbc74b6194efa9680775326e7b82a3c628
Author: Jan Dankert <develop@jandankert.de>
Date: Thu, 7 Nov 2019 00:57:48 +0100
No direct outputs any more. All UI output is done through a template file. From this point is it easier for the API design.
Diffstat:
8 files changed, 86 insertions(+), 71 deletions(-)
diff --git a/modules/cms-core/action/FileAction.class.php b/modules/cms-core/action/FileAction.class.php
@@ -118,7 +118,7 @@ class FileAction extends ObjectAction
$url = Html::url($this->file->getType(),'show',$this->file->objectid,array('target'=>'none') );
$this->setTemplateVar('preview_url',$url );
}
-
+
/**
* Anzeigen des Inhaltes, der Inhalt wird samt Header direkt
@@ -128,26 +128,26 @@ class FileAction extends ObjectAction
{
$this->file->publisher = new PublishPreview();
$this->lastModified( $this->file->lastchangeDate );
-
+
if ( $this->file->extension == 'gz' )
{
global $conf;
$mime_types = $conf['mime-types'];
-
+
$pos = strrpos($this->file->filename,'.');
if ( $pos === false )
$ext = '';
else
$ext = substr($this->file->filename,$pos+1);
-
+
$ext = strtolower($ext);
-
+
if ( !empty($mime_types[$ext]) )
$mime_type = $mime_types[$ext];
else
// Wenn kein Mime-Type gefunden, dann Standardwert setzen
$mime_type = OR_FILE_DEFAULT_MIMETYPE;
-
+
header('Content-Type: '.$mime_type );
header('Content-Encoding: gzip' );
}
@@ -156,40 +156,54 @@ class FileAction extends ObjectAction
// Angabe Content-Type
header('Content-Type: '.$this->file->mimeType() );
}
-
+
header('X-File-Id: ' .$this->file->fileid );
header('X-Id: ' .$this->file->id );
-
+
// Angabe Content-Disposition
// - Bild soll "inline" gezeigt werden
// - Dateiname wird benutzt, wenn der Browser das Bild speichern moechte
header('Content-Disposition: inline; filename='.$this->file->filename() );
header('Content-Transfer-Encoding: binary' );
header('Content-Description: '.$this->file->filename() );
-
+
$this->file->write(); // Bild aus Datenbank laden
-
+
// Groesse des Bildes in Bytes
// Der Browser hat so die Moeglichkeit, einen Fortschrittsbalken zu zeigen
header('Content-Length: '.filesize($this->file->getCache()->getFilename()) );
-
- if ( in_array( getenv('HTTP_ACCEPT'),array('application/php-array','application/php-serialized','application/json','application/xml')))
+
+
+ if ( $this->request->getRequestVar('encoding') == 'base64')
{
+ $encodingFunction = function($value) {
+ return base64_encode($value);
+ };
$this->setTemplateVar('encoding', 'base64');
- $this->setTemplateVar('value' , base64_encode($this->file->getCache()->getFilename()) );
}
+ else {
+ $encodingFunction = function($value) {
+ return $value;
+ };
+ $this->setTemplateVar('encoding', 'none');
+ }
+
+
// Unterscheidung, ob PHP-Code in der Datei ausgefuehrt werden soll.
- elseif ( ( config('publish','enable_php_in_file_content')=='auto' && $this->file->getRealExtension()=='php') ||
- config('publish','enable_php_in_file_content')===true )
- // PHP-Code ausfuehren
- require( $this->file->getCache()->getFilename() );
- else
- // PHP-Code nicht ausfuehren, Datei direkt auf die Standardausgabe schreiben
- readfile( $this->file->getCache()->getFilename() );
+ $phpActive = ( config('publish','enable_php_in_file_content')=='auto' && $this->file->getRealExtension()=='php') ||
+ config('publish','enable_php_in_file_content')===true;
- // Maybe we want some gzip-encoding?
+ if ( $phpActive ) {
- exit;
+ // PHP-Code ausfuehren
+ ob_start();
+ require( $this->file->getCache()->getFilename() );
+ $this->setTemplateVar('value',$encodingFunction(ob_get_contents()) );
+ ob_end_clean();
+ }
+ else
+ $this->setTemplateVar('value',$encodingFunction(file_get_contents( $this->file->getCache()->getFilename()) ) );
+ // Maybe we want some gzip-encoding?
}
diff --git a/modules/cms-core/action/PageAction.class.php b/modules/cms-core/action/PageAction.class.php
@@ -667,14 +667,17 @@ class PageAction extends ObjectAction
Logger::debug("Preview page: ".$this->page->__toString() );
- // Wenn
+ // Executing PHP in Pages.
if ( ( config('publish','enable_php_in_page_content')=='auto' && $this->page->template->extension == 'php') ||
config('publish','enable_php_in_page_content')===true )
- require( $this->page->getCache()->getFilename() );
+ {
+ ob_start();
+ require( $this->page->getCache()->getFilename() );
+ $this->setTemplateVar('output',ob_get_contents() );
+ ob_end_clean();
+ }
else
- readfile( $this->page->getCache()->getFilename() );
-
- exit();
+ $this->setTemplateVar('output',file_get_contents( $this->page->getCache()->getFilename() ) );
}
diff --git a/modules/cms-ui/themes/default/html/views/file/show.php b/modules/cms-ui/themes/default/html/views/file/show.php
@@ -1,25 +1 @@
-<?php if (!defined('OR_TITLE')) die('Forbidden'); ?>
-
-
-
- <tr>
- <td colspan="2">
- <iframe src="<?php echo $preview_url ?>"></iframe>
-
- <a class="action" target="_self" data-action="file" data-method="edit" data-id="<?php echo OR_ID ?>" data-extra="[]" href="./#/file/">
- <img src="./modules/cms-ui/themes/default/images/icon/icon/edit.png" />
-
- <span><?php echo nl2br(encodeHtml(htmlentities(lang(''.'menu_file_edit'.'')))); ?></span>
-
- </a>
- <a class="action" target="_self" data-action="file" data-method="editvalue" data-id="<?php echo OR_ID ?>" data-extra="[]" href="./#/file/">
- <img src="./modules/cms-ui/themes/default/images/icon/icon/editvalue.png" />
-
- <span><?php echo nl2br(encodeHtml(htmlentities(lang(''.'menu_file_editvalue'.'')))); ?></span>
-
- </a>
- </td>
- </tr>
-
-
- -
\ No newline at end of file
+<?php if (!defined('OR_TITLE')) die('Forbidden'); ?><?php echo $value; ?>+
\ No newline at end of file
diff --git a/modules/cms-ui/themes/default/html/views/file/show.tpl.src.xml b/modules/cms-ui/themes/default/html/views/file/show.tpl.src.xml
@@ -1,3 +1,4 @@
-<output xmlns="http://www.openrat.de/template"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.openrat.de/template ../../../../../../template-engine/components/template.xsd"><dummy><window icon="folder"><row><column colspan="2"><insert url="var:preview_url"></insert><link class="action" action="file" subaction="edit"><image file="icon/edit"></image><text key="menu_file_edit"></text></link><link class="action" action="file" subaction="editvalue"><image file="icon/editvalue"></image><text key="menu_file_editvalue"></text></link></column></row></window></dummy></output>-
\ No newline at end of file
+<text xmlns="http://www.openrat.de/template"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.openrat.de/template ../../../../../../template-engine/components/template.xsd"
+ var="value" escape="false" type="none" newline="false"></text>+
\ No newline at end of file
diff --git a/modules/cms-ui/themes/default/html/views/page/show.php b/modules/cms-ui/themes/default/html/views/page/show.php
@@ -0,0 +1 @@
+<?php if (!defined('OR_TITLE')) die('Forbidden'); ?><?php echo $output; ?>+
\ No newline at end of file
diff --git a/modules/cms-ui/themes/default/html/views/page/show.tpl.src.xml b/modules/cms-ui/themes/default/html/views/page/show.tpl.src.xml
@@ -0,0 +1,4 @@
+<text xmlns="http://www.openrat.de/template"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.openrat.de/template ../../../../../../template-engine/components/template.xsd"
+ var="output" escape="false" type="none" newline="false"></text>+
\ No newline at end of file
diff --git a/modules/template-engine/components/html/text/Text.class.php b/modules/template-engine/components/html/text/Text.class.php
@@ -18,6 +18,7 @@ class TextComponent extends HtmlComponent
public $accesskey;
public $cut = 'both';
public $label;
+ public $newline = true;
public function begin()
{
@@ -29,6 +30,9 @@ class TextComponent extends HtmlComponent
switch( $this->type )
{
+ case 'none':
+ $tag = '';
+ break;
case 'emphatic':
$tag = 'em';
break;
@@ -56,21 +60,27 @@ class TextComponent extends HtmlComponent
default:
$tag = 'span';
}
-
- echo '<'.$tag;
-
- if ( !empty($this->class))
- echo ' class="'.$this->htmlvalue($this->class).'"';
-
- if ( !empty($this->title))
- echo ' title="'.$this->htmlvalue($this->title).'"';
-
- echo '><?php ';
-
+
+ if ( $tag )
+ {
+
+ echo '<'.$tag;
+
+ if ( !empty($this->class))
+ echo ' class="'.$this->htmlvalue($this->class).'"';
+
+ if ( !empty($this->title))
+ echo ' title="'.$this->htmlvalue($this->title).'"';
+
+ echo '>';
+ }
+ echo '<?php ';
+
$functions = array(); // Funktionen, durch die der Text gefiltert wird.
-
- $functions[] = 'nl2br(@)';
+
+ if ( $this->newline)
+ $functions[] = 'nl2br(@)';
if ( $this->escape )
@@ -119,7 +129,10 @@ class TextComponent extends HtmlComponent
}
echo "echo $value;";
- echo ' ?></'.$tag.'>'; // Tag schliessen.
+ echo ' ?>';
+
+ if ( $tag )
+ echo '</'.$tag.'>'; // Tag schliessen.
if ( $this->label )
echo '</span></label>';
diff --git a/modules/template-engine/components/template.xsd b/modules/template-engine/components/template.xsd
@@ -109,6 +109,7 @@
<xsd:attribute name="accesskey" type="xsd:string"/>
<xsd:attribute name="cut" type="xsd:string"/>
<xsd:attribute name="label" type="xsd:string"/>
+ <xsd:attribute name="newline" type="xsd:boolean"/>
<xsd:attribute name="class" type="xsd:string"/>
<xsd:attribute name="request" type="xsd:string"/>
</xsd:complexType>