From c19e2a432bffdeb86d375395797f291a21eed96b Mon Sep 17 00:00:00 2001 From: cdujeu Date: Mon, 9 May 2016 13:58:41 +0200 Subject: [PATCH] Move get_boot_conf action to dedicated method (psr-7 compatible). --- .../gui.ajax/class.AJXP_ClientDriver.php | 149 +++--------------- core/src/plugins/gui.ajax/manifest.xml | 2 +- 2 files changed, 19 insertions(+), 132 deletions(-) diff --git a/core/src/plugins/gui.ajax/class.AJXP_ClientDriver.php b/core/src/plugins/gui.ajax/class.AJXP_ClientDriver.php index f61d5d602c..ec49b22d4f 100644 --- a/core/src/plugins/gui.ajax/class.AJXP_ClientDriver.php +++ b/core/src/plugins/gui.ajax/class.AJXP_ClientDriver.php @@ -61,6 +61,23 @@ public function loadConfigs($configData) } } + /** + * @param ServerRequestInterface $request + * @param ResponseInterface $response + */ + public function getBootConf(ServerRequestInterface &$request, ResponseInterface &$response){ + + $out = array(); + Utils::parseApplicationGetParameters($request->getQueryParams(), $out, $_SESSION); + $config = $this->computeBootConf(); + $response = $response->withHeader("Content-type", "application/json;charset=UTF-8"); + $response->getBody()->write(json_encode($config)); + + } + /** + * @param ServerRequestInterface $request + * @param ResponseInterface $response + */ public function getBootGui(ServerRequestInterface &$request, ResponseInterface &$response){ if (!defined("AJXP_THEME_FOLDER")) { @@ -250,137 +267,7 @@ public function switchAction($action, $httpVars, $fileVars) break; - - //------------------------------------ - // GET BOOT GUI - //------------------------------------ - case "get_boot_gui": - - HTMLWriter::internetExplorerMainDocumentHeader(); - HTMLWriter::charsetHeader(); - - if (!is_file(TESTS_RESULT_FILE)) { - $outputArray = array(); - $testedParams = array(); - $passed = Utils::runTests($outputArray, $testedParams); - if (!$passed && !isset($httpVars["ignore_tests"])) { - Utils::testResultsToTable($outputArray, $testedParams); - die(); - } else { - Utils::testResultsToFile($outputArray, $testedParams); - } - } - - $root = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); - $configUrl = ConfService::getCoreConf("SERVER_URL"); - if(!empty($configUrl)){ - $root = '/'.ltrim(parse_url($configUrl, PHP_URL_PATH), '/'); - if(strlen($root) > 1) $root = rtrim($root, '/').'/'; - }else{ - preg_match ('/ws-(.)*\/|settings|dashboard|welcome|user/', $root, $matches, PREG_OFFSET_CAPTURE); - if(count($matches)){ - $capture = $matches[0][1]; - $root = substr($root, 0, $capture); - } - } - $START_PARAMETERS = array( - "BOOTER_URL" =>"index.php?get_action=get_boot_conf", - "MAIN_ELEMENT" => "ajxp_desktop", - "APPLICATION_ROOT" => $root, - "REBASE" => $root - ); - if (AuthService::usersEnabled()) { - AuthService::preLogUser((isSet($httpVars["remote_session"])?$httpVars["remote_session"]:"")); - AuthService::bootSequence($START_PARAMETERS); - if (AuthService::getLoggedUser() != null || AuthService::logUser(null, null) == 1) { - if (AuthService::getDefaultRootId() == -1) { - AuthService::disconnect(); - } else { - $loggedUser = AuthService::getLoggedUser(); - if(!$loggedUser->canRead(ConfService::getCurrentRepositoryId()) - && AuthService::getDefaultRootId() != ConfService::getCurrentRepositoryId()) - { - ConfService::switchRootDir(AuthService::getDefaultRootId()); - } - } - } - } - - Utils::parseApplicationGetParameters($_GET, $START_PARAMETERS, $_SESSION); - - $confErrors = ConfService::getErrors(); - if (count($confErrors)) { - $START_PARAMETERS["ALERT"] = implode(", ", array_values($confErrors)); - } - // PRECOMPUTE BOOT CONF - if (!preg_match('/MSIE 7/',$_SERVER['HTTP_USER_AGENT']) && !preg_match('/MSIE 8/',$_SERVER['HTTP_USER_AGENT'])) { - $preloadedBootConf = $this->computeBootConf(); - Controller::applyHook("loader.filter_boot_conf", array(&$preloadedBootConf)); - $START_PARAMETERS["PRELOADED_BOOT_CONF"] = $preloadedBootConf; - } - - // PRECOMPUTE REGISTRY - if (!isSet($START_PARAMETERS["FORCE_REGISTRY_RELOAD"])) { - $clone = ConfService::getFilteredXMLRegistry(true, true); - $clonePath = new DOMXPath($clone); - $serverCallbacks = $clonePath->query("//serverCallback|hooks"); - foreach ($serverCallbacks as $callback) { - $callback->parentNode->removeChild($callback); - } - $START_PARAMETERS["PRELOADED_REGISTRY"] = XMLWriter::replaceAjxpXmlKeywords($clone->saveXML()); - } - - $JSON_START_PARAMETERS = json_encode($START_PARAMETERS); - $crtTheme = $this->pluginConf["GUI_THEME"]; - $additionalFrameworks = $this->getFilteredOption("JS_RESOURCES_BEFORE"); - $ADDITIONAL_FRAMEWORKS = ""; - if( !empty($additionalFrameworks) ){ - $frameworkList = explode(",", $additionalFrameworks); - foreach($frameworkList as $index => $framework){ - $frameworkList[$index] = ''."\n"; - } - $ADDITIONAL_FRAMEWORKS = implode("", $frameworkList); - } - if (ConfService::getConf("JS_DEBUG")) { - if (!isSet($mess)) { - $mess = ConfService::getMessages(); - } - if (is_file(AJXP_INSTALL_PATH."/plugins/gui.ajax/res/themes/$crtTheme/html/gui_debug.html")) { - include(AJXP_INSTALL_PATH."/plugins/gui.ajax/res/themes/$crtTheme/html/gui_debug.html"); - } else { - include(AJXP_INSTALL_PATH."/plugins/gui.ajax/res/html/gui_debug.html"); - } - } else { - if (is_file(AJXP_INSTALL_PATH."/plugins/gui.ajax/res/themes/$crtTheme/html/gui.html")) { - $content = file_get_contents(AJXP_INSTALL_PATH."/plugins/gui.ajax/res/themes/$crtTheme/html/gui.html"); - } else { - $content = file_get_contents(AJXP_INSTALL_PATH."/plugins/gui.ajax/res/html/gui.html"); - } - if (preg_match('/MSIE 7/',$_SERVER['HTTP_USER_AGENT'])){ - $ADDITIONAL_FRAMEWORKS = ""; - } - $content = str_replace("AJXP_ADDITIONAL_JS_FRAMEWORKS", $ADDITIONAL_FRAMEWORKS, $content); - $content = XMLWriter::replaceAjxpXmlKeywords($content, false); - $content = str_replace("AJXP_REBASE", isSet($START_PARAMETERS["REBASE"])?'':"", $content); - if ($JSON_START_PARAMETERS) { - $content = str_replace("//AJXP_JSON_START_PARAMETERS", "startParameters = ".$JSON_START_PARAMETERS.";", $content); - } - print($content); - } - break; - //------------------------------------ - // GET CONFIG FOR BOOT - //------------------------------------ - case "get_boot_conf": - - $out = array(); - Utils::parseApplicationGetParameters($_GET, $out, $_SESSION); - $config = $this->computeBootConf(); - header("Content-type:application/json;charset=UTF-8"); - print(json_encode($config)); - - break; - + default; break; } diff --git a/core/src/plugins/gui.ajax/manifest.xml b/core/src/plugins/gui.ajax/manifest.xml index 9107da09c3..69dddeaaa7 100644 --- a/core/src/plugins/gui.ajax/manifest.xml +++ b/core/src/plugins/gui.ajax/manifest.xml @@ -191,7 +191,7 @@ - +