diff --git a/framework/base/control.class.php b/framework/base/control.class.php index 1576843b29..c83a61d294 100644 --- a/framework/base/control.class.php +++ b/framework/base/control.class.php @@ -366,19 +366,20 @@ class baseControl * * @param string $moduleName module name * @param string $methodName method name + * @param string $viewDir * @access public * @return string the view file */ - public function setViewFile($moduleName, $methodName) + public function setViewFile($moduleName, $methodName, $viewDir = 'view') { $moduleName = strtolower(trim($moduleName)); $methodName = strtolower(trim($methodName)); $modulePath = $this->app->getModulePath($this->appName, $moduleName); - $viewExtPath = $this->app->getModuleExtPath($this->appName, $moduleName, 'view'); + $viewExtPath = $this->app->getModuleExtPath($this->appName, $moduleName, $viewDir); $viewType = $this->viewType == 'mhtml' ? 'html' : $this->viewType; - $mainViewFile = $modulePath . 'view' . DS . $this->devicePrefix . $methodName . '.' . $viewType . '.php'; + $mainViewFile = $modulePath . $viewDir . DS . $this->devicePrefix . $methodName . '.' . $viewType . '.php'; $viewFile = $mainViewFile; if(!empty($viewExtPath)) @@ -893,6 +894,72 @@ class baseControl echo $this->output; } + /** + * 向浏览器输出内容。 + * Print the content of the view. + * + * @param string $moduleName module name + * @param string $methodName method name + * @access public + * @return void + */ + public function render($moduleName = '', $methodName = '') + { + if(empty($moduleName)) $moduleName = $this->moduleName; + if(empty($methodName)) $methodName = $this->methodName; + + include $this->app->getBasePath() . 'zin' . DS . 'wg.func.php'; + include $this->app->getBasePath() . 'zin' . DS . 'block.class.php'; + include $this->app->getBasePath() . 'zin' . DS . 'page.class.php'; + + /** + * 设置视图文件。(PHP7有一个bug,不能直接$viewFile = $this->setViewFile())。 + * Set viewFile. (Can't assign $viewFile = $this->setViewFile() directly because one php7's bug.) + */ + $results = $this->setViewFile($moduleName, $methodName, 'ui'); + + $viewFile = $results; + if(is_array($results)) extract($results); + + /** + * 获得当前页面的CSS和JS。 + * Get css and js codes for current method. + */ + $css = $this->getCSS($moduleName, $methodName); + $js = $this->getJS($moduleName, $methodName); + if($css) $this->view->pageCSS = $css; + if($js) $this->view->pageJS = $js; + + /** + * 切换到视图文件所在的目录,以保证视图文件里面的include语句能够正常运行。 + * Change the dir to the view file to keep the relative paths work. + */ + $currentPWD = getcwd(); + chdir(dirname($viewFile)); + + /** + * 使用extract安定ob方法渲染$viewFile里面的代码。 + * Use extract and ob functions to eval the codes in $viewFile. + */ + extract((array)$this->view); + 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(); + */ + + /** + * 渲染完毕后,再切换回之前的路径。 + * At the end, chang the dir to the previous. + */ + chdir($currentPWD); + + echo $this->output; + } + /** * 直接输出data数据,通常用于ajax请求中。 * Send data directly, for ajax requests. diff --git a/framework/control.class.php b/framework/control.class.php index 209cf5fb76..d9d612c023 100644 --- a/framework/control.class.php +++ b/framework/control.class.php @@ -167,19 +167,20 @@ class control extends baseControl * * @param string $moduleName module name * @param string $methodName method name + * @param string $viewDir * @access public * @return string the view file */ - public function setViewFile($moduleName, $methodName) + public function setViewFile($moduleName, $methodName, $viewDir = 'view') { $moduleName = strtolower(trim($moduleName)); $methodName = strtolower(trim($methodName)); $modulePath = $this->app->getModulePath($this->appName, $moduleName); - $viewExtPath = $this->app->getModuleExtPath($this->appName, $moduleName, 'view'); + $viewExtPath = $this->app->getModuleExtPath($this->appName, $moduleName, $viewDir); $viewType = ($this->viewType == 'mhtml' or $this->viewType == 'xhtml') ? 'html' : $this->viewType; - $mainViewFile = $modulePath . 'view' . DS . $this->devicePrefix . $methodName . '.' . $viewType . '.php'; + $mainViewFile = $modulePath . $viewDir . DS . $this->devicePrefix . $methodName . '.' . $viewType . '.php'; /* If the main view file doesn't exist, set the device prefix to empty and reset the main view file. */ if(!file_exists($mainViewFile) and $this->app->clientDevice != 'mobile') diff --git a/module/program/control.php b/module/program/control.php index 7aebc08e59..989c66e343 100644 --- a/module/program/control.php +++ b/module/program/control.php @@ -99,7 +99,8 @@ class program extends control $this->view->progressList = $this->program->getProgressList(); $this->view->hasProject = $hasProject; - $this->display(); + // $this->display(); + $this->render(); } /** diff --git a/zin/block.class.php b/zin/block.class.php new file mode 100644 index 0000000000..340004b6c5 --- /dev/null +++ b/zin/block.class.php @@ -0,0 +1,35 @@ +lang = $lang; + $this->config = $config; + $this->app = $app; + $this->type = $type; + } + + public function __set($attr, $value) + { + $this->children[$attr] = $value; + } + + public function x() + { + foreach($this->children as $key => $child) + { + echo $child->toString(); + } + } +} + +function block($type) +{ + return new block($type); +} diff --git a/zin/page.class.php b/zin/page.class.php new file mode 100644 index 0000000000..0c0fab2485 --- /dev/null +++ b/zin/page.class.php @@ -0,0 +1,107 @@ +layout[$attr] = $value; + } +} + +class page +{ + public $top; + public $left; + public $right; + public $bottom; + + public function __construct($layout) + { + global $app, $config; + $this->app = $app; + $this->view = $app->control->view; + $this->config = $config; + $this->cookie = $app->cookie; + + $this->top = new region(); + $this->left = new region(); + $this->right = new region(); + $this->bottom = new region(); + } + + /** + * 获取某一个视图文件的扩展。 + * Get the extension file of an view. + * + * @param string $viewFile + * @access public + * @return string|bool If extension view file exists, return the path. Else return fasle. + */ + public function getExtViewFile($viewFile) + { + return $this->app->control->getExtViewFile($viewFile); + } + + /** + * 加载指定模块的model文件。 + * Load the model file of one module. + * + * @param string $moduleName 模块名,如果为空,使用当前模块。The module name, if empty, use current module's name. + * @param string $appName The app name, if empty, use current app's name. + * @access public + * @return object|bool 如果没有model文件,返回false,否则返回model对象。If no model file, return false, else return the model object. + */ + public function loadModel($moduleName = '', $appName = '') + { + return $this->app->control->loadModel($moduleName, $appName); + } + + public function x() + { + extract((array)$this->app->control->view); + + ob_start(); + + /* Header. */ + if(isset($hookFiles)) foreach($hookFiles as $hookFile) if(file_exists($hookFile)) include $hookFile; + include $this->app->getModuleRoot() . 'common' . DS . 'view' . DS . 'header.html.php'; + + /* Body. */ + if(!empty($this->top->layout)) + { + echo ''; + } + + echo '
'; + if(!empty($this->left->layout)) + { + echo ''; + } + + if(!empty($this->right->layout)) + { + echo '
'; + foreach($this->right->layout as $key => $block) $block->x(); + echo '
'; + } + echo '
'; + + /* Footer. */ + include $this->app->getModuleRoot() . 'common' . DS . 'view' . DS . 'footer.html.php'; + + $output .= ob_get_contents(); + ob_end_clean(); + + echo $output; + } +} + +function page($layout) +{ + return new page($layout); +} diff --git a/zin/wg.class.php b/zin/wg.class.php new file mode 100644 index 0000000000..7106914903 --- /dev/null +++ b/zin/wg.class.php @@ -0,0 +1,13 @@ +getBasePath() . 'zin' . DS . 'wg' . DS . $wgType . DS . 'v1.php'; + return new $wgType($text); +} + +function button($text = '', $v = 0) {return wgFactory('button', $text);} +function select($text = '', $v = 0) {return wgFactory('select', $text);} +function tab($text = '', $v = 0) {return wgFactory('tab', $text);} +function toolbar($text = '', $v = 0) {return wgFactory('toolbar', $text);} diff --git a/zin/wg/button/v1.php b/zin/wg/button/v1.php new file mode 100644 index 0000000000..fcc12c3840 --- /dev/null +++ b/zin/wg/button/v1.php @@ -0,0 +1,12 @@ + + } +} diff --git a/zin/wg/tab/v1.php b/zin/wg/tab/v1.php new file mode 100644 index 0000000000..595621e844 --- /dev/null +++ b/zin/wg/tab/v1.php @@ -0,0 +1,30 @@ +text = $text; + } + + public function active($isActive) + { + $this->isActive = $isActive; + return $this; + } + + public function link($link) + { + $this->link = $link; + return $this; + } + + public function toString() + { + $active = $this->isActive ? 'btn-active-text' : ''; + return html::a($link, $this->text, '', "class='btn btn-link $active'"); + } +} diff --git a/zin/wg/toolbar/v1.php b/zin/wg/toolbar/v1.php new file mode 100644 index 0000000000..c30a6bd1f5 --- /dev/null +++ b/zin/wg/toolbar/v1.php @@ -0,0 +1,24 @@ +children[] = $item; + } + + public function toString() + { + $html = '
'; + foreach($this->children as $child) + { + $html .= $child->toString(); + } + return $html . '
'; + } +}