commit 5d76c6ccb95e1ba89e2b5cd20e046b5b02bebc68
parent ae8be489ba1b1bf789c2edb31452df68e81f4b12
Author: Jan Dankert <develop@jandankert.de>
Date: Wed, 1 May 2019 00:33:53 +0200
Template-Quellcode für jede Sprache einzeln bearbeiten.
Diffstat:
5 files changed, 137 insertions(+), 155 deletions(-)
diff --git a/modules/cms-core/action/TemplateAction.class.php b/modules/cms-core/action/TemplateAction.class.php
@@ -79,41 +79,33 @@ class TemplateAction extends Action
/**
- * Speichern des Quelltextes.
+ * Save the new template source into the database.
*/
public function srcPost()
{
- $project = new Project( $this->template->projectid );
- $models = $project->getModels();
+ $modelId = $this->getRequestId('modelid');
- foreach( $models as $modelId => $modelName ) {
+ $templatemodel = new TemplateModel($this->template->templateid, $modelId);
+ $templatemodel->load();
- if ($this->hasRequestVar('source_'.$modelName))
- {
- $templatemodel = new TemplateModel($this->template->templateid, $modelId);
- $templatemodel->load();
-
- // Nur wenn das Eingabefeld im Request vorhanden ist, speichern wir etwas ab.
- $text = $this->getRequestVar('source_'.$modelName, 'raw');
-
- foreach ($this->template->getElementNames() as $elid => $elname) {
- $text = str_replace('{{' . $elname . '}}', '{{' . $elid . '}}', $text);
- $text = str_replace('{{->' . $elname . '}}', '{{->' . $elid . '}}', $text);
- $text = str_replace('{{' . lang('TEMPLATE_SRC_IFEMPTY') . ':' . $elname . ':' . lang('TEMPLATE_SRC_BEGIN') . '}}', '{{IFEMPTY:' . $elid . ':BEGIN}}', $text);
- $text = str_replace('{{' . lang('TEMPLATE_SRC_IFEMPTY') . ':' . $elname . ':' . lang('TEMPLATE_SRC_END') . '}}', '{{IFEMPTY:' . $elid . ':END}}', $text);
- $text = str_replace('{{' . lang('TEMPLATE_SRC_IFNOTEMPTY') . ':' . $elname . ':' . lang('TEMPLATE_SRC_BEGIN') . '}}', '{{IFNOTEMPTY:' . $elid . ':BEGIN}}', $text);
- $text = str_replace('{{' . lang('TEMPLATE_SRC_IFNOTEMPTY') . ':' . $elname . ':' . lang('TEMPLATE_SRC_END') . '}}', '{{IFNOTEMPTY:' . $elid . ':END}}', $text);
- }
-
- $templatemodel->src = $text;
-
- if ( !$templatemodel->isPersistent() )
- $templatemodel->add();
- else
- $templatemodel->save();
- }
+ $newSource = $this->request->getRequestVar('source',OR_FILTER_RAW);
+
+ foreach ($this->template->getElementNames() as $elid => $elname) {
+ $newSource = str_replace('{{' . $elname . '}}', '{{' . $elid . '}}', $newSource);
+ $newSource = str_replace('{{->' . $elname . '}}', '{{->' . $elid . '}}', $newSource);
+ $newSource = str_replace('{{' . lang('TEMPLATE_SRC_IFEMPTY') . ':' . $elname . ':' . lang('TEMPLATE_SRC_BEGIN') . '}}', '{{IFEMPTY:' . $elid . ':BEGIN}}', $newSource);
+ $newSource = str_replace('{{' . lang('TEMPLATE_SRC_IFEMPTY') . ':' . $elname . ':' . lang('TEMPLATE_SRC_END') . '}}', '{{IFEMPTY:' . $elid . ':END}}', $newSource);
+ $newSource = str_replace('{{' . lang('TEMPLATE_SRC_IFNOTEMPTY') . ':' . $elname . ':' . lang('TEMPLATE_SRC_BEGIN') . '}}', '{{IFNOTEMPTY:' . $elid . ':BEGIN}}', $newSource);
+ $newSource = str_replace('{{' . lang('TEMPLATE_SRC_IFNOTEMPTY') . ':' . $elname . ':' . lang('TEMPLATE_SRC_END') . '}}', '{{IFNOTEMPTY:' . $elid . ':END}}', $newSource);
}
+ $templatemodel->src = $newSource;
+
+ if ( !$templatemodel->isPersistent() )
+ $templatemodel->add();
+ else
+ $templatemodel->save();
+
$this->addNotice('template',$this->template->name,'SAVED',OR_NOTICE_OK);
}
@@ -434,49 +426,54 @@ class TemplateAction extends Action
$this->setTemplateVar('elements',$list);
- $text = Text::encodeHtml( $this->template->src );
- $text = str_replace("\n",'<br/>',$text);
-
- foreach( $this->template->getElementIds() as $elid )
- {
- $element = new Element( $elid );
- $element->load();
- $url = 'javascript:openNewAction(\''.$element->name.'\',\'element\',\''.$elid.'\');';
-
- $text = str_replace('{{'.$elid.'}}',
- '<a href="'.$url.'" class="element el_'.
- $element->getTypeClass().'" title="'.$element->desc.'">{{'.
- $element->name.'}}</a>',
- $text );
- $text = str_replace('{{->'.$elid.'}}',
- '<a href="'.$url.'" class="element el_'.
- $element->getTypeClass().'" title="'.$element->desc.'">{{->'.
- $element->name.'}}</a>',
- $text );
+ $project = new Project( $this->template->projectid );
- $text = str_replace('{{IFEMPTY:'.$elid.':BEGIN}}',
- '<a href="'.$url.'" class="element el_'.$element->getTypeClass().'" title="'.$element->desc.'">{{'.lang('TEMPLATE_SRC_IFEMPTY').':'.
- $element->name.':'.lang('TEMPLATE_SRC_BEGIN').'}}</a>',
- $text );
- $text = str_replace('{{IFEMPTY:'.$elid.':END}}',
- '<a href="'.$url.'" class="element el_'.$element->getTypeClass().'" title="'.$element->desc.'">{{'.lang('TEMPLATE_SRC_IFEMPTY').':'.
- $element->name.':'.lang('TEMPLATE_SRC_END').'}}</a>',
- $text );
- $text = str_replace('{{IFNOTEMPTY:'.$elid.':BEGIN}}',
- '<a href="'.$url.'" class="element el_'.$element->getTypeClass().'" title="'.$element->desc.'">{{'.lang('TEMPLATE_SRC_IFNOTEMPTY').':'.
- $element->name.':'.lang('TEMPLATE_SRC_BEGIN').'}}</a>',
- $text );
- $text = str_replace('{{IFNOTEMPTY:'.$elid.':END}}',
- '<a href="'.$url.'" class="element el_'.$element->getTypeClass().'" title="'.$element->desc.'">{{'.lang('TEMPLATE_SRC_IFNOTEMPTY').':'.
- $element->name.':'.lang('TEMPLATE_SRC_END').'}}</a>',
- $text );
-
- unset( $element );
- }
-
- $this->setTemplateVar('text',$text);
- }
+ $models = array();
+
+ foreach( $project->getModels() as $modelId => $modelName )
+ {
+ $templatemodel = new TemplateModel( $this->template->templateid, $modelId );
+ $templatemodel->load();
+
+ $text = $templatemodel->src;
+
+ foreach( $this->template->getElementIds() as $elid )
+ {
+ $element = new Element( $elid );
+ $element->load();
+
+ $text = str_replace('{{'.$elid.'}}',
+ '{{'.$element->name.'}}',
+ $text );
+ $text = str_replace('{{->'.$elid.'}}',
+ '{{->'.$element->name.'}}',
+ $text );
+ $text = str_replace('{{IFEMPTY:'.$elid.':BEGIN}}',
+ '{{'.lang('TEMPLATE_SRC_IFEMPTY').':'.$element->name.':'.lang('TEMPLATE_SRC_BEGIN').'}}',
+ $text );
+ $text = str_replace('{{IFEMPTY:'.$elid.':END}}',
+ '{{'.lang('TEMPLATE_SRC_IFEMPTY').':'.$element->name.':'.lang('TEMPLATE_SRC_END').'}}',
+ $text );
+ $text = str_replace('{{IFNOTEMPTY:'.$elid.':BEGIN}}',
+ '{{'.lang('TEMPLATE_SRC_IFNOTEMPTY').':'.$element->name.':'.lang('TEMPLATE_SRC_BEGIN').'}}',
+ $text );
+ $text = str_replace('{{IFNOTEMPTY:'.$elid.':END}}',
+ '{{'.lang('TEMPLATE_SRC_IFNOTEMPTY').':'.$element->name.':'.lang('TEMPLATE_SRC_END').'}}',
+ $text );
+ }
+
+ $models[ $modelId ] = array(
+ 'name' => $modelName,
+ 'source' => $text,
+ 'modelid' => $modelId
+ );
+ }
+
+ $this->setTemplateVar( 'models',$models );
+
+
+ }
function srcelementView()
@@ -507,49 +504,42 @@ class TemplateAction extends Action
function srcView()
{
$project = new Project( $this->template->projectid );
- $models = $project->getModels();
+ $modelId = $this->getRequestId('modelid');
$modelSrc = array();
- foreach( $models as $modelId => $modelName )
- {
- $templatemodel = new TemplateModel( $this->template->templateid, $modelId );
- $templatemodel->load();
-
- $text = $templatemodel->src;
+ $templatemodel = new TemplateModel( $this->template->templateid, $modelId );
+ $templatemodel->load();
- foreach( $this->template->getElementIds() as $elid )
- {
- $element = new Element( $elid );
- $element->load();
+ $text = $templatemodel->src;
- $text = str_replace('{{'.$elid.'}}',
- '{{'.$element->name.'}}',
- $text );
- $text = str_replace('{{->'.$elid.'}}',
- '{{->'.$element->name.'}}',
- $text );
- $text = str_replace('{{IFEMPTY:'.$elid.':BEGIN}}',
- '{{'.lang('TEMPLATE_SRC_IFEMPTY').':'.$element->name.':'.lang('TEMPLATE_SRC_BEGIN').'}}',
- $text );
- $text = str_replace('{{IFEMPTY:'.$elid.':END}}',
- '{{'.lang('TEMPLATE_SRC_IFEMPTY').':'.$element->name.':'.lang('TEMPLATE_SRC_END').'}}',
- $text );
- $text = str_replace('{{IFNOTEMPTY:'.$elid.':BEGIN}}',
- '{{'.lang('TEMPLATE_SRC_IFNOTEMPTY').':'.$element->name.':'.lang('TEMPLATE_SRC_BEGIN').'}}',
- $text );
- $text = str_replace('{{IFNOTEMPTY:'.$elid.':END}}',
- '{{'.lang('TEMPLATE_SRC_IFNOTEMPTY').':'.$element->name.':'.lang('TEMPLATE_SRC_END').'}}',
- $text );
- }
-
- $modelSrc[ $modelId ] = array(
- 'name' =>$modelName,
- 'source'=>$text
- );
+ foreach( $this->template->getElementIds() as $elid )
+ {
+ $element = new Element( $elid );
+ $element->load();
+
+ $text = str_replace('{{'.$elid.'}}',
+ '{{'.$element->name.'}}',
+ $text );
+ $text = str_replace('{{->'.$elid.'}}',
+ '{{->'.$element->name.'}}',
+ $text );
+ $text = str_replace('{{IFEMPTY:'.$elid.':BEGIN}}',
+ '{{'.lang('TEMPLATE_SRC_IFEMPTY').':'.$element->name.':'.lang('TEMPLATE_SRC_BEGIN').'}}',
+ $text );
+ $text = str_replace('{{IFEMPTY:'.$elid.':END}}',
+ '{{'.lang('TEMPLATE_SRC_IFEMPTY').':'.$element->name.':'.lang('TEMPLATE_SRC_END').'}}',
+ $text );
+ $text = str_replace('{{IFNOTEMPTY:'.$elid.':BEGIN}}',
+ '{{'.lang('TEMPLATE_SRC_IFNOTEMPTY').':'.$element->name.':'.lang('TEMPLATE_SRC_BEGIN').'}}',
+ $text );
+ $text = str_replace('{{IFNOTEMPTY:'.$elid.':END}}',
+ '{{'.lang('TEMPLATE_SRC_IFNOTEMPTY').':'.$element->name.':'.lang('TEMPLATE_SRC_END').'}}',
+ $text );
}
- $this->setTemplateVar( 'src',$modelSrc );
+ $this->setTemplateVar( 'modelid',$modelId );
+ $this->setTemplateVar( 'source' ,$text );
}
diff --git a/modules/cms-ui/themes/default/html/views/template/edit.php b/modules/cms-ui/themes/default/html/views/template/edit.php
@@ -50,23 +50,21 @@
</td>
</tr>
</table>
- <fieldset class="toggle-open-close<?php echo '1'?" open":" closed" ?><?php echo '1'?" show":"" ?>"><legend class="on-click-open-close"><div class="arrow arrow-right on-closed"></div><div class="arrow arrow-down on-open"></div><?php echo lang('src') ?></legend><div>
- <div class="table-wrapper"><div class="table-filter"><input type="search" name="filter" placeholder="<?php echo lang('SEARCH_FILTER') ?>" /></div><table width="100%"></div>
- <tr class="data">
- <td>
- <div class="clickable">
- <a target="_self" data-type="view" data-action="" data-method="src" data-id="<?php echo OR_ID ?>" data-extra="[]" href="<?php echo Html::url('','src','',array()) ?>">
- <img src="./modules/cms-ui/themes/default/images/icon/template.png" />
-
- <span><?php echo nl2br(encodeHtml(htmlentities(lang(''.'edit'.'')))); ?></span>
-
- </a>
+ <?php foreach($models as $list_key=>$list_value){ ?><?php extract($list_value) ?>
+ <fieldset class="toggle-open-close<?php echo '1'?" open":" closed" ?><?php echo '1'?" show":"" ?>"><legend class="on-click-open-close"><div class="arrow arrow-right on-closed"></div><div class="arrow arrow-down on-open"></div><?php echo $name ?></legend><div>
+ <div class="clickable">
+ <code><?php echo nl2br(encodeHtml(htmlentities($source))); ?></code>
+
+ <br/>
+
+ <a class="or-form-button" target="_self" data-type="edit" data-action="" data-method="src" data-id="<?php echo OR_ID ?>" data-extra="{'modelid':'<?php echo $modelid ?>'}" href="<?php echo Html::url('','src','',array('modelid'=>$modelid)) ?>">
+ <img src="./modules/cms-ui/themes/default/images/icon/template.png" />
+
+ <span><?php echo nl2br(encodeHtml(htmlentities(lang(''.'edit'.'')))); ?></span>
+
+ </a>
- </div>
- </td>
- </tr>
- </table>
- <code><?php echo nl2br($text); ?></code>
-
- </div></fieldset>
+ </div>
+ </div></fieldset>
+ <?php } ?>
\ No newline at end of file
diff --git a/modules/cms-ui/themes/default/html/views/template/edit.tpl.src.xml b/modules/cms-ui/themes/default/html/views/template/edit.tpl.src.xml
@@ -41,20 +41,20 @@
</row>
</table>
- <group title="message:src">
- <table>
- <row class="data">
- <column>
- <part class="clickable">
- <link type="view" subaction="src">
- <image icon="template" />
- <text key="edit"></text>
- </link>
- </part>
- </column>
- </row>
- </table>
+ <list list="models" extract="true">
+
+ <group title="var:name">
+
+ <part class="clickable">
+ <text var="source" escape="true" type="code"></text>
+ <newline/>
+
+ <link type="edit" subaction="src" var1="modelid" value1="var:modelid" class="or-form-button">
+ <image icon="template"/>
+ <text key="edit"></text>
+ </link>
+ </part>
+ </group>
+ </list>
- <text var="text" escape="false" type="code"></text>
- </group>
</output>
\ No newline at end of file
diff --git a/modules/cms-ui/themes/default/html/views/template/src.php b/modules/cms-ui/themes/default/html/views/template/src.php
@@ -1,13 +1,11 @@
<form name="" target="_self" data-target="view" action="./" data-method="src" data-action="template" data-id="<?php echo OR_ID ?>" method="POST" enctype="application/x-www-form-urlencoded" class="or-form template" data-async="" data-autosave=""><input type="hidden" name="<?php echo REQ_PARAM_EMBED ?>" value="1" /><input type="hidden" name="<?php echo REQ_PARAM_TOKEN ?>" value="<?php echo token() ?>" /><input type="hidden" name="<?php echo REQ_PARAM_ACTION ?>" value="template" /><input type="hidden" name="<?php echo REQ_PARAM_SUBACTION ?>" value="src" /><input type="hidden" name="<?php echo REQ_PARAM_ID ?>" value="<?php echo OR_ID ?>" />
- <?php foreach($src as $list_key=>$list_value){ ?><?php extract($list_value) ?>
- <fieldset class="toggle-open-close<?php echo '1'?" open":" closed" ?><?php echo '1'?" show":"" ?>"><legend class="on-click-open-close"><div class="arrow arrow-right on-closed"></div><div class="arrow arrow-down on-open"></div><?php echo $name ?></legend><div>
- <?php $$name= $source; ?>
-
- <textarea name="<?php if ('source') echo 'source'.'_' ?><?php echo $name ?><?php if ('') echo '_disabled' ?>" data-extension="" data-mimetype="" data-mode="htmlmixed" class="editor code-editor"><?php echo htmlentities(${$name}) ?></textarea>
-
- </div></fieldset>
- <?php } ?>
- <div class="or-form-actionbar"><input type="submit" class="or-form-btn or-form-btn--primary" value="OK" /></div></form>
+ <input type="hidden" name="modelid" value="<?php echo $modelid ?>"/>
+
+ <fieldset class="toggle-open-close<?php echo '1'?" open":" closed" ?><?php echo '1'?" show":"" ?>"><legend class="on-click-open-close"><div class="arrow arrow-right on-closed"></div><div class="arrow arrow-down on-open"></div><?php echo lang('source') ?></legend><div>
+ <textarea name="<?php if ('') echo ''.'_' ?>source<?php if ('') echo '_disabled' ?>" data-extension="" data-mimetype="" data-mode="htmlmixed" class="editor code-editor"><?php echo htmlentities(${'source'}) ?></textarea>
+
+ </div></fieldset>
+ <div class="or-form-actionbar"><input type="button" class="or-form-btn or-form-btn--secondary or-form-btn--cancel" value="<?php echo lang("CANCEL") ?>" /><input type="submit" class="or-form-btn or-form-btn--primary" value="OK" /></div></form>
\ No newline at end of file
diff --git a/modules/cms-ui/themes/default/html/views/template/src.tpl.src.xml b/modules/cms-ui/themes/default/html/views/template/src.tpl.src.xml
@@ -1,14 +1,10 @@
<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">
<form>
- <list list="src" extract="true">
-
- <group title="var:name">
-
- <set var="var:name" value="var:source" />
- <editor type="code" prefix="source" name="var:name" mode="htmlmixed" />
- </group>
- </list>
+ <hidden name="modelid" />
+ <group title="message:source">
+ <editor type="code" name="source" mode="htmlmixed" />
+ </group>
</form>
</output>
\ No newline at end of file