require_once 'application/TimeZone.php';
require_once 'application/Utils.php';
-use \Shaarli\ApplicationUtils;
-use Shaarli\Bookmark\BookmarkServiceInterface;
-use \Shaarli\Bookmark\Exception\BookmarkNotFoundException;
+use Shaarli\ApplicationUtils;
use Shaarli\Bookmark\Bookmark;
-use Shaarli\Bookmark\BookmarkFilter;
use Shaarli\Bookmark\BookmarkFileService;
-use \Shaarli\Config\ConfigManager;
-use \Shaarli\Feed\CachedPage;
-use \Shaarli\Feed\FeedBuilder;
+use Shaarli\Bookmark\BookmarkFilter;
+use Shaarli\Bookmark\BookmarkServiceInterface;
+use Shaarli\Bookmark\Exception\BookmarkNotFoundException;
+use Shaarli\Config\ConfigManager;
+use Shaarli\Container\ContainerBuilder;
+use Shaarli\Feed\CachedPage;
+use Shaarli\Feed\FeedBuilder;
use Shaarli\Formatter\BookmarkMarkdownFormatter;
use Shaarli\Formatter\FormatterFactory;
-use \Shaarli\History;
-use \Shaarli\Languages;
-use \Shaarli\Netscape\NetscapeBookmarkUtils;
-use \Shaarli\Plugin\PluginManager;
-use \Shaarli\Render\PageBuilder;
-use \Shaarli\Render\ThemeUtils;
-use \Shaarli\Router;
-use \Shaarli\Security\LoginManager;
-use \Shaarli\Security\SessionManager;
-use \Shaarli\Thumbnailer;
-use \Shaarli\Updater\Updater;
-use \Shaarli\Updater\UpdaterUtils;
+use Shaarli\History;
+use Shaarli\Languages;
+use Shaarli\Netscape\NetscapeBookmarkUtils;
+use Shaarli\Plugin\PluginManager;
+use Shaarli\Render\PageBuilder;
+use Shaarli\Render\ThemeUtils;
+use Shaarli\Router;
+use Shaarli\Security\LoginManager;
+use Shaarli\Security\SessionManager;
+use Shaarli\Thumbnailer;
+use Shaarli\Updater\Updater;
+use Shaarli\Updater\UpdaterUtils;
+use Slim\App;
// Ensure the PHP version is supported
try {
// Optional redirect after login:
if (isset($_GET['post'])) {
- $uri = '?post='. urlencode($_GET['post']);
+ $uri = './?post='. urlencode($_GET['post']);
foreach (array('description', 'source', 'title', 'tags') as $param) {
if (!empty($_GET[$param])) {
$uri .= '&'.$param.'='.urlencode($_GET[$param]);
}
if (isset($_GET['edit_link'])) {
- header('Location: ?edit_link='. escape($_GET['edit_link']));
+ header('Location: ./?edit_link='. escape($_GET['edit_link']));
exit;
}
if (isset($_POST['returnurl'])) {
// Prevent loops over login screen.
- if (strpos($_POST['returnurl'], 'do=login') === false) {
+ if (strpos($_POST['returnurl'], '/login') === false) {
header('Location: '. generateLocation($_POST['returnurl'], $_SERVER['HTTP_HOST']));
exit;
}
}
- header('Location: ?');
+ header('Location: ./?');
exit;
} else {
$loginManager->handleFailedLogin($_SERVER);
- $redir = '&username='. urlencode($_POST['login']);
+ $redir = '?username='. urlencode($_POST['login']);
if (isset($_GET['post'])) {
$redir .= '&post=' . urlencode($_GET['post']);
foreach (array('description', 'source', 'title', 'tags') as $param) {
}
}
// Redirect to login screen.
- echo '<script>alert("'. t("Wrong login/password.") .'");document.location=\'?do=login'.$redir.'\';</script>';
+ echo '<script>alert("'. t("Wrong login/password.") .'");document.location=\'./login'.$redir.'\';</script>';
exit;
}
}
// -------- Display login form.
if ($targetPage == Router::$PAGE_LOGIN) {
- if ($conf->get('security.open_shaarli')) {
- header('Location: ?');
- exit;
- } // No need to login for open Shaarli
- if (isset($_GET['username'])) {
- $PAGE->assign('username', escape($_GET['username']));
- }
- $PAGE->assign('returnurl', (isset($_SERVER['HTTP_REFERER']) ? escape($_SERVER['HTTP_REFERER']):''));
- // add default state of the 'remember me' checkbox
- $PAGE->assign('remember_user_default', $conf->get('privacy.remember_user_default'));
- $PAGE->assign('user_can_login', $loginManager->canLogin($_SERVER));
- $PAGE->assign('pagetitle', t('Login') .' - '. $conf->get('general.title', 'Shaarli'));
- $PAGE->renderPage('loginform');
+ header('Location: ./login');
exit;
}
// -------- User wants to logout.
alphabetical_sort($tags, false, true);
+ $logMaxCount = $maxcount > 1 ? log($maxcount, 30) : 1;
$tagList = array();
foreach ($tags as $key => $value) {
if (in_array($key, $filteringTags)) {
}
// Tag font size scaling:
// default 15 and 30 logarithm bases affect scaling,
- // 22 and 6 are arbitrary font sizes for max and min sizes.
- $size = log($value, 15) / log($maxcount, 30) * 2.2 + 0.8;
+ // 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, '.', ''),
// Show login screen, then redirect to ?post=...
if (isset($_GET['post'])) {
header( // Redirect to login page, then back to post link.
- 'Location: ?do=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']):'').
showLinkList($PAGE, $bookmarkService, $conf, $pluginManager, $loginManager);
if (isset($_GET['edit_link'])) {
- header('Location: ?do=login&edit_link='. escape($_GET['edit_link']));
+ header('Location: /login?edit_link='. escape($_GET['edit_link']));
exit;
}
echo '<script>alert('
.'"Shaarli is now configured. '
.'Please enter your login/password and start shaaring your bookmarks!"'
- .');document.location=\'?do=login\';</script>';
+ .');document.location=\'./login\';</script>';
exit;
}
exit;
}
-$container = new \Slim\Container();
-$container['conf'] = $conf;
-$container['plugins'] = $pluginManager;
-$container['history'] = $history;
-$app = new \Slim\App($container);
+$containerBuilder = new ContainerBuilder($conf, $sessionManager, $loginManager);
+$container = $containerBuilder->build();
+$app = new App($container);
// REST API routes
$app->group('/api/v1', function () {
$this->get('/info', '\Shaarli\Api\Controllers\Info:getInfo')->setName('getInfo');
- $this->get('/bookmarks', '\Shaarli\Api\Controllers\Links:getLinks')->setName('getLinks');
- $this->get('/bookmarks/{id:[\d]+}', '\Shaarli\Api\Controllers\Links:getLink')->setName('getLink');
- $this->post('/bookmarks', '\Shaarli\Api\Controllers\Links:postLink')->setName('postLink');
- $this->put('/bookmarks/{id:[\d]+}', '\Shaarli\Api\Controllers\Links:putLink')->setName('putLink');
- $this->delete('/bookmarks/{id:[\d]+}', '\Shaarli\Api\Controllers\Links:deleteLink')->setName('deleteLink');
+ $this->get('/links', '\Shaarli\Api\Controllers\Links:getLinks')->setName('getLinks');
+ $this->get('/links/{id:[\d]+}', '\Shaarli\Api\Controllers\Links:getLink')->setName('getLink');
+ $this->post('/links', '\Shaarli\Api\Controllers\Links:postLink')->setName('postLink');
+ $this->put('/links/{id:[\d]+}', '\Shaarli\Api\Controllers\Links:putLink')->setName('putLink');
+ $this->delete('/links/{id:[\d]+}', '\Shaarli\Api\Controllers\Links:deleteLink')->setName('deleteLink');
$this->get('/tags', '\Shaarli\Api\Controllers\Tags:getTags')->setName('getTags');
$this->get('/tags/{tagName:[\w]+}', '\Shaarli\Api\Controllers\Tags:getTag')->setName('getTag');
$this->get('/history', '\Shaarli\Api\Controllers\HistoryController:getHistory')->setName('getHistory');
})->add('\Shaarli\Api\ApiMiddleware');
+$app->group('', function () {
+ $this->get('/login', '\Shaarli\Front\Controller\LoginController:index')->setName('login');
+})->add('\Shaarli\Front\ShaarliMiddleware');
+
$response = $app->run(true);
// Hack to make Slim and Shaarli router work together: