static function handleAdminPage()
 {
     $app = App::$instance;
     $path = (string) $app->request->path;
     if ($path === Options::$adminPagesPathPrefix) {
         if (!$app->bearCMS->data->users->hasUsers()) {
             return new App\Response\TemporaryRedirect($app->request->base . Options::$adminPagesPathPrefix . 'firstrun/');
         }
     } elseif ($path === Options::$adminPagesPathPrefix . 'firstrun/') {
         if ($app->bearCMS->data->users->hasUsers()) {
             return new App\Response\TemporaryRedirect($app->request->base . Options::$adminPagesPathPrefix);
         }
     }
     $arguments = [];
     $arguments['path'] = $path;
     $data = Server::call('adminpage', $arguments, true);
     if (isset($data['result'])) {
         if ($data['result'] === 'notFound') {
             return new App\Response\NotFound();
         } elseif (is_array($data['result']) && isset($data['result']['content'])) {
             $content = $data['result']['content'];
             $content = Server::updateAssetsUrls($content, false);
             $response = new App\Response\HTML($content);
             $response->enableBearCMS = true;
             $response->bearCMSSystemPage = true;
             return $response;
         }
     }
     return new App\Response\TemporaryUnavailable();
 }
Example #2
0
            }
            if (is_array($elementsEditorData) && isset($elementsEditorData['result']) && is_array($elementsEditorData['result']) && isset($elementsEditorData['result']['content'])) {
                $domDocument = new HTML5DOMDocument();
                $domDocument->loadHTML($content);
                $domDocument->insertHTML($elementsEditorData['result']['content']);
                $content = $domDocument->saveHTML();
            } else {
                $response = new App\Response\TemporaryUnavailable();
            }
        }
        // It's needed even when there is no editable zone on the current page (editing a blog post for instance)
        $domDocument = new HTML5DOMDocument();
        $domDocument->loadHTML($content);
        $domDocument->insertHTML('<html><body><script src="' . htmlentities($context->assets->getUrl('assets/HTML5DOMDocument.min.js')) . '"></script></body></html>');
        $content = $domDocument->saveHTML();
        $content = Server::updateAssetsUrls($content, false);
        if (strpos($content, '{body}') !== false) {
            $content = str_replace('{body}', '<component src="data:base64,' . base64_encode($response->content) . '"/>', $content);
        } elseif (strpos($content, '{jsonEncodedBody}') !== false) {
            $content = str_replace('{jsonEncodedBody}', json_encode($app->components->process($response->content)), $content);
        }
        $response->content = $app->components->process($content);
    } else {
        $response = new App\Response\TemporaryUnavailable();
    }
}, ['priority' => 1000]);
if (Options::hasServer() && (Options::hasFeature('USERS') || Options::hasFeature('USERS_LOGIN_*'))) {
    $app->hooks->add('responseCreated', function () {
        Cookies::update();
    }, ['priority' => 1001]);
}