From dec5e0be5fae7b033bdd6b981edcdccf40f2b75b Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Fri, 25 Sep 2020 13:21:02 +0300 Subject: [PATCH] cs fix --- .../Espo/Core/ApplicationRunners/EntryPoint.php | 14 +++++++++++++- application/Espo/EntryPoints/Portal.php | 5 +++++ portal/index.php | 9 ++++++++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/application/Espo/Core/ApplicationRunners/EntryPoint.php b/application/Espo/Core/ApplicationRunners/EntryPoint.php index 2251f3a37f..78616f72eb 100644 --- a/application/Espo/Core/ApplicationRunners/EntryPoint.php +++ b/application/Espo/Core/ApplicationRunners/EntryPoint.php @@ -105,13 +105,16 @@ class EntryPoint implements ApplicationRunner if ($authRequired && !$authNotStrict && !$final) { $portalId = $this->detectPortalId(); + if ($portalId) { $this->runThroughPortal($portalId, $entryPoint, $data); + return; } } $slim = SlimAppFactory::create(); + $slim->setBasePath(Route::detectBasePath()); $slim->add( @@ -164,7 +167,9 @@ class EntryPoint implements ApplicationRunner } ob_start(); + $this->entryPointManager->run($entryPoint, $requestWrapped, $responseWrapped, $data); + $contents = ob_get_clean(); if ($contents) { @@ -180,20 +185,27 @@ class EntryPoint implements ApplicationRunner if (!empty($_GET['portalId'])) { return $_GET['portalId']; } + if (!empty($_COOKIE['auth-token'])) { - $token = $this->entityManager->getRepository('AuthToken')->where(['token' => $_COOKIE['auth-token']])->findOne(); + $token = $this->entityManager + ->getRepository('AuthToken') + ->where(['token' => $_COOKIE['auth-token']]) + ->findOne(); if ($token && $token->get('portalId')) { return $token->get('portalId'); } } + return null; } protected function runThroughPortal(string $portalId, string $entryPoint, ?StdClass $data) { $app = new PortalApplication($portalId); + $app->setClientBasePath($this->clientManager->getBasePath()); + $app->run(EntryPoint::class, (object) [ 'entryPoint' => $entryPoint, 'data' => $data, diff --git a/application/Espo/EntryPoints/Portal.php b/application/Espo/EntryPoints/Portal.php index bf06ed71df..75f6cc6b4f 100644 --- a/application/Espo/EntryPoints/Portal.php +++ b/application/Espo/EntryPoints/Portal.php @@ -68,23 +68,28 @@ class Portal implements EntryPoint if (!$id) { $url = $_SERVER['REQUEST_URI']; + $id = explode('/', $url)[count(explode('/', $_SERVER['SCRIPT_NAME'])) - 1]; if (!isset($id)) { $url = $_SERVER['REDIRECT_URL']; + $id = explode('/', $url)[count(explode('/', $_SERVER['SCRIPT_NAME'])) - 1]; } if (!$id) { $id = $this->config->get('defaultPortalId'); } + if (!$id) { throw new NotFound(); } } $application = new PortalApplication($id); + $application->setClientBasePath($this->clientManager->getBasePath()); + $application->run(Client::class); } } diff --git a/portal/index.php b/portal/index.php index 155c20bbc1..4703d25d44 100644 --- a/portal/index.php +++ b/portal/index.php @@ -50,20 +50,26 @@ if (strpos($requestUri, '=') !== false) { if (!isset($portalId)) { $url = $_SERVER['REDIRECT_URL']; + $portalId = explode('/', $url)[count(explode('/', $_SERVER['SCRIPT_NAME'])) - 1]; } $a = explode('?', $url); + if (substr($a[0], -1) !== '/') { $url = $a[0] . '/'; + if (count($a) > 1) { $url .= '?' . $a[1]; } + header("Location: " . $url); - exit(); + + exit; } $a = explode('?', $requestUri); + $requestUri = rtrim($a[0], '/'); if (strpos($requestUri, '/') !== false) { @@ -76,6 +82,7 @@ if (strpos($requestUri, '/') !== false) { if (!empty($_GET['entryPoint'])) { $app->run(EntryPoint::class); + exit; }