* change for supper xhtml.

This commit is contained in:
wangyidong
2018-12-11 16:38:03 +08:00
parent dfe6066d78
commit 89409fe3ef
6 changed files with 158 additions and 1 deletions
+2
View File
@@ -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/
+2 -1
View File
@@ -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();
+117
View File
@@ -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);
}
}
+34
View File
@@ -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';
}
}
}
+2
View File
@@ -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();
}
+1
View File
@@ -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();