X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=index.php;h=423a68f4bfdce2735d132bca7353380cd7bb268e;hb=72caf4e84c412ab6a4181b83a96dbef8ebb3c65a;hp=d3cb33d380b69e69087d1d4c995406f69ae6d718;hpb=bee33239ed444f9724422fe5234cd79997500519;p=github%2Fshaarli%2FShaarli.git diff --git a/index.php b/index.php index d3cb33d3..423a68f4 100644 --- a/index.php +++ b/index.php @@ -53,7 +53,6 @@ require_once __DIR__ . '/vendor/autoload.php'; // Shaarli library require_once 'application/bookmark/LinkUtils.php'; require_once 'application/config/ConfigPlugin.php'; -require_once 'application/feed/Cache.php'; require_once 'application/http/HttpUtils.php'; require_once 'application/http/UrlUtils.php'; require_once 'application/updater/UpdaterUtils.php'; @@ -78,6 +77,7 @@ use Shaarli\Languages; use Shaarli\Netscape\NetscapeBookmarkUtils; use Shaarli\Plugin\PluginManager; use Shaarli\Render\PageBuilder; +use Shaarli\Render\PageCacheManager; use Shaarli\Render\ThemeUtils; use Shaarli\Router; use Shaarli\Security\LoginManager; @@ -530,6 +530,7 @@ function showLinkList($PAGE, $linkDb, $conf, $pluginManager, $loginManager) */ function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionManager, $loginManager) { + $pageCacheManager = new PageCacheManager($conf->get('resource.page_cache')); $updater = new Updater( UpdaterUtils::read_updates_file($conf->get('resource.updates')), $bookmarkService, @@ -543,6 +544,8 @@ function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionM $conf->get('resource.updates'), $updater->getDoneUpdates() ); + + $pageCacheManager->invalidateCaches(); } } catch (Exception $e) { die($e->getMessage()); @@ -601,94 +604,19 @@ function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionM } // -------- User wants to logout. if (isset($_SERVER['QUERY_STRING']) && startsWith($_SERVER['QUERY_STRING'], 'do=logout')) { - invalidateCaches($conf->get('resource.page_cache')); - $sessionManager->logout(); - setcookie(LoginManager::$STAY_SIGNED_IN_COOKIE, 'false', 0, WEB_PATH); - header('Location: ?'); + header('Location: ./logout'); exit; } // -------- Picture wall if ($targetPage == Router::$PAGE_PICWALL) { - $PAGE->assign('pagetitle', t('Picture wall') .' - '. $conf->get('general.title', 'Shaarli')); - if (! $conf->get('thumbnails.mode', Thumbnailer::MODE_NONE) === Thumbnailer::MODE_NONE) { - $PAGE->assign('linksToDisplay', []); - $PAGE->renderPage('picwall'); - exit; - } - - // Optionally filter the results: - $links = $bookmarkService->search($_GET); - $linksToDisplay = []; - - // Get only bookmarks which have a thumbnail. - // Note: we do not retrieve thumbnails here, the request is too heavy. - $factory = new FormatterFactory($conf, $loginManager->isLoggedIn()); - $formatter = $factory->getFormatter(); - foreach ($links as $key => $link) { - if ($link->getThumbnail() !== false) { - $linksToDisplay[] = $formatter->format($link); - } - } - - $data = [ - 'linksToDisplay' => $linksToDisplay, - ]; - $pluginManager->executeHooks('render_picwall', $data, ['loggedin' => $loginManager->isLoggedIn()]); - - foreach ($data as $key => $value) { - $PAGE->assign($key, $value); - } - - $PAGE->renderPage('picwall'); + header('Location: ./picture-wall'); exit; } // -------- Tag cloud if ($targetPage == Router::$PAGE_TAGCLOUD) { - $visibility = ! empty($_SESSION['visibility']) ? $_SESSION['visibility'] : ''; - $filteringTags = isset($_GET['searchtags']) ? explode(' ', $_GET['searchtags']) : []; - $tags = $bookmarkService->bookmarksCountPerTag($filteringTags, $visibility); - - // We sort tags alphabetically, then choose a font size according to count. - // First, find max value. - $maxcount = 0; - foreach ($tags as $value) { - $maxcount = max($maxcount, $value); - } - - alphabetical_sort($tags, false, true); - - $logMaxCount = $maxcount > 1 ? log($maxcount, 30) : 1; - $tagList = array(); - foreach ($tags as $key => $value) { - if (in_array($key, $filteringTags)) { - continue; - } - // Tag font size scaling: - // default 15 and 30 logarithm bases affect scaling, - // 2.2 and 0.8 are arbitrary font sizes in em. - $size = log($value, 15) / $logMaxCount * 2.2 + 0.8; - $tagList[$key] = array( - 'count' => $value, - 'size' => number_format($size, 2, '.', ''), - ); - } - - $searchTags = implode(' ', escape($filteringTags)); - $data = array( - 'search_tags' => $searchTags, - 'tags' => $tagList, - ); - $pluginManager->executeHooks('render_tagcloud', $data, array('loggedin' => $loginManager->isLoggedIn())); - - foreach ($data as $key => $value) { - $PAGE->assign($key, $value); - } - - $searchTags = ! empty($searchTags) ? $searchTags .' - ' : ''; - $PAGE->assign('pagetitle', $searchTags. t('Tag cloud') .' - '. $conf->get('general.title', 'Shaarli')); - $PAGE->renderPage('tag.cloud'); + header('Location: ./tag-cloud'); exit; } @@ -924,7 +852,7 @@ function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionM // Show login screen, then redirect to ?post=... if (isset($_GET['post'])) { header( // Redirect to login page, then back to post link. - 'Location: /login?post='.urlencode($_GET['post']). + 'Location: ./login?post='.urlencode($_GET['post']). (!empty($_GET['title'])?'&title='.urlencode($_GET['title']):''). (!empty($_GET['description'])?'&description='.urlencode($_GET['description']):''). (!empty($_GET['tags'])?'&tags='.urlencode($_GET['tags']):''). @@ -935,7 +863,7 @@ function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionM showLinkList($PAGE, $bookmarkService, $conf, $pluginManager, $loginManager); if (isset($_GET['edit_link'])) { - header('Location: /login?edit_link='. escape($_GET['edit_link'])); + header('Location: ./login?edit_link='. escape($_GET['edit_link'])); exit; } @@ -1059,7 +987,7 @@ function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionM try { $conf->write($loginManager->isLoggedIn()); $history->updateSettings(); - invalidateCaches($conf->get('resource.page_cache')); + $pageCacheManager->invalidateCaches(); } catch (Exception $e) { error_log( 'ERROR while writing config file after configuration update.' . PHP_EOL . @@ -1921,7 +1849,7 @@ if (isset($_SERVER['QUERY_STRING']) && startsWith($_SERVER['QUERY_STRING'], 'do= exit; } -$containerBuilder = new ContainerBuilder($conf, $sessionManager, $loginManager); +$containerBuilder = new ContainerBuilder($conf, $sessionManager, $loginManager, WEB_PATH); $container = $containerBuilder->build(); $app = new App($container); @@ -1944,6 +1872,10 @@ $app->group('/api/v1', function () { $app->group('', function () { $this->get('/login', '\Shaarli\Front\Controller\LoginController:index')->setName('login'); + $this->get('/logout', '\Shaarli\Front\Controller\LogoutController:index')->setName('logout'); + $this->get('/picture-wall', '\Shaarli\Front\Controller\PictureWallController:index')->setName('picwall'); + $this->get('/tag-cloud', '\Shaarli\Front\Controller\TagCloudController:index')->setName('tagcloud'); + $this->get('/add-tag/{newTag}', '\Shaarli\Front\Controller\TagController:addTag')->setName('add-tag'); })->add('\Shaarli\Front\ShaarliMiddleware'); $response = $app->run(true);