diff --git a/sources/application/WebPage/AjaxPage.php b/sources/application/WebPage/AjaxPage.php index 21023afb6a..8819ac99f6 100644 --- a/sources/application/WebPage/AjaxPage.php +++ b/sources/application/WebPage/AjaxPage.php @@ -15,7 +15,7 @@ class AjaxPage extends WebPage implements iTabbedPage * * @var array */ - protected $m_sReadyScript; + protected $m_aReadyScripts; protected $m_oTabs; private $m_sMenu; // If set, then the menu will be updated const DEFAULT_PAGE_TEMPLATE_REL_PATH = 'pages/backoffice/ajaxpage/layout'; @@ -31,7 +31,7 @@ class AjaxPage extends WebPage implements iTabbedPage $bPrintable = ($sPrintable == '1'); parent::__construct($s_title, $bPrintable); - $this->m_sReadyScript = ""; + $this->m_aReadyScripts = []; //$this->add_header("Content-type: text/html; charset=utf-8"); $this->add_header("Cache-control: no-cache"); $this->m_oTabs = new TabManager(); @@ -135,6 +135,8 @@ class AjaxPage extends WebPage implements iTabbedPage */ public function output() { + $s_captured_output = $this->ob_get_clean_safe(); + if (!empty($this->sContentType)) { $this->add_header('Content-type: '.$this->sContentType); } @@ -199,11 +201,6 @@ EOF } // Render the blocks - //$this->s_content = $this->oUIBlockManager->RenderIntoContent($this->s_content, $this); - - // Render the tabs in the page (if any) - //$this->s_content = $this->m_oTabs->RenderIntoContent($this->s_content, $this); - // Additional UI widgets to be activated inside the ajax fragment // Important: Testing the content type is not enough because some ajax handlers have not correctly positionned the flag (e.g json response corrupted by the script) if (($this->sContentType == 'text/html') && (preg_match('/class="date-pick"/', $this->s_content) || preg_match('/class="datetime-pick"/', $this->s_content))) { @@ -230,9 +227,12 @@ EOF 'aCssInline' => $this->a_styles, 'aJsFiles' => $this->a_linked_scripts, 'aJsInlineLive' => $this->a_scripts, + 'aJsInlineOnDomReady' => $this->m_aReadyScripts, + 'bEscapeContent' => ($this->sContentType == 'text/html') && ($this->sContentDisposition == 'inline'), // TODO 2.8.0: TEMP, used while developping, remove it. 'sSanitizedContent' => utils::FilterXSS($this->s_content), - 'sDeferredContent' => utils::FilterXSS($this->s_deferred_content), + 'sDeferredContent' => utils::FilterXSS(addslashes(str_replace("\n", '', $this->s_deferred_content))), + 'sCapturedOutput' => $s_captured_output, ]; $oTwigEnv = TwigHelper::GetTwigEnvironment(BlockRenderer::TWIG_BASE_PATH, BlockRenderer::TWIG_ADDITIONAL_PATHS); @@ -246,9 +246,9 @@ EOF echo $sHtml; $oKpi->ComputeAndReport('Echoing ('.round(strlen($sHtml) / 1024).' Kb)'); - return; + $oKPI = new ExecutionKPI(); $s_captured_output = $this->ob_get_clean_safe(); if (($this->sContentType == 'text/html') && ($this->sContentDisposition == 'inline')) { @@ -257,6 +257,8 @@ EOF } else { echo $this->s_content; } + + // TODO 2.8.0 Only for designer ? if (!empty($this->m_sMenu)) { $uid = time(); echo "
\n"; @@ -291,9 +293,9 @@ EOF echo "\$('body').append('".addslashes(str_replace("\n", '', $this->s_deferred_content))."');\n"; echo "\n\n"; } - if (!empty($this->m_sReadyScript)) { + if (!empty($this->m_aReadyScripts)) { echo "\n"; } if (count($this->a_linked_stylesheets) > 0) { @@ -394,7 +396,9 @@ EOF */ public function add_ready_script($sScript) { - $this->m_sReadyScript .= $sScript."\n"; + if (!empty(trim($sScript))) { + $this->m_aReadyScripts[] = $sScript; + } } /** diff --git a/sources/application/WebPage/NiceWebPage.php b/sources/application/WebPage/NiceWebPage.php index 0e3eb1f547..0e2731a762 100644 --- a/sources/application/WebPage/NiceWebPage.php +++ b/sources/application/WebPage/NiceWebPage.php @@ -232,7 +232,9 @@ EOF public function add_ready_script($sScript) { - $this->m_aReadyScripts[] = $sScript; + if (!empty(trim($sScript))) { + $this->m_aReadyScripts[] = $sScript; + } } /** diff --git a/templates/pages/backoffice/ajaxpage/layout.html.twig b/templates/pages/backoffice/ajaxpage/layout.html.twig index 19f9533694..670f180262 100644 --- a/templates/pages/backoffice/ajaxpage/layout.html.twig +++ b/templates/pages/backoffice/ajaxpage/layout.html.twig @@ -1 +1,49 @@ -{{ render_block(oLayout, {aPage: aPage}) }} +{% apply spaceless %} + {% if bEscapeContent %} + {{ render_block(oLayout, {aPage: aPage})|escape }} + {% else %} + {{ render_block(oLayout, {aPage: aPage}) }} + {% endif %} + + {% block iboPageJsInlineLive %} + {% for sJsInline in aPage.aJsInlineLive %} + {# We put each scripts in a dedicated script tag to prevent massive failure if 1 script is broken (eg. missing semi-colon or non closed multi-line comment) #} + + {% endfor %} + {% endblock %} + + {% block iboPageJsFiles %} + {% for sJsFile in aPage.aJsFiles %} + + {% endfor %} + {% endblock %} + + {% if sDeferredContent %} + + {% endif %} + + {% block iboPageJsInlineOnDomReady %} + {% for sJsInline in aPage.aJsInlineOnDomReady %} + + {% endfor %} + {% endblock %} + + {% block iboPageCssFiles %} + {% for aCssFileData in aPage.aCssFiles %} + + {% endfor %} + {% endblock %} + + {{ sCapturedOutput }} + +{% endapply %} \ No newline at end of file diff --git a/templates/pages/backoffice/nicewebpage/layout.html.twig b/templates/pages/backoffice/nicewebpage/layout.html.twig index 993e7a7925..602ebf6f62 100644 --- a/templates/pages/backoffice/nicewebpage/layout.html.twig +++ b/templates/pages/backoffice/nicewebpage/layout.html.twig @@ -1,10 +1,10 @@ {% extends "pages/backoffice/webpage/layout.html.twig" %} {% block iboPageJsInlineOnDomReady %} - setTimeout(function () { {% for sJsInline in aPage.aJsInlineOnDomReady %} + setTimeout(function () { {{ sJsInline|raw }} + }, 50); {% endfor %} - }, 50); {% endblock %} diff --git a/templates/pages/backoffice/webpage/layout.html.twig b/templates/pages/backoffice/webpage/layout.html.twig index 85be2a25dd..e652ebd488 100644 --- a/templates/pages/backoffice/webpage/layout.html.twig +++ b/templates/pages/backoffice/webpage/layout.html.twig @@ -54,7 +54,7 @@ {% block iboPageJsInlineScripts %}