3 * Shaarli - The personal, minimalist, super-fast, database free, bookmarking service.
5 * Friendly fork by the Shaarli community:
6 * - https://github.com/shaarli/Shaarli
8 * Original project by sebsauvage.net:
9 * - http://sebsauvage.net/wiki/doku.php?id=php:shaarli
10 * - https://github.com/sebsauvage/Shaarli
12 * Licence: http://www.opensource.org/licenses/zlib-license.php
15 require_once 'inc/rain.tpl.class.php';
16 require_once __DIR__
. '/vendor/autoload.php';
19 require_once 'application/bookmark/LinkUtils.php';
20 require_once 'application/config/ConfigPlugin.php';
21 require_once 'application/http/HttpUtils.php';
22 require_once 'application/http/UrlUtils.php';
23 require_once 'application/TimeZone.php';
24 require_once 'application/Utils.php';
26 require_once __DIR__
. '/init.php';
28 use Katzgrau\KLogger\Logger
;
30 use Shaarli\Config\ConfigManager
;
31 use Shaarli\Container\ContainerBuilder
;
32 use Shaarli\Languages
;
33 use Shaarli\Security\BanManager
;
34 use Shaarli\Security\CookieManager
;
35 use Shaarli\Security\LoginManager
;
36 use Shaarli\Security\SessionManager
;
39 $conf = new ConfigManager();
41 // Manually override root URL for complex server configurations
42 define('SHAARLI_ROOT_URL', $conf->get('general.root_url', null));
44 // In dev mode, throw exception on any warning
45 if ($conf->get('dev.debug', false)) {
46 // See all errors (for debugging only)
49 set_error_handler(function ($errno, $errstr, $errfile, $errline, array $errcontext) {
50 throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
55 dirname($conf->get('resource.log')),
56 !$conf->get('dev.debug') ? LogLevel
::INFO
: LogLevel
::DEBUG
,
57 ['filename' => basename($conf->get('resource.log'))]
59 $sessionManager = new SessionManager($_SESSION, $conf, session_save_path());
60 $sessionManager->initialize();
61 $cookieManager = new CookieManager($_COOKIE);
62 $banManager = new BanManager(
63 $conf->get('security.trusted_proxies', []),
64 $conf->get('security.ban_after'),
65 $conf->get('security.ban_duration'),
66 $conf->get('resource.ban_file', 'data/ipbans.php'),
69 $loginManager = new LoginManager($conf, $sessionManager, $cookieManager, $banManager, $logger);
70 $loginManager->generateStaySignedInToken($_SERVER['REMOTE_ADDR']);
72 // Sniff browser language and set date format accordingly.
73 if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
74 autoLocale($_SERVER['HTTP_ACCEPT_LANGUAGE']);
77 new Languages(setlocale(LC_MESSAGES
, 0), $conf);
79 $conf->setEmpty('general.timezone', date_default_timezone_get());
80 $conf->setEmpty('general.title', t('Shared bookmarks on '). escape(index_url($_SERVER)));
82 RainTPL
::$tpl_dir = $conf->get('resource.raintpl_tpl').'/'.$conf->get('resource.theme').'/'; // template directory
83 RainTPL
::$cache_dir = $conf->get('resource.raintpl_tmp'); // cache directory
85 date_default_timezone_set($conf->get('general.timezone', 'UTC'));
87 $loginManager->checkLoginState(client_ip_id($_SERVER));
89 $containerBuilder = new ContainerBuilder($conf, $sessionManager, $cookieManager, $loginManager, $logger);
90 $container = $containerBuilder->build();
91 $app = new App($container);
93 // Main Shaarli routes
94 $app->group('', function () {
95 $this->get('/install', '\Shaarli\Front\Controller\Visitor\InstallController:index')->setName('displayInstall');
96 $this->get('/install/session-test', '\Shaarli\Front\Controller\Visitor\InstallController:sessionTest');
97 $this->post('/install', '\Shaarli\Front\Controller\Visitor\InstallController:save')->setName('saveInstall');
100 $this->get('/', '\Shaarli\Front\Controller\Visitor\BookmarkListController:index');
101 $this->get('/shaare/{hash}', '\Shaarli\Front\Controller\Visitor\BookmarkListController:permalink');
102 $this->get('/login', '\Shaarli\Front\Controller\Visitor\LoginController:index')->setName('login');
103 $this->post('/login', '\Shaarli\Front\Controller\Visitor\LoginController:login')->setName('processLogin');
104 $this->get('/picture-wall', '\Shaarli\Front\Controller\Visitor\PictureWallController:index');
105 $this->get('/tags/cloud', '\Shaarli\Front\Controller\Visitor\TagCloudController:cloud');
106 $this->get('/tags/list', '\Shaarli\Front\Controller\Visitor\TagCloudController:list');
107 $this->get('/daily', '\Shaarli\Front\Controller\Visitor\DailyController:index');
108 $this->get('/daily-rss', '\Shaarli\Front\Controller\Visitor\DailyController:rss')->setName('rss');
109 $this->get('/feed/atom', '\Shaarli\Front\Controller\Visitor\FeedController:atom')->setName('atom');
110 $this->get('/feed/rss', '\Shaarli\Front\Controller\Visitor\FeedController:rss');
111 $this->get('/open-search', '\Shaarli\Front\Controller\Visitor\OpenSearchController:index');
113 $this->get('/add-tag/{newTag}', '\Shaarli\Front\Controller\Visitor\TagController:addTag');
114 $this->get('/remove-tag/{tag}', '\Shaarli\Front\Controller\Visitor\TagController:removeTag');
115 $this->get('/links-per-page', '\Shaarli\Front\Controller\Visitor\PublicSessionFilterController:linksPerPage');
116 $this->get('/untagged-only', '\Shaarli\Front\Controller\Visitor\PublicSessionFilterController:untaggedOnly');
117 })->add('\Shaarli\Front\ShaarliMiddleware');
119 $app->group('/admin', function () {
120 $this->get('/logout', '\Shaarli\Front\Controller\Admin\LogoutController:index');
121 $this->get('/tools', '\Shaarli\Front\Controller\Admin\ToolsController:index');
122 $this->get('/password', '\Shaarli\Front\Controller\Admin\PasswordController:index');
123 $this->post('/password', '\Shaarli\Front\Controller\Admin\PasswordController:change');
124 $this->get('/configure', '\Shaarli\Front\Controller\Admin\ConfigureController:index');
125 $this->post('/configure', '\Shaarli\Front\Controller\Admin\ConfigureController:save');
126 $this->get('/tags', '\Shaarli\Front\Controller\Admin\ManageTagController:index');
127 $this->post('/tags', '\Shaarli\Front\Controller\Admin\ManageTagController:save');
128 $this->get('/add-shaare', '\Shaarli\Front\Controller\Admin\ShaareAddController:addShaare');
129 $this->get('/shaare', '\Shaarli\Front\Controller\Admin\ShaarePublishController:displayCreateForm');
130 $this->get('/shaare/{id:[0-9]+}', '\Shaarli\Front\Controller\Admin\ShaarePublishController:displayEditForm');
131 $this->get('/shaare/private/{hash}', '\Shaarli\Front\Controller\Admin\ShaareManageController:sharePrivate');
132 $this->post('/shaare-batch', '\Shaarli\Front\Controller\Admin\ShaarePublishController:displayCreateBatchForms');
133 $this->post('/shaare', '\Shaarli\Front\Controller\Admin\ShaarePublishController:save');
134 $this->get('/shaare/delete', '\Shaarli\Front\Controller\Admin\ShaareManageController:deleteBookmark');
135 $this->get('/shaare/visibility', '\Shaarli\Front\Controller\Admin\ShaareManageController:changeVisibility');
136 $this->get('/shaare/{id:[0-9]+}/pin', '\Shaarli\Front\Controller\Admin\ShaareManageController:pinBookmark');
138 '/shaare/{id:[0-9]+}/update-thumbnail',
139 '\Shaarli\Front\Controller\Admin\ThumbnailsController:ajaxUpdate'
141 $this->get('/export', '\Shaarli\Front\Controller\Admin\ExportController:index');
142 $this->post('/export', '\Shaarli\Front\Controller\Admin\ExportController:export');
143 $this->get('/import', '\Shaarli\Front\Controller\Admin\ImportController:index');
144 $this->post('/import', '\Shaarli\Front\Controller\Admin\ImportController:import');
145 $this->get('/plugins', '\Shaarli\Front\Controller\Admin\PluginsController:index');
146 $this->post('/plugins', '\Shaarli\Front\Controller\Admin\PluginsController:save');
147 $this->get('/token', '\Shaarli\Front\Controller\Admin\TokenController:getToken');
148 $this->get('/server', '\Shaarli\Front\Controller\Admin\ServerController:index');
149 $this->get('/clear-cache', '\Shaarli\Front\Controller\Admin\ServerController:clearCache');
150 $this->get('/thumbnails', '\Shaarli\Front\Controller\Admin\ThumbnailsController:index');
151 $this->get('/metadata', '\Shaarli\Front\Controller\Admin\MetadataController:ajaxRetrieveTitle');
152 $this->get('/visibility/{visibility}', '\Shaarli\Front\Controller\Admin\SessionFilterController:visibility');
153 })->add('\Shaarli\Front\ShaarliAdminMiddleware');
157 $app->group('/api/v1', function () {
158 $this->get('/info', '\Shaarli\Api\Controllers\Info:getInfo')->setName('getInfo');
159 $this->get('/links', '\Shaarli\Api\Controllers\Links:getLinks')->setName('getLinks');
160 $this->get('/links/{id:[\d]+}', '\Shaarli\Api\Controllers\Links:getLink')->setName('getLink');
161 $this->post('/links', '\Shaarli\Api\Controllers\Links:postLink')->setName('postLink');
162 $this->put('/links/{id:[\d]+}', '\Shaarli\Api\Controllers\Links:putLink')->setName('putLink');
163 $this->delete('/links/{id:[\d]+}', '\Shaarli\Api\Controllers\Links:deleteLink')->setName('deleteLink');
165 $this->get('/tags', '\Shaarli\Api\Controllers\Tags:getTags')->setName('getTags');
166 $this->get('/tags/{tagName:[\w]+}', '\Shaarli\Api\Controllers\Tags:getTag')->setName('getTag');
167 $this->put('/tags/{tagName:[\w]+}', '\Shaarli\Api\Controllers\Tags:putTag')->setName('putTag');
168 $this->delete('/tags/{tagName:[\w]+}', '\Shaarli\Api\Controllers\Tags:deleteTag')->setName('deleteTag');
170 $this->get('/history', '\Shaarli\Api\Controllers\HistoryController:getHistory')->setName('getHistory');
171 })->add('\Shaarli\Api\ApiMiddleware');
174 $response = $app->run(true);
175 $app->respond($response);
176 } catch (Throwable
$e) {
178 'An unexpected error happened, and the error template could not be displayed.' . PHP_EOL
. PHP_EOL
.