Skip to content

Commit eddd0a7

Browse files
committed
Allow Loading html from from POST request for editor components
1 parent 04f5b0c commit eddd0a7

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

system/core/view.php

+22-4
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ class View {
5858

5959
private $componentContent;
6060

61+
private $html;
62+
6163
private $useComponent;
6264

6365
private $isEditor = false;
@@ -80,18 +82,23 @@ function __construct() {
8082
$this->theme = config(APP . '.theme', 'default');
8183
}
8284

85+
if (isEditor()) {
86+
$this->isEditor = true;
87+
}
88+
8389
$domain = $this->theme . '-domain';
8490
addTranslationDomain($domain);
8591

8692
$this->htmlPath = DIR_THEME . $this->theme . DS;
8793
$this->templatePath = DIR_THEME . $this->theme . DS; //\Vvveb\config(APP . '.theme', 'default') . DS;
8894

89-
if (isset($_REQUEST['_component_ajax'])) {
95+
if (isset($_REQUEST['_component_ajax']) && $this->isEditor) {
9096
$this->component = \Vvveb\filter('/[a-z\-]*/', $_REQUEST['_component_ajax'], 15);
9197
$this->componentCount = \Vvveb\filter('/\d+/', $_REQUEST['_component_id'], 2);
9298
//$this->componentCount = 0;
9399
//if (isset($_REQUEST['_server_template'])) {
94100
$this->componentContent = $_POST['_component_content'] ?? '';
101+
$this->html = $_POST['html'] ?? '';
95102
//}
96103
}
97104

@@ -109,7 +116,7 @@ function __construct() {
109116
$template->addTemplatePath($this->htmlPath . 'template' . DS);
110117
$template->setHtmlPath($this->htmlPath);
111118

112-
if (isEditor()) {
119+
if ($this->isEditor) {
113120
$this->isEditor = true;
114121
$template->removeVattrs(false);
115122
}
@@ -257,13 +264,24 @@ private function compile($filename, $file, $service = false) {
257264
if ($this->useComponent && ! defined('CLI')) {
258265
//regenerate components cache
259266
if (! $service) {
260-
$service = Component::getInstance($this, true, $this->componentContent);
267+
if ($this->html) {
268+
$html = $this->html;
269+
} else {
270+
$html = $this->componentContent;
271+
}
272+
273+
$service = Component::getInstance($this, true, $html);
261274
}
262275
}
263276

264277
list($this->template, $filename, $this->tplFile) =
265278
Event :: trigger(__CLASS__,__FUNCTION__, $this->template, $filename, $this->tplFile, $this->templateEngine, $this);
266-
$errors = $this->templateEngine->loadHtmlTemplate($filename);
279+
280+
if ($this->html) {
281+
$errors = $this->templateEngine->loadHtml($this->html);
282+
} else {
283+
$errors = $this->templateEngine->loadHtmlTemplate($filename);
284+
}
267285

268286
//if no template defined use the default
269287
if ($this->tplFile[0] == '/') {

0 commit comments

Comments
 (0)