From 7dd4586d4683fa2f0597e11798880ba2ec0c0923 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=80=A1=E6=A0=8B?= Date: Fri, 12 Nov 2021 13:51:26 +0800 Subject: [PATCH] * adjust for api. --- api/v1/entries/views.php | 9 ++++++- framework/base/router.class.php | 47 +++++++++++++++++++++++---------- framework/helper.class.php | 5 +++- 3 files changed, 45 insertions(+), 16 deletions(-) diff --git a/api/v1/entries/views.php b/api/v1/entries/views.php index f2b27bef9a..bb229944d2 100644 --- a/api/v1/entries/views.php +++ b/api/v1/entries/views.php @@ -20,12 +20,19 @@ class viewsEntry extends entry public function get() { $position = $this->param('position', ''); - $lite = $this->param('lite', ''); + $tab = $this->param('tab', ''); + $lite = $this->param('lite', ''); if(empty($position)) return $this->sendError(400, 'Need position param.'); if($position != 'header' and $position != 'footer') return $this->sendError(400, 'Value of position param only is header or footer.'); if(!empty($lite)) $lite .= 'lite.'; + if($tab) + { + $_COOKIE['tab'] = $tab; + $this->app->setOpenApp(); + } + $viewFile = $this->app->moduleRoot . "common/view/{$position}.{$lite}html.php"; if(!file_exists($viewFile)) return $this->sendError(400, 'This view file is not exists.'); diff --git a/framework/base/router.class.php b/framework/base/router.class.php index 1aeffb2b0c..527dfa74a9 100644 --- a/framework/base/router.class.php +++ b/framework/base/router.class.php @@ -1396,6 +1396,31 @@ class baseRouter /* 如果扩展目录为空,不包含任何扩展文件。If there's no ext paths return false.*/ if(empty($moduleExtPaths)) return false; + /* 如果extensionLevel == 2,且扩展文件存在,返回该站点扩展文件。If extensionLevel == 2 and site extensionFile exists, return it. */ + if($this->config->framework->extensionLevel == 2 and !empty( $moduleExtPaths['site'])) + { + $this->extActionFile = $moduleExtPaths['site'] . $this->methodName . '.php'; + if(file_exists($this->extActionFile)) return true; + } + + /* 然后再尝试寻找公共扩展文件。Then try to find the common extension file. */ + $this->extActionFile = $moduleExtPaths['common'] . $this->methodName . '.php'; + return file_exists($this->extActionFile); + } + + /** + * Check for API extend. + * + * @access public + * @return bool + */ + public function checkAPIFile() + { + $moduleExtPaths = $this->getModuleExtPath('', $this->moduleName, 'control'); + + /* 如果扩展目录为空,不包含任何扩展文件。If there's no ext paths return false.*/ + if(empty($moduleExtPaths)) return false; + /* 如果extensionLevel == 2,且扩展文件存在,返回该站点扩展文件。If extensionLevel == 2 and site extensionFile exists, return it. */ if($this->config->framework->extensionLevel == 2 and !empty( $moduleExtPaths['site'])) { @@ -1403,9 +1428,6 @@ class baseRouter if(file_exists($locateFile)) $this->sendAPI($locateFile); $requestFile = $moduleExtPaths['site'] . $this->methodName . '.api'; if(file_exists($requestFile)) $this->sendAPI($requestFile); - - $this->extActionFile = $moduleExtPaths['site'] . $this->methodName . '.php'; - if(file_exists($this->extActionFile)) return true; } /* 然后再尝试寻找公共扩展文件。Then try to find the common extension file. */ @@ -1414,8 +1436,7 @@ class baseRouter $requestFile = $moduleExtPaths['common'] . $this->methodName . '.api'; if(file_exists($requestFile)) $this->sendAPI($requestFile); - $this->extActionFile = $moduleExtPaths['common'] . $this->methodName . '.php'; - return file_exists($this->extActionFile); + return false; } /** @@ -1707,19 +1728,16 @@ class baseRouter $obLevel = ob_get_level(); for($i = 0; $i < $obLevel; $i++) ob_end_clean(); - $controller = new control(); - $viewFiles = $controller->setViewFile($this->moduleName, $this->methodName); + $viewFiles = $this->control->setViewFile($this->moduleName, $this->methodName); - $css = $controller->getCSS($this->moduleName, $this->methodName); - $js = $controller->getJS($this->moduleName, $this->methodName); - if($css) $controller->view->pageCSS = $css; - if($js) $controller->view->pageJS = $js; + if($css) $this->control->view->pageCSS = $css; + if($js) $this->control->view->pageJS = $js; $output = ''; - $output .= $controller->printViewFile($headFile); + $output .= $this->control->printViewFile($headFile); $output .= $response; - if(isset($viewFiles['hookFiles'])) foreach($viewFiles['hookFiles'] as $hookFile) $output .= $controller->printViewFile($hookFile); - $output .= $controller->printViewFile($footFile); + if(isset($viewFiles['hookFiles'])) foreach($viewFiles['hookFiles'] as $hookFile) $output .= $this->control->printViewFile($hookFile); + $output .= $this->control->printViewFile($footFile); die($output); } } @@ -1893,6 +1911,7 @@ class baseRouter /* 调用该方法 Call the method. */ call_user_func_array(array($module, $methodName), $this->params); + $this->checkAPIFile(); return $module; } diff --git a/framework/helper.class.php b/framework/helper.class.php index 27c43274dc..7a169ccaa1 100644 --- a/framework/helper.class.php +++ b/framework/helper.class.php @@ -243,7 +243,10 @@ class helper extends baseHelper $url .= (strpos($url, '?') !== false ? '&' : '?') . $config->sessionVar . '=' . session_id(); if(isset($_SESSION['user'])) $url .= '&account=' . $_SESSION['user']->account; - return common::http($url); + $response = common::http($url); + $jsonDecode = json_decode($response); + if(empty($jsonDecode)) return $response; + return $jsonDecode; } }