aboutsummaryrefslogtreecommitdiffhomepage
path: root/index.php
diff options
context:
space:
mode:
Diffstat (limited to 'index.php')
-rw-r--r--index.php101
1 files changed, 48 insertions, 53 deletions
diff --git a/index.php b/index.php
index a39fc762..b53b16fe 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 {
@@ -243,12 +245,14 @@ if (isset($_POST['login'])) {
243 } 245 }
244 246
245 // Send cookie with the new expiration date to the browser 247 // Send cookie with the new expiration date to the browser
248 session_destroy();
246 session_set_cookie_params($expirationTime, $cookiedir, $_SERVER['SERVER_NAME']); 249 session_set_cookie_params($expirationTime, $cookiedir, $_SERVER['SERVER_NAME']);
250 session_start();
247 session_regenerate_id(true); 251 session_regenerate_id(true);
248 252
249 // Optional redirect after login: 253 // Optional redirect after login:
250 if (isset($_GET['post'])) { 254 if (isset($_GET['post'])) {
251 $uri = '?post='. urlencode($_GET['post']); 255 $uri = './?post='. urlencode($_GET['post']);
252 foreach (array('description', 'source', 'title', 'tags') as $param) { 256 foreach (array('description', 'source', 'title', 'tags') as $param) {
253 if (!empty($_GET[$param])) { 257 if (!empty($_GET[$param])) {
254 $uri .= '&'.$param.'='.urlencode($_GET[$param]); 258 $uri .= '&'.$param.'='.urlencode($_GET[$param]);
@@ -259,22 +263,22 @@ if (isset($_POST['login'])) {
259 } 263 }
260 264
261 if (isset($_GET['edit_link'])) { 265 if (isset($_GET['edit_link'])) {
262 header('Location: ?edit_link='. escape($_GET['edit_link'])); 266 header('Location: ./?edit_link='. escape($_GET['edit_link']));
263 exit; 267 exit;
264 } 268 }
265 269
266 if (isset($_POST['returnurl'])) { 270 if (isset($_POST['returnurl'])) {
267 // Prevent loops over login screen. 271 // Prevent loops over login screen.
268 if (strpos($_POST['returnurl'], 'do=login') === false) { 272 if (strpos($_POST['returnurl'], '/login') === false) {
269 header('Location: '. generateLocation($_POST['returnurl'], $_SERVER['HTTP_HOST'])); 273 header('Location: '. generateLocation($_POST['returnurl'], $_SERVER['HTTP_HOST']));
270 exit; 274 exit;
271 } 275 }
272 } 276 }
273 header('Location: ?'); 277 header('Location: ./?');
274 exit; 278 exit;
275 } else { 279 } else {
276 $loginManager->handleFailedLogin($_SERVER); 280 $loginManager->handleFailedLogin($_SERVER);
277 $redir = '&username='. urlencode($_POST['login']); 281 $redir = '?username='. urlencode($_POST['login']);
278 if (isset($_GET['post'])) { 282 if (isset($_GET['post'])) {
279 $redir .= '&post=' . urlencode($_GET['post']); 283 $redir .= '&post=' . urlencode($_GET['post']);
280 foreach (array('description', 'source', 'title', 'tags') as $param) { 284 foreach (array('description', 'source', 'title', 'tags') as $param) {
@@ -284,7 +288,7 @@ if (isset($_POST['login'])) {
284 } 288 }
285 } 289 }
286 // Redirect to login screen. 290 // Redirect to login screen.
287 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>';
288 exit; 292 exit;
289 } 293 }
290} 294}
@@ -592,19 +596,7 @@ function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionM
592 596
593 // -------- Display login form. 597 // -------- Display login form.
594 if ($targetPage == Router::$PAGE_LOGIN) { 598 if ($targetPage == Router::$PAGE_LOGIN) {
595 if ($conf->get('security.open_shaarli')) { 599 header('Location: ./login');
596 header('Location: ?');
597 exit;
598 } // No need to login for open Shaarli
599 if (isset($_GET['username'])) {
600 $PAGE->assign('username', escape($_GET['username']));
601 }
602 $PAGE->assign('returnurl', (isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']):''));
603 // add default state of the 'remember me' checkbox
604 $PAGE->assign('remember_user_default', $conf->get('privacy.remember_user_default'));
605 $PAGE->assign('user_can_login', $loginManager->canLogin($_SERVER));
606 $PAGE->assign('pagetitle', t('Login') .' - '. $conf->get('general.title', 'Shaarli'));
607 $PAGE->renderPage('loginform');
608 exit; 600 exit;
609 } 601 }
610 // -------- User wants to logout. 602 // -------- User wants to logout.
@@ -667,6 +659,7 @@ function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionM
667 659
668 alphabetical_sort($tags, false, true); 660 alphabetical_sort($tags, false, true);
669 661
662 $logMaxCount = $maxcount > 1 ? log($maxcount, 30) : 1;
670 $tagList = array(); 663 $tagList = array();
671 foreach ($tags as $key => $value) { 664 foreach ($tags as $key => $value) {
672 if (in_array($key, $filteringTags)) { 665 if (in_array($key, $filteringTags)) {
@@ -674,8 +667,8 @@ function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionM
674 } 667 }
675 // Tag font size scaling: 668 // Tag font size scaling:
676 // default 15 and 30 logarithm bases affect scaling, 669 // default 15 and 30 logarithm bases affect scaling,
677 // 22 and 6 are arbitrary font sizes for max and min sizes. 670 // 2.2 and 0.8 are arbitrary font sizes in em.
678 $size = log($value, 15) / log($maxcount, 30) * 2.2 + 0.8; 671 $size = log($value, 15) / $logMaxCount * 2.2 + 0.8;
679 $tagList[$key] = array( 672 $tagList[$key] = array(
680 'count' => $value, 673 'count' => $value,
681 'size' => number_format($size, 2, '.', ''), 674 'size' => number_format($size, 2, '.', ''),
@@ -931,7 +924,7 @@ function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionM
931 // Show login screen, then redirect to ?post=... 924 // Show login screen, then redirect to ?post=...
932 if (isset($_GET['post'])) { 925 if (isset($_GET['post'])) {
933 header( // Redirect to login page, then back to post link. 926 header( // Redirect to login page, then back to post link.
934 'Location: ?do=login&post='.urlencode($_GET['post']). 927 'Location: /login?post='.urlencode($_GET['post']).
935 (!empty($_GET['title'])?'&title='.urlencode($_GET['title']):''). 928 (!empty($_GET['title'])?'&title='.urlencode($_GET['title']):'').
936 (!empty($_GET['description'])?'&description='.urlencode($_GET['description']):''). 929 (!empty($_GET['description'])?'&description='.urlencode($_GET['description']):'').
937 (!empty($_GET['tags'])?'&tags='.urlencode($_GET['tags']):''). 930 (!empty($_GET['tags'])?'&tags='.urlencode($_GET['tags']):'').
@@ -942,7 +935,7 @@ function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionM
942 935
943 showLinkList($PAGE, $bookmarkService, $conf, $pluginManager, $loginManager); 936 showLinkList($PAGE, $bookmarkService, $conf, $pluginManager, $loginManager);
944 if (isset($_GET['edit_link'])) { 937 if (isset($_GET['edit_link'])) {
945 header('Location: ?do=login&edit_link='. escape($_GET['edit_link'])); 938 header('Location: /login?edit_link='. escape($_GET['edit_link']));
946 exit; 939 exit;
947 } 940 }
948 941
@@ -1898,7 +1891,7 @@ function install($conf, $sessionManager, $loginManager)
1898 echo '<script>alert(' 1891 echo '<script>alert('
1899 .'"Shaarli is now configured. ' 1892 .'"Shaarli is now configured. '
1900 .'Please enter your login/password and start shaaring your bookmarks!"' 1893 .'Please enter your login/password and start shaaring your bookmarks!"'
1901 .');document.location=\'?do=login\';</script>'; 1894 .');document.location=\'./login\';</script>';
1902 exit; 1895 exit;
1903 } 1896 }
1904 1897
@@ -1928,20 +1921,18 @@ if (isset($_SERVER['QUERY_STRING']) && startsWith($_SERVER['QUERY_STRING'], 'do=
1928 exit; 1921 exit;
1929} 1922}
1930 1923
1931$container = new \Slim\Container(); 1924$containerBuilder = new ContainerBuilder($conf, $sessionManager, $loginManager);
1932$container['conf'] = $conf; 1925$container = $containerBuilder->build();
1933$container['plugins'] = $pluginManager; 1926$app = new App($container);
1934$container['history'] = $history;
1935$app = new \Slim\App($container);
1936 1927
1937// REST API routes 1928// REST API routes
1938$app->group('/api/v1', function () { 1929$app->group('/api/v1', function () {
1939 $this->get('/info', '\Shaarli\Api\Controllers\Info:getInfo')->setName('getInfo'); 1930 $this->get('/info', '\Shaarli\Api\Controllers\Info:getInfo')->setName('getInfo');
1940 $this->get('/bookmarks', '\Shaarli\Api\Controllers\Links:getLinks')->setName('getLinks'); 1931 $this->get('/links', '\Shaarli\Api\Controllers\Links:getLinks')->setName('getLinks');
1941 $this->get('/bookmarks/{id:[\d]+}', '\Shaarli\Api\Controllers\Links:getLink')->setName('getLink'); 1932 $this->get('/links/{id:[\d]+}', '\Shaarli\Api\Controllers\Links:getLink')->setName('getLink');
1942 $this->post('/bookmarks', '\Shaarli\Api\Controllers\Links:postLink')->setName('postLink'); 1933 $this->post('/links', '\Shaarli\Api\Controllers\Links:postLink')->setName('postLink');
1943 $this->put('/bookmarks/{id:[\d]+}', '\Shaarli\Api\Controllers\Links:putLink')->setName('putLink'); 1934 $this->put('/links/{id:[\d]+}', '\Shaarli\Api\Controllers\Links:putLink')->setName('putLink');
1944 $this->delete('/bookmarks/{id:[\d]+}', '\Shaarli\Api\Controllers\Links:deleteLink')->setName('deleteLink'); 1935 $this->delete('/links/{id:[\d]+}', '\Shaarli\Api\Controllers\Links:deleteLink')->setName('deleteLink');
1945 1936
1946 $this->get('/tags', '\Shaarli\Api\Controllers\Tags:getTags')->setName('getTags'); 1937 $this->get('/tags', '\Shaarli\Api\Controllers\Tags:getTags')->setName('getTags');
1947 $this->get('/tags/{tagName:[\w]+}', '\Shaarli\Api\Controllers\Tags:getTag')->setName('getTag'); 1938 $this->get('/tags/{tagName:[\w]+}', '\Shaarli\Api\Controllers\Tags:getTag')->setName('getTag');
@@ -1951,6 +1942,10 @@ $app->group('/api/v1', function () {
1951 $this->get('/history', '\Shaarli\Api\Controllers\HistoryController:getHistory')->setName('getHistory'); 1942 $this->get('/history', '\Shaarli\Api\Controllers\HistoryController:getHistory')->setName('getHistory');
1952})->add('\Shaarli\Api\ApiMiddleware'); 1943})->add('\Shaarli\Api\ApiMiddleware');
1953 1944
1945$app->group('', function () {
1946 $this->get('/login', '\Shaarli\Front\Controller\LoginController:index')->setName('login');
1947})->add('\Shaarli\Front\ShaarliMiddleware');
1948
1954$response = $app->run(true); 1949$response = $app->run(true);
1955 1950
1956// Hack to make Slim and Shaarli router work together: 1951// Hack to make Slim and Shaarli router work together: