aboutsummaryrefslogtreecommitdiffhomepage
path: root/index.php
diff options
context:
space:
mode:
Diffstat (limited to 'index.php')
-rw-r--r--index.php84
1 files changed, 38 insertions, 46 deletions
diff --git a/index.php b/index.php
index 76ad3696..474d9af5 100644
--- a/index.php
+++ b/index.php
@@ -61,29 +61,31 @@ require_once 'application/FileUtils.php';
61require_once 'application/TimeZone.php'; 61require_once 'application/TimeZone.php';
62require_once 'application/Utils.php'; 62require_once 'application/Utils.php';
63 63
64use \Shaarli\ApplicationUtils; 64use Shaarli\ApplicationUtils;
65use Shaarli\Bookmark\BookmarkServiceInterface;
66use \Shaarli\Bookmark\Exception\BookmarkNotFoundException;
67use Shaarli\Bookmark\Bookmark; 65use Shaarli\Bookmark\Bookmark;
68use Shaarli\Bookmark\BookmarkFilter;
69use Shaarli\Bookmark\BookmarkFileService; 66use Shaarli\Bookmark\BookmarkFileService;
70use \Shaarli\Config\ConfigManager; 67use Shaarli\Bookmark\BookmarkFilter;
71use \Shaarli\Feed\CachedPage; 68use Shaarli\Bookmark\BookmarkServiceInterface;
72use \Shaarli\Feed\FeedBuilder; 69use Shaarli\Bookmark\Exception\BookmarkNotFoundException;
70use Shaarli\Config\ConfigManager;
71use Shaarli\Container\ContainerBuilder;
72use Shaarli\Feed\CachedPage;
73use Shaarli\Feed\FeedBuilder;
73use Shaarli\Formatter\BookmarkMarkdownFormatter; 74use Shaarli\Formatter\BookmarkMarkdownFormatter;
74use Shaarli\Formatter\FormatterFactory; 75use Shaarli\Formatter\FormatterFactory;
75use \Shaarli\History; 76use Shaarli\History;
76use \Shaarli\Languages; 77use Shaarli\Languages;
77use \Shaarli\Netscape\NetscapeBookmarkUtils; 78use Shaarli\Netscape\NetscapeBookmarkUtils;
78use \Shaarli\Plugin\PluginManager; 79use Shaarli\Plugin\PluginManager;
79use \Shaarli\Render\PageBuilder; 80use Shaarli\Render\PageBuilder;
80use \Shaarli\Render\ThemeUtils; 81use Shaarli\Render\ThemeUtils;
81use \Shaarli\Router; 82use Shaarli\Router;
82use \Shaarli\Security\LoginManager; 83use Shaarli\Security\LoginManager;
83use \Shaarli\Security\SessionManager; 84use Shaarli\Security\SessionManager;
84use \Shaarli\Thumbnailer; 85use Shaarli\Thumbnailer;
85use \Shaarli\Updater\Updater; 86use Shaarli\Updater\Updater;
86use \Shaarli\Updater\UpdaterUtils; 87use Shaarli\Updater\UpdaterUtils;
88use Slim\App;
87 89
88// Ensure the PHP version is supported 90// Ensure the PHP version is supported
89try { 91try {
@@ -250,7 +252,7 @@ if (isset($_POST['login'])) {
250 252
251 // Optional redirect after login: 253 // Optional redirect after login:
252 if (isset($_GET['post'])) { 254 if (isset($_GET['post'])) {
253 $uri = '?post='. urlencode($_GET['post']); 255 $uri = './?post='. urlencode($_GET['post']);
254 foreach (array('description', 'source', 'title', 'tags') as $param) { 256 foreach (array('description', 'source', 'title', 'tags') as $param) {
255 if (!empty($_GET[$param])) { 257 if (!empty($_GET[$param])) {
256 $uri .= '&'.$param.'='.urlencode($_GET[$param]); 258 $uri .= '&'.$param.'='.urlencode($_GET[$param]);
@@ -261,22 +263,22 @@ if (isset($_POST['login'])) {
261 } 263 }
262 264
263 if (isset($_GET['edit_link'])) { 265 if (isset($_GET['edit_link'])) {
264 header('Location: ?edit_link='. escape($_GET['edit_link'])); 266 header('Location: ./?edit_link='. escape($_GET['edit_link']));
265 exit; 267 exit;
266 } 268 }
267 269
268 if (isset($_POST['returnurl'])) { 270 if (isset($_POST['returnurl'])) {
269 // Prevent loops over login screen. 271 // Prevent loops over login screen.
270 if (strpos($_POST['returnurl'], 'do=login') === false) { 272 if (strpos($_POST['returnurl'], '/login') === false) {
271 header('Location: '. generateLocation($_POST['returnurl'], $_SERVER['HTTP_HOST'])); 273 header('Location: '. generateLocation($_POST['returnurl'], $_SERVER['HTTP_HOST']));
272 exit; 274 exit;
273 } 275 }
274 } 276 }
275 header('Location: ?'); 277 header('Location: ./?');
276 exit; 278 exit;
277 } else { 279 } else {
278 $loginManager->handleFailedLogin($_SERVER); 280 $loginManager->handleFailedLogin($_SERVER);
279 $redir = '&username='. urlencode($_POST['login']); 281 $redir = '?username='. urlencode($_POST['login']);
280 if (isset($_GET['post'])) { 282 if (isset($_GET['post'])) {
281 $redir .= '&post=' . urlencode($_GET['post']); 283 $redir .= '&post=' . urlencode($_GET['post']);
282 foreach (array('description', 'source', 'title', 'tags') as $param) { 284 foreach (array('description', 'source', 'title', 'tags') as $param) {
@@ -286,7 +288,7 @@ if (isset($_POST['login'])) {
286 } 288 }
287 } 289 }
288 // Redirect to login screen. 290 // Redirect to login screen.
289 echo '<script>alert("'. t("Wrong login/password.") .'");document.location=\'?do=login'.$redir.'\';</script>'; 291 echo '<script>alert("'. t("Wrong login/password.") .'");document.location=\'./login'.$redir.'\';</script>';
290 exit; 292 exit;
291 } 293 }
292} 294}
@@ -594,19 +596,7 @@ function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionM
594 596
595 // -------- Display login form. 597 // -------- Display login form.
596 if ($targetPage == Router::$PAGE_LOGIN) { 598 if ($targetPage == Router::$PAGE_LOGIN) {
597 if ($conf->get('security.open_shaarli')) { 599 header('Location: ./login');
598 header('Location: ?');
599 exit;
600 } // No need to login for open Shaarli
601 if (isset($_GET['username'])) {
602 $PAGE->assign('username', escape($_GET['username']));
603 }
604 $PAGE->assign('returnurl', (isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']):''));
605 // add default state of the 'remember me' checkbox
606 $PAGE->assign('remember_user_default', $conf->get('privacy.remember_user_default'));
607 $PAGE->assign('user_can_login', $loginManager->canLogin($_SERVER));
608 $PAGE->assign('pagetitle', t('Login') .' - '. $conf->get('general.title', 'Shaarli'));
609 $PAGE->renderPage('loginform');
610 exit; 600 exit;
611 } 601 }
612 // -------- User wants to logout. 602 // -------- User wants to logout.
@@ -933,7 +923,7 @@ function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionM
933 // Show login screen, then redirect to ?post=... 923 // Show login screen, then redirect to ?post=...
934 if (isset($_GET['post'])) { 924 if (isset($_GET['post'])) {
935 header( // Redirect to login page, then back to post link. 925 header( // Redirect to login page, then back to post link.
936 'Location: ?do=login&post='.urlencode($_GET['post']). 926 'Location: /login?post='.urlencode($_GET['post']).
937 (!empty($_GET['title'])?'&title='.urlencode($_GET['title']):''). 927 (!empty($_GET['title'])?'&title='.urlencode($_GET['title']):'').
938 (!empty($_GET['description'])?'&description='.urlencode($_GET['description']):''). 928 (!empty($_GET['description'])?'&description='.urlencode($_GET['description']):'').
939 (!empty($_GET['tags'])?'&tags='.urlencode($_GET['tags']):''). 929 (!empty($_GET['tags'])?'&tags='.urlencode($_GET['tags']):'').
@@ -944,7 +934,7 @@ function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionM
944 934
945 showLinkList($PAGE, $bookmarkService, $conf, $pluginManager, $loginManager); 935 showLinkList($PAGE, $bookmarkService, $conf, $pluginManager, $loginManager);
946 if (isset($_GET['edit_link'])) { 936 if (isset($_GET['edit_link'])) {
947 header('Location: ?do=login&edit_link='. escape($_GET['edit_link'])); 937 header('Location: /login?edit_link='. escape($_GET['edit_link']));
948 exit; 938 exit;
949 } 939 }
950 940
@@ -1900,7 +1890,7 @@ function install($conf, $sessionManager, $loginManager)
1900 echo '<script>alert(' 1890 echo '<script>alert('
1901 .'"Shaarli is now configured. ' 1891 .'"Shaarli is now configured. '
1902 .'Please enter your login/password and start shaaring your bookmarks!"' 1892 .'Please enter your login/password and start shaaring your bookmarks!"'
1903 .');document.location=\'?do=login\';</script>'; 1893 .');document.location=\'./login\';</script>';
1904 exit; 1894 exit;
1905 } 1895 }
1906 1896
@@ -1930,11 +1920,9 @@ if (isset($_SERVER['QUERY_STRING']) && startsWith($_SERVER['QUERY_STRING'], 'do=
1930 exit; 1920 exit;
1931} 1921}
1932 1922
1933$container = new \Slim\Container(); 1923$containerBuilder = new ContainerBuilder($conf, $sessionManager, $loginManager);
1934$container['conf'] = $conf; 1924$container = $containerBuilder->build();
1935$container['plugins'] = $pluginManager; 1925$app = new App($container);
1936$container['history'] = $history;
1937$app = new \Slim\App($container);
1938 1926
1939// REST API routes 1927// REST API routes
1940$app->group('/api/v1', function () { 1928$app->group('/api/v1', function () {
@@ -1953,6 +1941,10 @@ $app->group('/api/v1', function () {
1953 $this->get('/history', '\Shaarli\Api\Controllers\HistoryController:getHistory')->setName('getHistory'); 1941 $this->get('/history', '\Shaarli\Api\Controllers\HistoryController:getHistory')->setName('getHistory');
1954})->add('\Shaarli\Api\ApiMiddleware'); 1942})->add('\Shaarli\Api\ApiMiddleware');
1955 1943
1944$app->group('', function () {
1945 $this->get('/login', '\Shaarli\Front\Controller\LoginController:index')->setName('login');
1946})->add('\Shaarli\Front\ShaarliMiddleware');
1947
1956$response = $app->run(true); 1948$response = $app->run(true);
1957 1949
1958// Hack to make Slim and Shaarli router work together: 1950// Hack to make Slim and Shaarli router work together: