]> git.immae.eu Git - github/shaarli/Shaarli.git/blame - index.php
Strict types: fix an issue in daily where the date could be an int
[github/shaarli/Shaarli.git] / index.php
CommitLineData
45034273 1<?php
49e2b35b 2/**
b786c883 3 * Shaarli - The personal, minimalist, super-fast, database free, bookmarking service.
49e2b35b
V
4 *
5 * Friendly fork by the Shaarli community:
6 * - https://github.com/shaarli/Shaarli
7 *
8 * Original project by sebsauvage.net:
9 * - http://sebsauvage.net/wiki/doku.php?id=php:shaarli
10 * - https://github.com/sebsauvage/Shaarli
11 *
12 * Licence: http://www.opensource.org/licenses/zlib-license.php
49e2b35b 13 */
afd7b77b 14
a973afea
V
15require_once 'inc/rain.tpl.class.php';
16require_once __DIR__ . '/vendor/autoload.php';
17
ca74886f 18// Shaarli library
fe3713d2 19require_once 'application/bookmark/LinkUtils.php';
e6cd773f 20require_once 'application/config/ConfigPlugin.php';
51753e40
V
21require_once 'application/http/HttpUtils.php';
22require_once 'application/http/UrlUtils.php';
d1e2f8e5 23require_once 'application/TimeZone.php';
ca74886f 24require_once 'application/Utils.php';
f24896b2 25
fabff383
A
26require_once __DIR__ . '/init.php';
27
6c50a6cc
A
28use Shaarli\Config\ConfigManager;
29use Shaarli\Container\ContainerBuilder;
6c50a6cc 30use Shaarli\Languages;
c4ad3d4f 31use Shaarli\Security\CookieManager;
6c50a6cc
A
32use Shaarli\Security\LoginManager;
33use Shaarli\Security\SessionManager;
6c50a6cc 34use Slim\App;
ca74886f 35
278d9ee2 36$conf = new ConfigManager();
cf92b4dd 37
650a5f09
A
38// Manually override root URL for complex server configurations
39define('SHAARLI_ROOT_URL', $conf->get('general.root_url', null));
40
cf92b4dd
A
41// In dev mode, throw exception on any warning
42if ($conf->get('dev.debug', false)) {
43 // See all errors (for debugging only)
44 error_reporting(-1);
45
c4ad3d4f 46 set_error_handler(function ($errno, $errstr, $errfile, $errline, array $errcontext) {
cf92b4dd
A
47 throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
48 });
49}
50
c4ad3d4f 51$sessionManager = new SessionManager($_SESSION, $conf, session_save_path());
fabff383 52$sessionManager->initialize();
c4ad3d4f
A
53$cookieManager = new CookieManager($_COOKIE);
54$loginManager = new LoginManager($conf, $sessionManager, $cookieManager);
c689e108 55$loginManager->generateStaySignedInToken($_SERVER['REMOTE_ADDR']);
b7c412d4 56
12266213
A
57// Sniff browser language and set date format accordingly.
58if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
59 autoLocale($_SERVER['HTTP_ACCEPT_LANGUAGE']);
60}
61
62new Languages(setlocale(LC_MESSAGES, 0), $conf);
63
7f179985 64$conf->setEmpty('general.timezone', date_default_timezone_get());
cf92b4dd 65$conf->setEmpty('general.title', t('Shared bookmarks on '). escape(index_url($_SERVER)));
fabff383 66
adc4aee8 67RainTPL::$tpl_dir = $conf->get('resource.raintpl_tpl').'/'.$conf->get('resource.theme').'/'; // template directory
894a3c4b 68RainTPL::$cache_dir = $conf->get('resource.raintpl_tmp'); // cache directory
45034273 69
da10377b 70date_default_timezone_set($conf->get('general.timezone', 'UTC'));
d93d51b2 71
fabff383 72$loginManager->checkLoginState(client_ip_id($_SERVER));
18e67967 73
c4ad3d4f 74$containerBuilder = new ContainerBuilder($conf, $sessionManager, $cookieManager, $loginManager);
6c50a6cc
A
75$container = $containerBuilder->build();
76$app = new App($container);
18e67967 77
fabff383 78// Main Shaarli routes
6c50a6cc 79$app->group('', function () {
c4ad3d4f
A
80 $this->get('/install', '\Shaarli\Front\Controller\Visitor\InstallController:index')->setName('displayInstall');
81 $this->get('/install/session-test', '\Shaarli\Front\Controller\Visitor\InstallController:sessionTest');
82 $this->post('/install', '\Shaarli\Front\Controller\Visitor\InstallController:save')->setName('saveInstall');
83
2899ebb5 84 /* -- PUBLIC --*/
1a8ac737
A
85 $this->get('/', '\Shaarli\Front\Controller\Visitor\BookmarkListController:index');
86 $this->get('/shaare/{hash}', '\Shaarli\Front\Controller\Visitor\BookmarkListController:permalink');
87 $this->get('/login', '\Shaarli\Front\Controller\Visitor\LoginController:index')->setName('login');
a8c11451 88 $this->post('/login', '\Shaarli\Front\Controller\Visitor\LoginController:login')->setName('processLogin');
9c75f877
A
89 $this->get('/picture-wall', '\Shaarli\Front\Controller\Visitor\PictureWallController:index');
90 $this->get('/tags/cloud', '\Shaarli\Front\Controller\Visitor\TagCloudController:cloud');
91 $this->get('/tags/list', '\Shaarli\Front\Controller\Visitor\TagCloudController:list');
92 $this->get('/daily', '\Shaarli\Front\Controller\Visitor\DailyController:index');
1a8ac737
A
93 $this->get('/daily-rss', '\Shaarli\Front\Controller\Visitor\DailyController:rss')->setName('rss');
94 $this->get('/feed/atom', '\Shaarli\Front\Controller\Visitor\FeedController:atom')->setName('atom');
9c75f877
A
95 $this->get('/feed/rss', '\Shaarli\Front\Controller\Visitor\FeedController:rss');
96 $this->get('/open-search', '\Shaarli\Front\Controller\Visitor\OpenSearchController:index');
97
98 $this->get('/add-tag/{newTag}', '\Shaarli\Front\Controller\Visitor\TagController:addTag');
99 $this->get('/remove-tag/{tag}', '\Shaarli\Front\Controller\Visitor\TagController:removeTag');
b725eb04 100 $this->get('/links-per-page', '\Shaarli\Front\Controller\Visitor\PublicSessionFilterController:linksPerPage');
63b0059e 101 $this->get('/untagged-only', '\Shaarli\Front\Controller\Visitor\PublicSessionFilterController:untaggedOnly');
bedbb845 102})->add('\Shaarli\Front\ShaarliMiddleware');
2899ebb5 103
bedbb845 104$app->group('/admin', function () {
9c75f877 105 $this->get('/logout', '\Shaarli\Front\Controller\Admin\LogoutController:index');
bedbb845
A
106 $this->get('/tools', '\Shaarli\Front\Controller\Admin\ToolsController:index');
107 $this->get('/password', '\Shaarli\Front\Controller\Admin\PasswordController:index');
108 $this->post('/password', '\Shaarli\Front\Controller\Admin\PasswordController:change');
109 $this->get('/configure', '\Shaarli\Front\Controller\Admin\ConfigureController:index');
110 $this->post('/configure', '\Shaarli\Front\Controller\Admin\ConfigureController:save');
111 $this->get('/tags', '\Shaarli\Front\Controller\Admin\ManageTagController:index');
112 $this->post('/tags', '\Shaarli\Front\Controller\Admin\ManageTagController:save');
113 $this->get('/add-shaare', '\Shaarli\Front\Controller\Admin\ManageShaareController:addShaare');
114 $this->get('/shaare', '\Shaarli\Front\Controller\Admin\ManageShaareController:displayCreateForm');
115 $this->get('/shaare/{id:[0-9]+}', '\Shaarli\Front\Controller\Admin\ManageShaareController:displayEditForm');
116 $this->post('/shaare', '\Shaarli\Front\Controller\Admin\ManageShaareController:save');
117 $this->get('/shaare/delete', '\Shaarli\Front\Controller\Admin\ManageShaareController:deleteBookmark');
118 $this->get('/shaare/visibility', '\Shaarli\Front\Controller\Admin\ManageShaareController:changeVisibility');
119 $this->get('/shaare/{id:[0-9]+}/pin', '\Shaarli\Front\Controller\Admin\ManageShaareController:pinBookmark');
6132d647 120 $this->patch(
bedbb845 121 '/shaare/{id:[0-9]+}/update-thumbnail',
6132d647
A
122 '\Shaarli\Front\Controller\Admin\ThumbnailsController:ajaxUpdate'
123 );
bedbb845
A
124 $this->get('/export', '\Shaarli\Front\Controller\Admin\ExportController:index');
125 $this->post('/export', '\Shaarli\Front\Controller\Admin\ExportController:export');
126 $this->get('/import', '\Shaarli\Front\Controller\Admin\ImportController:index');
127 $this->post('/import', '\Shaarli\Front\Controller\Admin\ImportController:import');
128 $this->get('/plugins', '\Shaarli\Front\Controller\Admin\PluginsController:index');
129 $this->post('/plugins', '\Shaarli\Front\Controller\Admin\PluginsController:save');
130 $this->get('/token', '\Shaarli\Front\Controller\Admin\TokenController:getToken');
131 $this->get('/thumbnails', '\Shaarli\Front\Controller\Admin\ThumbnailsController:index');
9c75f877 132
9c75f877 133 $this->get('/visibility/{visibility}', '\Shaarli\Front\Controller\Admin\SessionFilterController:visibility');
bedbb845
A
134})->add('\Shaarli\Front\ShaarliAdminMiddleware');
135
6c50a6cc 136
fabff383
A
137// REST API routes
138$app->group('/api/v1', function () {
139 $this->get('/info', '\Shaarli\Api\Controllers\Info:getInfo')->setName('getInfo');
140 $this->get('/links', '\Shaarli\Api\Controllers\Links:getLinks')->setName('getLinks');
141 $this->get('/links/{id:[\d]+}', '\Shaarli\Api\Controllers\Links:getLink')->setName('getLink');
142 $this->post('/links', '\Shaarli\Api\Controllers\Links:postLink')->setName('postLink');
143 $this->put('/links/{id:[\d]+}', '\Shaarli\Api\Controllers\Links:putLink')->setName('putLink');
144 $this->delete('/links/{id:[\d]+}', '\Shaarli\Api\Controllers\Links:deleteLink')->setName('deleteLink');
145
146 $this->get('/tags', '\Shaarli\Api\Controllers\Tags:getTags')->setName('getTags');
147 $this->get('/tags/{tagName:[\w]+}', '\Shaarli\Api\Controllers\Tags:getTag')->setName('getTag');
148 $this->put('/tags/{tagName:[\w]+}', '\Shaarli\Api\Controllers\Tags:putTag')->setName('putTag');
149 $this->delete('/tags/{tagName:[\w]+}', '\Shaarli\Api\Controllers\Tags:deleteTag')->setName('deleteTag');
150
151 $this->get('/history', '\Shaarli\Api\Controllers\HistoryController:getHistory')->setName('getHistory');
152})->add('\Shaarli\Api\ApiMiddleware');
153
18e67967 154$response = $app->run(true);
5d9bc40d 155
1a8ac737 156$app->respond($response);