From b85aa4f7d11caf7d525cdc5b5cb8dd8ef185c134 Mon Sep 17 00:00:00 2001 From: sunhao Date: Tue, 20 Jun 2023 20:49:01 +0800 Subject: [PATCH] * zin: support to use raw content from buffer. --- framework/base/control.class.php | 10 +++------- lib/zin/core/wg.class.php | 11 +++++++++-- lib/zin/core/wg.func.php | 10 ++++++++++ lib/zin/wg/fragment/v1.php | 11 +++++++++-- lib/zin/wg/modaldialog/v1.php | 7 +++++-- lib/zin/wg/pagebase/v1.php | 23 +++++++++++++---------- 6 files changed, 49 insertions(+), 23 deletions(-) diff --git a/framework/base/control.class.php b/framework/base/control.class.php index 9310469b8d..728546cdca 100644 --- a/framework/base/control.class.php +++ b/framework/base/control.class.php @@ -1011,14 +1011,10 @@ class baseControl */ extract(\zin\zin::$data); - include $viewFile; - /* - extract((array)$this->view); ob_start(); - if(isset($hookFiles)) foreach($hookFiles as $hookFile) if(file_exists($hookFile)) include $hookFile; - $this->output .= ob_get_contents(); - ob_end_clean(); - */ + include $viewFile; + ob_end_flush(); + echo $output; /** * 渲染完毕后,再切换回之前的路径。 diff --git a/lib/zin/core/wg.class.php b/lib/zin/core/wg.class.php index 4e4d66306a..e3f0921dd0 100644 --- a/lib/zin/core/wg.class.php +++ b/lib/zin/core/wg.class.php @@ -156,6 +156,10 @@ class wg if(isset($app->zinErrors)) $zinDebug['errors'] = $app->zinErrors; } + $rawContent = ob_get_contents(); + if(!is_string($rawContent)) $rawContent = ''; + ob_end_clean(); + if(is_object($result)) { if($zinDebug && isset($result['zinDebug'])) $result['zinDebug'] = $zinDebug; @@ -167,8 +171,10 @@ class wg { if(!isset($item['type']) || $item['type'] !== 'html') continue; - $item['data'] = str_replace('/*{{ZIN_PAGE_CSS}}*/', $css, $item['data']); - $item['data'] = str_replace('/*{{ZIN_PAGE_JS}}*/', $js, $item['data']); + $item['data'] = str_replace('/*{{ZIN_PAGE_CSS}}*/', $css, $item['data']); + $item['data'] = str_replace('/*{{ZIN_PAGE_JS}}*/', $js, $item['data']); + $item['data'] = str_replace('', $rawContent, $item['data']); + $result[$name]['data'] = $item['data']; } if($zinDebug && isset($result['zinDebug'])) $result['zinDebug'] = $zinDebug; @@ -179,6 +185,7 @@ class wg if($zinDebug) $js .= h::createJsVarCode('window.zinDebug', $zinDebug); $result = str_replace('/*{{ZIN_PAGE_CSS}}*/', $css, $result); $result = str_replace('/*{{ZIN_PAGE_JS}}*/', $js, $result); + $result = str_replace('', $rawContent, $result); } echo $result; diff --git a/lib/zin/core/wg.func.php b/lib/zin/core/wg.func.php index 432e27e1b3..a31951721f 100644 --- a/lib/zin/core/wg.func.php +++ b/lib/zin/core/wg.func.php @@ -280,3 +280,13 @@ function groupWgInList(wg|array $items, string|array $types): array $groups[] = $restList; return $groups; } + +/** + * Create raw content placeholder. + * + * @return directive + */ +function rawContent(): directive +{ + return h::comment('{{RAW_CONTENT}}'); +} diff --git a/lib/zin/wg/fragment/v1.php b/lib/zin/wg/fragment/v1.php index 06d0c19f34..f19f78a1b5 100644 --- a/lib/zin/wg/fragment/v1.php +++ b/lib/zin/wg/fragment/v1.php @@ -3,15 +3,22 @@ namespace zin; class fragment extends wg { + static $defineProps = array + ( + 'rawContent?: bool=true' + ); + protected function build() { - $css = array(data('pageCSS'), '/*{{ZIN_PAGE_CSS}}*/'); - $js = array('/*{{ZIN_PAGE_JS}}*/', data('pageJS')); + $css = array(data('pageCSS'), '/*{{ZIN_PAGE_CSS}}*/'); + $js = array('/*{{ZIN_PAGE_JS}}*/', data('pageJS')); + $rawContent = $this->prop('rawContent'); return array ( h::css($css, setClass('zin-page-css')), $this->children(), + $rawContent ? rawContent() : null, h::js($js, setClass('zin-page-js')) ); } diff --git a/lib/zin/wg/modaldialog/v1.php b/lib/zin/wg/modaldialog/v1.php index 73c5b898f6..7ba7ca9fa6 100644 --- a/lib/zin/wg/modaldialog/v1.php +++ b/lib/zin/wg/modaldialog/v1.php @@ -14,6 +14,7 @@ class modalDialog extends wg 'footerActions?: array', 'footerClass?: string', 'footerProps?: array', + 'rawContent?: bool=true' ); static $defineBlocks = array( @@ -81,10 +82,12 @@ class modalDialog extends wg protected function buildBody() { + $rawContent = $this->prop('rawContent'); return div ( setClass('modal-body'), - $this->children() + $this->children(), + $rawContent ? rawContent() : null, ); } @@ -93,7 +96,7 @@ class modalDialog extends wg return div ( setClass('modal-dialog'), - set($this->props->skip(array_keys(static::getDefinedProps()))), + set($this->getRestProps()), div ( setClass('modal-content'), diff --git a/lib/zin/wg/pagebase/v1.php b/lib/zin/wg/pagebase/v1.php index 7834df97b5..9c9928eb0d 100644 --- a/lib/zin/wg/pagebase/v1.php +++ b/lib/zin/wg/pagebase/v1.php @@ -13,7 +13,8 @@ class pageBase extends wg 'bodyClass?: array|string', 'zui?: bool', 'lang?: string', - 'display?: bool' + 'display?: bool', + 'rawContent?: bool=true' ); static $defaultProps = array @@ -48,15 +49,16 @@ class pageBase extends wg $head = $this->buildHead(); $body = $this->buildBody(); - $jsConfig = \js::getJSConfigVars(); - $bodyProps = $this->prop('bodyProps'); - $bodyClass = $this->prop('bodyClass'); - $metas = $this->prop('metas'); - $title = $this->props->get('title', data('title')) . " - $lang->zentaoPMS"; - $attrs = $this->props->skip(array_keys(static::getDefinedProps())); - $css = array(data('pageCSS'), '/*{{ZIN_PAGE_CSS}}*/'); - $js = array('/*{{ZIN_PAGE_JS}}*/', data('pageJS')); - $imports = context::current()->getImportList(); + $jsConfig = \js::getJSConfigVars(); + $bodyProps = $this->prop('bodyProps'); + $bodyClass = $this->prop('bodyClass'); + $metas = $this->prop('metas'); + $rawContent = $this->prop('rawContent'); + $title = $this->props->get('title', data('title')) . " - $lang->zentaoPMS"; + $attrs = $this->props->skip(array_keys(static::getDefinedProps())); + $css = array(data('pageCSS'), '/*{{ZIN_PAGE_CSS}}*/'); + $js = array('/*{{ZIN_PAGE_JS}}*/', data('pageJS')); + $imports = context::current()->getImportList(); $jsConfig->zin = true; if($config->debug) @@ -95,6 +97,7 @@ class pageBase extends wg empty($imports) ? null : h::import($imports), h::css($css, setClass('zin-page-css')), $body, + $rawContent ? rawContent() : null, h::js($js, setClass('zin-page-js')) ) );