aboutsummaryrefslogtreecommitdiffhomepage
path: root/index.php
diff options
context:
space:
mode:
Diffstat (limited to 'index.php')
-rw-r--r--index.php534
1 files changed, 6 insertions, 528 deletions
diff --git a/index.php b/index.php
index a07de74d..2737c22c 100644
--- a/index.php
+++ b/index.php
@@ -61,30 +61,15 @@ require_once 'application/TimeZone.php';
61require_once 'application/Utils.php'; 61require_once 'application/Utils.php';
62 62
63use Shaarli\ApplicationUtils; 63use Shaarli\ApplicationUtils;
64use Shaarli\Bookmark\Bookmark;
65use Shaarli\Bookmark\BookmarkFileService; 64use Shaarli\Bookmark\BookmarkFileService;
66use Shaarli\Bookmark\BookmarkFilter;
67use Shaarli\Bookmark\BookmarkServiceInterface;
68use Shaarli\Bookmark\Exception\BookmarkNotFoundException;
69use Shaarli\Config\ConfigManager; 65use Shaarli\Config\ConfigManager;
70use Shaarli\Container\ContainerBuilder; 66use Shaarli\Container\ContainerBuilder;
71use Shaarli\Feed\CachedPage;
72use Shaarli\Feed\FeedBuilder;
73use Shaarli\Formatter\BookmarkMarkdownFormatter;
74use Shaarli\Formatter\FormatterFactory;
75use Shaarli\History; 67use Shaarli\History;
76use Shaarli\Languages; 68use Shaarli\Languages;
77use Shaarli\Netscape\NetscapeBookmarkUtils;
78use Shaarli\Plugin\PluginManager; 69use Shaarli\Plugin\PluginManager;
79use Shaarli\Render\PageBuilder; 70use Shaarli\Render\PageBuilder;
80use Shaarli\Render\PageCacheManager;
81use Shaarli\Render\ThemeUtils;
82use Shaarli\Router;
83use Shaarli\Security\LoginManager; 71use Shaarli\Security\LoginManager;
84use Shaarli\Security\SessionManager; 72use Shaarli\Security\SessionManager;
85use Shaarli\Thumbnailer;
86use Shaarli\Updater\Updater;
87use Shaarli\Updater\UpdaterUtils;
88use Slim\App; 73use Slim\App;
89 74
90// Ensure the PHP version is supported 75// Ensure the PHP version is supported
@@ -196,20 +181,6 @@ if (! is_file($conf->getConfigFileExt())) {
196 181
197$loginManager->checkLoginState($_COOKIE, $clientIpId); 182$loginManager->checkLoginState($_COOKIE, $clientIpId);
198 183
199/**
200 * Adapter function to ensure compatibility with third-party templates
201 *
202 * @see https://github.com/shaarli/Shaarli/pull/1086
203 *
204 * @return bool true when the user is logged in, false otherwise
205 */
206function isLoggedIn()
207{
208 global $loginManager;
209 return $loginManager->isLoggedIn();
210}
211
212
213// ------------------------------------------------------------------------------------------ 184// ------------------------------------------------------------------------------------------
214// Process login form: Check if login/password is correct. 185// Process login form: Check if login/password is correct.
215if (isset($_POST['login'])) { 186if (isset($_POST['login'])) {
@@ -301,473 +272,6 @@ if (!isset($_SESSION['tokens'])) {
301} 272}
302 273
303/** 274/**
304 * Renders the linklist
305 *
306 * @param pageBuilder $PAGE pageBuilder instance.
307 * @param BookmarkServiceInterface $linkDb instance.
308 * @param ConfigManager $conf Configuration Manager instance.
309 * @param PluginManager $pluginManager Plugin Manager instance.
310 */
311function showLinkList($PAGE, $linkDb, $conf, $pluginManager, $loginManager)
312{
313 buildLinkList($PAGE, $linkDb, $conf, $pluginManager, $loginManager);
314 $PAGE->renderPage('linklist');
315}
316
317/**
318 * Render HTML page (according to URL parameters and user rights)
319 *
320 * @param ConfigManager $conf Configuration Manager instance.
321 * @param PluginManager $pluginManager Plugin Manager instance,
322 * @param BookmarkServiceInterface $bookmarkService
323 * @param History $history instance
324 * @param SessionManager $sessionManager SessionManager instance
325 * @param LoginManager $loginManager LoginManager instance
326 */
327function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionManager, $loginManager)
328{
329 $pageCacheManager = new PageCacheManager($conf->get('resource.page_cache'), $loginManager->isLoggedIn());
330 $updater = new Updater(
331 UpdaterUtils::read_updates_file($conf->get('resource.updates')),
332 $bookmarkService,
333 $conf,
334 $loginManager->isLoggedIn()
335 );
336 try {
337 $newUpdates = $updater->update();
338 if (! empty($newUpdates)) {
339 UpdaterUtils::write_updates_file(
340 $conf->get('resource.updates'),
341 $updater->getDoneUpdates()
342 );
343
344 $pageCacheManager->invalidateCaches();
345 }
346 } catch (Exception $e) {
347 die($e->getMessage());
348 }
349
350 $PAGE = new PageBuilder($conf, $_SESSION, $bookmarkService, $sessionManager->generateToken(), $loginManager->isLoggedIn());
351 $PAGE->assign('linkcount', $bookmarkService->count(BookmarkFilter::$ALL));
352 $PAGE->assign('privateLinkcount', $bookmarkService->count(BookmarkFilter::$PRIVATE));
353 $PAGE->assign('plugin_errors', $pluginManager->getErrors());
354
355 // Determine which page will be rendered.
356 $query = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : '';
357 $targetPage = Router::findPage($query, $_GET, $loginManager->isLoggedIn());
358
359 if (// if the user isn't logged in
360 !$loginManager->isLoggedIn() &&
361 // and Shaarli doesn't have public content...
362 $conf->get('privacy.hide_public_links') &&
363 // and is configured to enforce the login
364 $conf->get('privacy.force_login') &&
365 // and the current page isn't already the login page
366 $targetPage !== Router::$PAGE_LOGIN &&
367 // and the user is not requesting a feed (which would lead to a different content-type as expected)
368 $targetPage !== Router::$PAGE_FEED_ATOM &&
369 $targetPage !== Router::$PAGE_FEED_RSS
370 ) {
371 // force current page to be the login page
372 $targetPage = Router::$PAGE_LOGIN;
373 }
374
375 // Call plugin hooks for header, footer and includes, specifying which page will be rendered.
376 // Then assign generated data to RainTPL.
377 $common_hooks = array(
378 'includes',
379 'header',
380 'footer',
381 );
382
383 foreach ($common_hooks as $name) {
384 $plugin_data = array();
385 $pluginManager->executeHooks(
386 'render_' . $name,
387 $plugin_data,
388 array(
389 'target' => $targetPage,
390 'loggedin' => $loginManager->isLoggedIn()
391 )
392 );
393 $PAGE->assign('plugins_' . $name, $plugin_data);
394 }
395
396 // -------- Display login form.
397 if ($targetPage == Router::$PAGE_LOGIN) {
398 header('Location: ./login');
399 exit;
400 }
401 // -------- User wants to logout.
402 if (isset($_SERVER['QUERY_STRING']) && startsWith($_SERVER['QUERY_STRING'], 'do=logout')) {
403 header('Location: ./logout');
404 exit;
405 }
406
407 // -------- Picture wall
408 if ($targetPage == Router::$PAGE_PICWALL) {
409 header('Location: ./picture-wall');
410 exit;
411 }
412
413 // -------- Tag cloud
414 if ($targetPage == Router::$PAGE_TAGCLOUD) {
415 header('Location: ./tags/cloud');
416 exit;
417 }
418
419 // -------- Tag list
420 if ($targetPage == Router::$PAGE_TAGLIST) {
421 header('Location: ./tags/list');
422 exit;
423 }
424
425 // Daily page.
426 if ($targetPage == Router::$PAGE_DAILY) {
427 $dayParam = !empty($_GET['day']) ? '?day=' . escape($_GET['day']) : '';
428 header('Location: ./daily'. $dayParam);
429 exit;
430 }
431
432 // ATOM and RSS feed.
433 if ($targetPage == Router::$PAGE_FEED_ATOM || $targetPage == Router::$PAGE_FEED_RSS) {
434 $feedType = $targetPage == Router::$PAGE_FEED_RSS ? FeedBuilder::$FEED_RSS : FeedBuilder::$FEED_ATOM;
435
436 header('Location: ./feed/'. $feedType .'?'. http_build_query($_GET));
437 exit;
438 }
439
440 // Display opensearch plugin (XML)
441 if ($targetPage == Router::$PAGE_OPENSEARCH) {
442 header('Location: ./open-search');
443 exit;
444 }
445
446 // -------- User clicks on a tag in a link: The tag is added to the list of searched tags (searchtags=...)
447 if (isset($_GET['addtag'])) {
448 header('Location: ./add-tag/'. $_GET['addtag']);
449 exit;
450 }
451
452 // -------- User clicks on a tag in result count: Remove the tag from the list of searched tags (searchtags=...)
453 if (isset($_GET['removetag'])) {
454 header('Location: ./remove-tag/'. $_GET['removetag']);
455 exit;
456 }
457
458 // -------- User wants to change the number of bookmarks per page (linksperpage=...)
459 if (isset($_GET['linksperpage'])) {
460 header('Location: ./links-per-page?nb='. $_GET['linksperpage']);
461 exit;
462 }
463
464 // -------- User wants to see only private bookmarks (toggle)
465 if (isset($_GET['visibility'])) {
466 header('Location: ./visibility/'. $_GET['visibility']);
467 exit;
468 }
469
470 // -------- User wants to see only untagged bookmarks (toggle)
471 if (isset($_GET['untaggedonly'])) {
472 header('Location: ./untagged-only');
473 exit;
474 }
475
476 // -------- Handle other actions allowed for non-logged in users:
477 if (!$loginManager->isLoggedIn()) {
478 // User tries to post new link but is not logged in:
479 // Show login screen, then redirect to ?post=...
480 if (isset($_GET['post'])) {
481 header( // Redirect to login page, then back to post link.
482 'Location: ./login?post='.urlencode($_GET['post']).
483 (!empty($_GET['title'])?'&title='.urlencode($_GET['title']):'').
484 (!empty($_GET['description'])?'&description='.urlencode($_GET['description']):'').
485 (!empty($_GET['tags'])?'&tags='.urlencode($_GET['tags']):'').
486 (!empty($_GET['source'])?'&source='.urlencode($_GET['source']):'')
487 );
488 exit;
489 }
490
491 showLinkList($PAGE, $bookmarkService, $conf, $pluginManager, $loginManager);
492 if (isset($_GET['edit_link'])) {
493 header('Location: ./login?edit_link='. escape($_GET['edit_link']));
494 exit;
495 }
496
497 exit; // Never remove this one! All operations below are reserved for logged in user.
498 }
499
500 // -------- All other functions are reserved for the registered user:
501
502 // TODO: Remove legacy admin route redirections. We'll only keep public URL.
503
504 // -------- Display the Tools menu if requested (import/export/bookmarklet...)
505 if ($targetPage == Router::$PAGE_TOOLS) {
506 header('Location: ./admin/tools');
507 exit;
508 }
509
510 // -------- User wants to change his/her password.
511 if ($targetPage == Router::$PAGE_CHANGEPASSWORD) {
512 header('Location: ./admin/password');
513 exit;
514 }
515
516 // -------- User wants to change configuration
517 if ($targetPage == Router::$PAGE_CONFIGURE) {
518 header('Location: ./admin/configure');
519 exit;
520 }
521
522 // -------- User wants to rename a tag or delete it
523 if ($targetPage == Router::$PAGE_CHANGETAG) {
524 header('Location: ./admin/tags');
525 exit;
526 }
527
528 // -------- User wants to add a link without using the bookmarklet: Show form.
529 if ($targetPage == Router::$PAGE_ADDLINK) {
530 header('Location: ./admin/shaare');
531 exit;
532 }
533
534 // -------- User clicked the "Save" button when editing a link: Save link to database.
535 if (isset($_POST['save_edit'])) {
536 // This route is no longer supported in legacy mode
537 header('Location: ./');
538 exit;
539 }
540
541 // -------- User clicked the "Delete" button when editing a link: Delete link from database.
542 if ($targetPage == Router::$PAGE_DELETELINK) {
543 $ids = $_GET['lf_linkdate'] ?? '';
544 $token = $_GET['token'] ?? '';
545
546 header('Location: ./admin/shaare/delete?id=' . $ids . '&token=' . $token);
547 exit;
548 }
549
550 // -------- User clicked either "Set public" or "Set private" bulk operation
551 if ($targetPage == Router::$PAGE_CHANGE_VISIBILITY) {
552 header('Location: ./admin/shaare/visibility?id=' . $_GET['token']);
553 exit;
554 }
555
556 // -------- User clicked the "EDIT" button on a link: Display link edit form.
557 if (isset($_GET['edit_link'])) {
558 $id = (int) escape($_GET['edit_link']);
559 header('Location: ./admin/shaare/' . $id);
560 exit;
561 }
562
563 // -------- User want to post a new link: Display link edit form.
564 if (isset($_GET['post'])) {
565 header('Location: ./admin/shaare?' . http_build_query($_GET));
566 exit;
567 }
568
569 if ($targetPage == Router::$PAGE_PINLINK) {
570 // This route is no longer supported in legacy mode
571 header('Location: ./');
572 exit;
573 }
574
575 if ($targetPage == Router::$PAGE_EXPORT) {
576 header('Location: ./admin/export');
577 exit;
578 }
579
580 if ($targetPage == Router::$PAGE_IMPORT) {
581 header('Location: ./admin/import');
582 exit;
583 }
584
585 // Plugin administration page
586 if ($targetPage == Router::$PAGE_PLUGINSADMIN) {
587 header('Location: ./admin/plugins');
588 exit;
589 }
590
591 // Plugin administration form action
592 if ($targetPage == Router::$PAGE_SAVE_PLUGINSADMIN) {
593 // This route is no longer supported in legacy mode
594 header('Location: ./admin/plugins');
595 exit;
596 }
597
598 // Get a fresh token
599 if ($targetPage == Router::$GET_TOKEN) {
600 header('Location: ./admin/token');
601 exit;
602 }
603
604 // -------- Thumbnails Update
605 if ($targetPage == Router::$PAGE_THUMBS_UPDATE) {
606 header('Location: ./admin/thumbnails');
607 exit;
608 }
609
610 // -------- Single Thumbnail Update
611 if ($targetPage == Router::$AJAX_THUMB_UPDATE) {
612 // This route is no longer supported in legacy mode
613 http_response_code(404);
614 exit;
615 }
616
617 // -------- Otherwise, simply display search form and bookmarks:
618 showLinkList($PAGE, $bookmarkService, $conf, $pluginManager, $loginManager);
619 exit;
620}
621
622/**
623 * Template for the list of bookmarks (<div id="linklist">)
624 * This function fills all the necessary fields in the $PAGE for the template 'linklist.html'
625 *
626 * @param pageBuilder $PAGE pageBuilder instance.
627 * @param BookmarkServiceInterface $linkDb LinkDB instance.
628 * @param ConfigManager $conf Configuration Manager instance.
629 * @param PluginManager $pluginManager Plugin Manager instance.
630 * @param LoginManager $loginManager LoginManager instance
631 */
632function buildLinkList($PAGE, $linkDb, $conf, $pluginManager, $loginManager)
633{
634 $factory = new FormatterFactory($conf, $loginManager->isLoggedIn());
635 $formatter = $factory->getFormatter();
636
637 // Used in templates
638 if (isset($_GET['searchtags'])) {
639 if (! empty($_GET['searchtags'])) {
640 $searchtags = escape(normalize_spaces($_GET['searchtags']));
641 } else {
642 $searchtags = false;
643 }
644 } else {
645 $searchtags = '';
646 }
647 $searchterm = !empty($_GET['searchterm']) ? escape(normalize_spaces($_GET['searchterm'])) : '';
648
649 // Smallhash filter
650 if (! empty($_SERVER['QUERY_STRING'])
651 && preg_match('/^[a-zA-Z0-9-_@]{6}($|&|#)/', $_SERVER['QUERY_STRING'])) {
652 try {
653 $linksToDisplay = $linkDb->findByHash($_SERVER['QUERY_STRING']);
654 } catch (BookmarkNotFoundException $e) {
655 $PAGE->render404($e->getMessage());
656 exit;
657 }
658 } else {
659 // Filter bookmarks according search parameters.
660 $visibility = ! empty($_SESSION['visibility']) ? $_SESSION['visibility'] : null;
661 $request = [
662 'searchtags' => $searchtags,
663 'searchterm' => $searchterm,
664 ];
665 $linksToDisplay = $linkDb->search($request, $visibility, false, !empty($_SESSION['untaggedonly']));
666 }
667
668 // ---- Handle paging.
669 $keys = array();
670 foreach ($linksToDisplay as $key => $value) {
671 $keys[] = $key;
672 }
673
674 // Select articles according to paging.
675 $pagecount = ceil(count($keys) / $_SESSION['LINKS_PER_PAGE']);
676 $pagecount = $pagecount == 0 ? 1 : $pagecount;
677 $page= empty($_GET['page']) ? 1 : intval($_GET['page']);
678 $page = $page < 1 ? 1 : $page;
679 $page = $page > $pagecount ? $pagecount : $page;
680 // Start index.
681 $i = ($page-1) * $_SESSION['LINKS_PER_PAGE'];
682 $end = $i + $_SESSION['LINKS_PER_PAGE'];
683
684 $thumbnailsEnabled = $conf->get('thumbnails.mode', Thumbnailer::MODE_NONE) !== Thumbnailer::MODE_NONE;
685 if ($thumbnailsEnabled) {
686 $thumbnailer = new Thumbnailer($conf);
687 }
688
689 $linkDisp = array();
690 while ($i<$end && $i<count($keys)) {
691 $link = $formatter->format($linksToDisplay[$keys[$i]]);
692
693 // Logged in, thumbnails enabled, not a note,
694 // and (never retrieved yet or no valid cache file)
695 if ($loginManager->isLoggedIn()
696 && $thumbnailsEnabled
697 && !$linksToDisplay[$keys[$i]]->isNote()
698 && $linksToDisplay[$keys[$i]]->getThumbnail() !== false
699 && ! is_file($linksToDisplay[$keys[$i]]->getThumbnail())
700 ) {
701 $linksToDisplay[$keys[$i]]->setThumbnail($thumbnailer->get($link['url']));
702 $linkDb->set($linksToDisplay[$keys[$i]], false);
703 $updateDB = true;
704 $link['thumbnail'] = $linksToDisplay[$keys[$i]]->getThumbnail();
705 }
706
707 // Check for both signs of a note: starting with ? and 7 chars long.
708// if ($link['url'][0] === '?' && strlen($link['url']) === 7) {
709// $link['url'] = index_url($_SERVER) . $link['url'];
710// }
711
712 $linkDisp[$keys[$i]] = $link;
713 $i++;
714 }
715
716 // If we retrieved new thumbnails, we update the database.
717 if (!empty($updateDB)) {
718 $linkDb->save();
719 }
720
721 // Compute paging navigation
722 $searchtagsUrl = $searchtags === '' ? '' : '&searchtags=' . urlencode($searchtags);
723 $searchtermUrl = empty($searchterm) ? '' : '&searchterm=' . urlencode($searchterm);
724 $previous_page_url = '';
725 if ($i != count($keys)) {
726 $previous_page_url = '?page=' . ($page+1) . $searchtermUrl . $searchtagsUrl;
727 }
728 $next_page_url='';
729 if ($page>1) {
730 $next_page_url = '?page=' . ($page-1) . $searchtermUrl . $searchtagsUrl;
731 }
732
733 // Fill all template fields.
734 $data = array(
735 'previous_page_url' => $previous_page_url,
736 'next_page_url' => $next_page_url,
737 'page_current' => $page,
738 'page_max' => $pagecount,
739 'result_count' => count($linksToDisplay),
740 'search_term' => $searchterm,
741 'search_tags' => $searchtags,
742 'visibility' => ! empty($_SESSION['visibility']) ? $_SESSION['visibility'] : '',
743 'links' => $linkDisp,
744 );
745
746 // If there is only a single link, we change on-the-fly the title of the page.
747 if (count($linksToDisplay) == 1) {
748 $data['pagetitle'] = $linksToDisplay[$keys[0]]->getTitle() .' - '. $conf->get('general.title');
749 } elseif (! empty($searchterm) || ! empty($searchtags)) {
750 $data['pagetitle'] = t('Search: ');
751 $data['pagetitle'] .= ! empty($searchterm) ? $searchterm .' ' : '';
752 $bracketWrap = function ($tag) {
753 return '['. $tag .']';
754 };
755 $data['pagetitle'] .= ! empty($searchtags)
756 ? implode(' ', array_map($bracketWrap, preg_split('/\s+/', $searchtags))).' '
757 : '';
758 $data['pagetitle'] .= '- '. $conf->get('general.title');
759 }
760
761 $pluginManager->executeHooks('render_linklist', $data, array('loggedin' => $loginManager->isLoggedIn()));
762
763 foreach ($data as $key => $value) {
764 $PAGE->assign($key, $value);
765 }
766
767 return;
768}
769
770/**
771 * Installation 275 * Installation
772 * This function should NEVER be called if the file data/config.php exists. 276 * This function should NEVER be called if the file data/config.php exists.
773 * 277 *
@@ -882,19 +386,6 @@ if (!isset($_SESSION['LINKS_PER_PAGE'])) {
882 $_SESSION['LINKS_PER_PAGE'] = $conf->get('general.links_per_page', 20); 386 $_SESSION['LINKS_PER_PAGE'] = $conf->get('general.links_per_page', 20);
883} 387}
884 388
885try {
886 $history = new History($conf->get('resource.history'));
887} catch (Exception $e) {
888 die($e->getMessage());
889}
890
891$linkDb = new BookmarkFileService($conf, $history, $loginManager->isLoggedIn());
892
893if (isset($_SERVER['QUERY_STRING']) && startsWith($_SERVER['QUERY_STRING'], 'do=dailyrss')) {
894 header('Location: ./daily-rss');
895 exit;
896}
897
898$containerBuilder = new ContainerBuilder($conf, $sessionManager, $loginManager); 389$containerBuilder = new ContainerBuilder($conf, $sessionManager, $loginManager);
899$container = $containerBuilder->build(); 390$container = $containerBuilder->build();
900$app = new App($container); 391$app = new App($container);
@@ -918,13 +409,15 @@ $app->group('/api/v1', function () {
918 409
919$app->group('', function () { 410$app->group('', function () {
920 /* -- PUBLIC --*/ 411 /* -- PUBLIC --*/
921 $this->get('/login', '\Shaarli\Front\Controller\Visitor\LoginController:index'); 412 $this->get('/', '\Shaarli\Front\Controller\Visitor\BookmarkListController:index');
413 $this->get('/shaare/{hash}', '\Shaarli\Front\Controller\Visitor\BookmarkListController:permalink');
414 $this->get('/login', '\Shaarli\Front\Controller\Visitor\LoginController:index')->setName('login');
922 $this->get('/picture-wall', '\Shaarli\Front\Controller\Visitor\PictureWallController:index'); 415 $this->get('/picture-wall', '\Shaarli\Front\Controller\Visitor\PictureWallController:index');
923 $this->get('/tags/cloud', '\Shaarli\Front\Controller\Visitor\TagCloudController:cloud'); 416 $this->get('/tags/cloud', '\Shaarli\Front\Controller\Visitor\TagCloudController:cloud');
924 $this->get('/tags/list', '\Shaarli\Front\Controller\Visitor\TagCloudController:list'); 417 $this->get('/tags/list', '\Shaarli\Front\Controller\Visitor\TagCloudController:list');
925 $this->get('/daily', '\Shaarli\Front\Controller\Visitor\DailyController:index'); 418 $this->get('/daily', '\Shaarli\Front\Controller\Visitor\DailyController:index');
926 $this->get('/daily-rss', '\Shaarli\Front\Controller\Visitor\DailyController:rss'); 419 $this->get('/daily-rss', '\Shaarli\Front\Controller\Visitor\DailyController:rss')->setName('rss');
927 $this->get('/feed/atom', '\Shaarli\Front\Controller\Visitor\FeedController:atom'); 420 $this->get('/feed/atom', '\Shaarli\Front\Controller\Visitor\FeedController:atom')->setName('atom');
928 $this->get('/feed/rss', '\Shaarli\Front\Controller\Visitor\FeedController:rss'); 421 $this->get('/feed/rss', '\Shaarli\Front\Controller\Visitor\FeedController:rss');
929 $this->get('/open-search', '\Shaarli\Front\Controller\Visitor\OpenSearchController:index'); 422 $this->get('/open-search', '\Shaarli\Front\Controller\Visitor\OpenSearchController:index');
930 423
@@ -967,19 +460,4 @@ $app->group('', function () {
967 460
968$response = $app->run(true); 461$response = $app->run(true);
969 462
970// Hack to make Slim and Shaarli router work together: 463$app->respond($response);
971// If a Slim route isn't found and NOT API call, we call renderPage().
972if ($response->getStatusCode() == 404 && strpos($_SERVER['REQUEST_URI'], '/api/v1') === false) {
973 // We use UTF-8 for proper international characters handling.
974 header('Content-Type: text/html; charset=utf-8');
975 renderPage($conf, $pluginManager, $linkDb, $history, $sessionManager, $loginManager);
976} else {
977 $response = $response
978 ->withHeader('Access-Control-Allow-Origin', '*')
979 ->withHeader(
980 'Access-Control-Allow-Headers',
981 'X-Requested-With, Content-Type, Accept, Origin, Authorization'
982 )
983 ->withHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
984 $app->respond($response);
985}