return new App\Response\PermanentRedirect($app->request->base . $app->request->path . '/'); }); } // Register a home page and the dynamic pages handler if (Options::hasFeature('PAGES')) { $app->routes->add('*', function () use($app) { $path = (string) $app->request->path; if ($path === '/') { if (Options::$autoCreateHomePage) { $pageID = 'home'; } else { $pageID = false; } } else { $hasSlash = substr($path, -1) === '/'; $pathsList = InternalData\Pages::getPathsList((Options::hasFeature('USERS') || Options::hasFeature('USERS_LOGIN_*')) && $app->bearCMS->currentUser->exists() ? 'all' : 'published'); if ($hasSlash) { $pageID = array_search($path, $pathsList); } else { $pageID = array_search($path . '/', $pathsList); if ($pageID !== false) { return new App\Response\PermanentRedirect($app->request->base . $app->request->path . '/'); } } } if ($pageID !== false) { $content = '<component src="bearcms-elements" id="bearcms-page-' . $pageID . '" editable="true"/>'; $response = new App\Response\HTML($content); $response->enableBearCMS = true; $response->applyBearCMSTheme = true; if ($pageID !== 'home') {
static function handleSitemap() { $app = App::$instance; $urls = []; $baseUrl = $app->request->base; $addUrl = function ($path) use(&$urls, $baseUrl) { $urls[] = '<url><loc>' . $baseUrl . $path . '</loc></url>'; }; $addUrl('/'); $list = \BearCMS\Internal\Data\Pages::getPathsList('published'); foreach ($list as $path) { $addUrl($path); } $list = \BearCMS\Internal\Data\Blog::getSlugsList('published'); foreach ($list as $slug) { $addUrl(Options::$blogPagesPathPrefix . $slug . '/'); } $response = new App\Response('<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.google.com/schemas/sitemap/0.84">' . implode('', $urls) . '</urlset>'); $response->setContentType('text/xml'); return $response; }