aboutsummaryrefslogtreecommitdiffhomepage
path: root/index.php
diff options
context:
space:
mode:
Diffstat (limited to 'index.php')
-rw-r--r--index.php44
1 files changed, 32 insertions, 12 deletions
diff --git a/index.php b/index.php
index 25e37b32..835fd7d2 100644
--- a/index.php
+++ b/index.php
@@ -175,7 +175,6 @@ define('STAY_SIGNED_IN_TOKEN', sha1($conf->get('credentials.hash') . $_SERVER['R
175if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { 175if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
176 autoLocale($_SERVER['HTTP_ACCEPT_LANGUAGE']); 176 autoLocale($_SERVER['HTTP_ACCEPT_LANGUAGE']);
177} 177}
178header('Content-Type: text/html; charset=utf-8'); // We use UTF-8 for proper international characters handling.
179 178
180/** 179/**
181 * Checking session state (i.e. is the user still logged in) 180 * Checking session state (i.e. is the user still logged in)
@@ -731,17 +730,10 @@ function showLinkList($PAGE, $LINKSDB, $conf, $pluginManager) {
731 * 730 *
732 * @param ConfigManager $conf Configuration Manager instance. 731 * @param ConfigManager $conf Configuration Manager instance.
733 * @param PluginManager $pluginManager Plugin Manager instance, 732 * @param PluginManager $pluginManager Plugin Manager instance,
733 * @param LinkDB $LINKSDB
734 */ 734 */
735function renderPage($conf, $pluginManager) 735function renderPage($conf, $pluginManager, $LINKSDB)
736{ 736{
737 $LINKSDB = new LinkDB(
738 $conf->get('resource.datastore'),
739 isLoggedIn(),
740 $conf->get('privacy.hide_public_links'),
741 $conf->get('redirector.url'),
742 $conf->get('redirector.encode_url')
743 );
744
745 $updater = new Updater( 737 $updater = new Updater(
746 read_updates_file($conf->get('resource.updates')), 738 read_updates_file($conf->get('resource.updates')),
747 $LINKSDB, 739 $LINKSDB,
@@ -938,7 +930,7 @@ function renderPage($conf, $pluginManager)
938 exit; 930 exit;
939 } 931 }
940 932
941 // Display openseach plugin (XML) 933 // Display opensearch plugin (XML)
942 if ($targetPage == Router::$PAGE_OPENSEARCH) { 934 if ($targetPage == Router::$PAGE_OPENSEARCH) {
943 header('Content-Type: application/xml; charset=utf-8'); 935 header('Content-Type: application/xml; charset=utf-8');
944 $PAGE->assign('serverurl', index_url($_SERVER)); 936 $PAGE->assign('serverurl', index_url($_SERVER));
@@ -2226,4 +2218,32 @@ if (isset($_SERVER['QUERY_STRING']) && startsWith($_SERVER['QUERY_STRING'], 'do=
2226if (!isset($_SESSION['LINKS_PER_PAGE'])) { 2218if (!isset($_SESSION['LINKS_PER_PAGE'])) {
2227 $_SESSION['LINKS_PER_PAGE'] = $conf->get('general.links_per_page', 20); 2219 $_SESSION['LINKS_PER_PAGE'] = $conf->get('general.links_per_page', 20);
2228} 2220}
2229renderPage($conf, $pluginManager); 2221
2222$linkDb = new LinkDB(
2223 $conf->get('resource.datastore'),
2224 isLoggedIn(),
2225 $conf->get('privacy.hide_public_links'),
2226 $conf->get('redirector.url'),
2227 $conf->get('redirector.encode_url')
2228);
2229
2230$container = new \Slim\Container();
2231$container['conf'] = $conf;
2232$container['plugins'] = $pluginManager;
2233$app = new \Slim\App($container);
2234
2235// REST API routes
2236$app->group('/api/v1', function() {
2237 $this->get('/info', '\Api\Controllers\Info:getInfo');
2238})->add('\Api\ApiMiddleware');
2239
2240$response = $app->run(true);
2241// Hack to make Slim and Shaarli router work together:
2242// If a Slim route isn't found, we call renderPage().
2243if ($response->getStatusCode() == 404) {
2244 // We use UTF-8 for proper international characters handling.
2245 header('Content-Type: text/html; charset=utf-8');
2246 renderPage($conf, $pluginManager, $linkDb);
2247} else {
2248 $app->respond($response);
2249}