diff options
Diffstat (limited to 'index.php')
-rw-r--r-- | index.php | 56 |
1 files changed, 44 insertions, 12 deletions
@@ -175,7 +175,6 @@ define('STAY_SIGNED_IN_TOKEN', sha1($conf->get('credentials.hash') . $_SERVER['R | |||
175 | if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { | 175 | if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { |
176 | autoLocale($_SERVER['HTTP_ACCEPT_LANGUAGE']); | 176 | autoLocale($_SERVER['HTTP_ACCEPT_LANGUAGE']); |
177 | } | 177 | } |
178 | header('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 | */ |
735 | function renderPage($conf, $pluginManager) | 735 | function 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)); |
@@ -1142,6 +1134,8 @@ function renderPage($conf, $pluginManager) | |||
1142 | $conf->set('feed.rss_permalinks', !empty($_POST['enableRssPermalinks'])); | 1134 | $conf->set('feed.rss_permalinks', !empty($_POST['enableRssPermalinks'])); |
1143 | $conf->set('updates.check_updates', !empty($_POST['updateCheck'])); | 1135 | $conf->set('updates.check_updates', !empty($_POST['updateCheck'])); |
1144 | $conf->set('privacy.hide_public_links', !empty($_POST['hidePublicLinks'])); | 1136 | $conf->set('privacy.hide_public_links', !empty($_POST['hidePublicLinks'])); |
1137 | $conf->set('api.enabled', !empty($_POST['apiEnabled'])); | ||
1138 | $conf->set('api.secret', escape($_POST['apiSecret'])); | ||
1145 | try { | 1139 | try { |
1146 | $conf->write(isLoggedIn()); | 1140 | $conf->write(isLoggedIn()); |
1147 | } | 1141 | } |
@@ -1170,6 +1164,8 @@ function renderPage($conf, $pluginManager) | |||
1170 | $PAGE->assign('enable_rss_permalinks', $conf->get('feed.rss_permalinks', false)); | 1164 | $PAGE->assign('enable_rss_permalinks', $conf->get('feed.rss_permalinks', false)); |
1171 | $PAGE->assign('enable_update_check', $conf->get('updates.check_updates', true)); | 1165 | $PAGE->assign('enable_update_check', $conf->get('updates.check_updates', true)); |
1172 | $PAGE->assign('hide_public_links', $conf->get('privacy.hide_public_links', false)); | 1166 | $PAGE->assign('hide_public_links', $conf->get('privacy.hide_public_links', false)); |
1167 | $PAGE->assign('api_enabled', $conf->get('api.enabled', true)); | ||
1168 | $PAGE->assign('api_secret', $conf->get('api.secret')); | ||
1173 | $PAGE->renderPage('configure'); | 1169 | $PAGE->renderPage('configure'); |
1174 | exit; | 1170 | exit; |
1175 | } | 1171 | } |
@@ -1954,6 +1950,14 @@ function install($conf) | |||
1954 | $conf->set('general.title', 'Shared links on '.escape(index_url($_SERVER))); | 1950 | $conf->set('general.title', 'Shared links on '.escape(index_url($_SERVER))); |
1955 | } | 1951 | } |
1956 | $conf->set('updates.check_updates', !empty($_POST['updateCheck'])); | 1952 | $conf->set('updates.check_updates', !empty($_POST['updateCheck'])); |
1953 | $conf->set('api.enabled', !empty($_POST['enableApi'])); | ||
1954 | $conf->set( | ||
1955 | 'api.secret', | ||
1956 | generate_api_secret( | ||
1957 | $this->conf->get('credentials.login'), | ||
1958 | $this->conf->get('credentials.salt') | ||
1959 | ) | ||
1960 | ); | ||
1957 | try { | 1961 | try { |
1958 | // Everything is ok, let's create config file. | 1962 | // Everything is ok, let's create config file. |
1959 | $conf->write(isLoggedIn()); | 1963 | $conf->write(isLoggedIn()); |
@@ -2216,4 +2220,32 @@ if (isset($_SERVER['QUERY_STRING']) && startsWith($_SERVER['QUERY_STRING'], 'do= | |||
2216 | if (!isset($_SESSION['LINKS_PER_PAGE'])) { | 2220 | if (!isset($_SESSION['LINKS_PER_PAGE'])) { |
2217 | $_SESSION['LINKS_PER_PAGE'] = $conf->get('general.links_per_page', 20); | 2221 | $_SESSION['LINKS_PER_PAGE'] = $conf->get('general.links_per_page', 20); |
2218 | } | 2222 | } |
2219 | renderPage($conf, $pluginManager); | 2223 | |
2224 | $linkDb = new LinkDB( | ||
2225 | $conf->get('resource.datastore'), | ||
2226 | isLoggedIn(), | ||
2227 | $conf->get('privacy.hide_public_links'), | ||
2228 | $conf->get('redirector.url'), | ||
2229 | $conf->get('redirector.encode_url') | ||
2230 | ); | ||
2231 | |||
2232 | $container = new \Slim\Container(); | ||
2233 | $container['conf'] = $conf; | ||
2234 | $container['plugins'] = $pluginManager; | ||
2235 | $app = new \Slim\App($container); | ||
2236 | |||
2237 | // REST API routes | ||
2238 | $app->group('/api/v1', function() { | ||
2239 | $this->get('/info', '\Api\Controllers\Info:getInfo'); | ||
2240 | })->add('\Api\ApiMiddleware'); | ||
2241 | |||
2242 | $response = $app->run(true); | ||
2243 | // Hack to make Slim and Shaarli router work together: | ||
2244 | // If a Slim route isn't found, we call renderPage(). | ||
2245 | if ($response->getStatusCode() == 404) { | ||
2246 | // We use UTF-8 for proper international characters handling. | ||
2247 | header('Content-Type: text/html; charset=utf-8'); | ||
2248 | renderPage($conf, $pluginManager, $linkDb); | ||
2249 | } else { | ||
2250 | $app->respond($response); | ||
2251 | } | ||