From 89409fe3efcb6da35b7b3851949e4308bb6da685 Mon Sep 17 00:00:00 2001 From: wangyidong Date: Tue, 11 Dec 2018 16:38:03 +0800 Subject: [PATCH] * change for supper xhtml. --- Makefile | 2 + config/config.php | 3 +- framework/control.class.php | 117 ++++++++++++++++++++++++++++++++++++ framework/router.class.php | 34 +++++++++++ module/my/control.php | 2 + www/index.php | 1 + 6 files changed, 158 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 49c3731579..f1718a17f1 100644 --- a/Makefile +++ b/Makefile @@ -46,12 +46,14 @@ pms: mkdir -p buildxx/framework mkdir -p buildxx/db mkdir -p buildxx/www + mkdir -p buildxx/module/common/ext/model/ svn export https://github.com/easysoft/xuanxuan.git/branches/master/ranzhi/ cp ranzhi/config/ext/xuanxuan.php buildxx/config/ext/ cp -r ranzhi/lib/phpaes buildxx/lib/ cp -r ranzhi/framework/xuanxuan.class.php buildxx/framework/ cp -r ranzhi/db/xuanxuan.sql buildxx/db/ cp -r ranzhi/app/sys/chat buildxx/module/ + cp -r ranzhi/app/sys/common/ext/model/hook buildxx/module/common/ext/model/ cp -r ranzhi/app/sys/action buildxx/module/ cp -r xuanxuan/module/* buildxx/module/ cp -r xuanxuan/www/* buildxx/www/ diff --git a/config/config.php b/config/config.php index 9bb69f45ff..ec8aa2bf6a 100644 --- a/config/config.php +++ b/config/config.php @@ -29,7 +29,7 @@ $config->moduleVar = 'm'; // 请求类型为GET:模块变量 $config->methodVar = 'f'; // 请求类型为GET:模块变量名。 requestType=GET: the method var name. $config->viewVar = 't'; // 请求类型为GET:视图变量名。 requestType=GET: the view var name. $config->sessionVar = 'zentaosid'; // 请求类型为GET:session变量名。 requestType=GET: the session var name. -$config->views = ',html,json,mhtml,'; // 支持的视图类型。 Supported view formats. +$config->views = ',html,json,mhtml,xhtml,'; // 支持的视图类型。 Supported view formats. /* 支持的主题和语言。Supported thems and languages. */ $config->themes['default'] = 'default'; @@ -39,6 +39,7 @@ $config->langs['en'] = 'English'; /* 设备类型视图文件前缀。The prefix for view file for different device. */ $config->devicePrefix['mhtml'] = ''; +$config->devicePrefix['xhtml'] = 'x.'; /* 默认值设置。Default settings. */ $config->default = new stdclass(); diff --git a/framework/control.class.php b/framework/control.class.php index 848194f79b..bd70b5db6c 100644 --- a/framework/control.class.php +++ b/framework/control.class.php @@ -20,4 +20,121 @@ include dirname(__FILE__) . '/base/control.class.php'; class control extends baseControl { + /** + * 设置视图文件:主视图文件,扩展视图文件, 站点扩展视图文件,以及钩子脚本。 + * Set view files: the main file, extension view file, site extension view file and hook files. + * + * @param string $moduleName module name + * @param string $methodName method name + * @access public + * @return string the view file + */ + public function setViewFile($moduleName, $methodName) + { + $moduleName = strtolower(trim($moduleName)); + $methodName = strtolower(trim($methodName)); + + $modulePath = $this->app->getModulePath($this->appName, $moduleName); + $viewExtPath = $this->app->getModuleExtPath($this->appName, $moduleName, 'view'); + + $viewType = ($this->viewType == 'mhtml' or $this->viewType == 'xhtml') ? 'html' : $this->viewType; + $mainViewFile = $modulePath . 'view' . 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($this->viewType == 'mhtml' or $this->viewType == 'xhtml') + { + if(!file_exists($mainViewFile)) + { + if($this->viewType == 'xhtml') $this->app->viewType = 'html'; + $this->devicePrefix = ''; + $mainViewFile = $modulePath . 'view' . DS . $this->devicePrefix . $methodName . '.' . $viewType . '.php'; + } + } + + $viewFile = $mainViewFile; + + if(!empty($viewExtPath)) + { + $commonExtViewFile = $viewExtPath['common'] . $this->devicePrefix . $methodName . ".{$viewType}.php"; + $siteExtViewFile = empty($viewExtPath['site']) ? '' : $viewExtPath['site'] . $this->devicePrefix . $methodName . ".{$viewType}.php"; + + $viewFile = file_exists($commonExtViewFile) ? $commonExtViewFile : $mainViewFile; + $viewFile = (!empty($siteExtViewFile) and file_exists($siteExtViewFile)) ? $siteExtViewFile : $viewFile; + if(!is_file($viewFile)) $this->app->triggerError("the view file $viewFile not found", __FILE__, __LINE__, $exit = true); + + $commonExtHookFiles = glob($viewExtPath['common'] . $this->devicePrefix . $methodName . ".*.{$viewType}.hook.php"); + $siteExtHookFiles = empty($viewExtPath['site']) ? '' : glob($viewExtPath['site'] . $this->devicePrefix . $methodName . ".*.{$viewType}.hook.php"); + $extHookFiles = array_merge((array) $commonExtHookFiles, (array) $siteExtHookFiles); + } + + if(!empty($extHookFiles)) return array('viewFile' => $viewFile, 'hookFiles' => $extHookFiles); + return $viewFile; + } + + /** + * 默认渲染方法,适用于viewType = html的时候。 + * Default parse method when viewType != json, like html. + * + * @param string $moduleName module name + * @param string $methodName method name + * @access public + * @return void + */ + public function parseDefault($moduleName, $methodName) + { + /** + * 设置视图文件。(PHP7有一个bug,不能直接$viewFile = $this->setViewFile())。 + * Set viewFile. (Can't assign $viewFile = $this->setViewFile() directly because one php7's bug.) + */ + $results = $this->setViewFile($moduleName, $methodName); + $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 the js or css file doesn't exist, set the device prefix to empty and reset the js or css file. */ + if($this->viewType == 'xhtml') + { + if(!$css) + { + $this->devicePrefix = ''; + $css = $this->getCSS($moduleName, $methodName); + } + if(!$js) + { + $this->devicePrefix = ''; + $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 pathes work. + */ + $currentPWD = getcwd(); + chdir(dirname($viewFile)); + + /** + * 使用extract安定ob方法渲染$viewFile里面的代码。 + * Use extract and ob functions to eval the codes in $viewFile. + */ + extract((array)$this->view); + ob_start(); + include $viewFile; + 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); + } } diff --git a/framework/router.class.php b/framework/router.class.php index 87c03113c4..34509bacc9 100755 --- a/framework/router.class.php +++ b/framework/router.class.php @@ -156,4 +156,38 @@ class router extends baseRouter $this->session->set('rand', $this->session->random); echo json_encode($view); } + + /** + * PATH_INFO方式解析,获取$URI和$viewType。 + * Parse PATH_INFO, get the $URI and $viewType. + * + * @access public + * @return void + */ + public function parsePathInfo() + { + parent::parsePathInfo(); + + if($this->get->display == 'card') + { + $this->viewType = 'xhtml'; + } + } + + /** + * GET请求方式解析,获取$URI和$viewType。 + * Parse GET, get $URI and $viewType. + * + * @access public + * @return void + */ + public function parseGET() + { + parent::parseGET(); + + if($this->get->display == 'card') + { + $this->viewType = 'xhtml'; + } + } } diff --git a/module/my/control.php b/module/my/control.php index 5f2950e160..d04674d664 100644 --- a/module/my/control.php +++ b/module/my/control.php @@ -197,6 +197,8 @@ class my extends control $this->view->orderBy = $orderBy; $this->view->users = $this->loadModel('user')->getPairs('noletter'); $this->view->pager = $pager; + + if($this->app->viewType == 'json') $this->view->tasks = array_values($this->view->tasks); $this->display(); } diff --git a/www/index.php b/www/index.php index de622f3c62..f5409faf48 100644 --- a/www/index.php +++ b/www/index.php @@ -61,6 +61,7 @@ if(file_exists('install.php') or file_exists('upgrade.php')) /* If client device is mobile and version is pro, set the default view as mthml. */ if($app->clientDevice == 'mobile' and (strpos($config->version, 'pro') === 0 or strpos($config->version, 'biz') === 0) and $config->default->view == 'html') $config->default->view = 'mhtml'; +if(!empty($_GET['display']) && $_GET['display'] == 'card') $config->default->view = 'xhtml'; $app->parseRequest(); $common->checkPriv();