X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=index.php;h=2ed14d4f2f3ac67ed6bd5e041fc434b27a7aa050;hb=fc11ab2f290a3712b766d78fdbcd354625a35d0a;hp=34f0e3817782b288f59fab89114ce6a1dde07ede;hpb=f4ebd5fed20b29c4fb580983b4be7bd0a52151b9;p=github%2Fshaarli%2FShaarli.git diff --git a/index.php b/index.php index 34f0e381..2ed14d4f 100644 --- a/index.php +++ b/index.php @@ -175,7 +175,6 @@ define('STAY_SIGNED_IN_TOKEN', sha1($conf->get('credentials.hash') . $_SERVER['R if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { autoLocale($_SERVER['HTTP_ACCEPT_LANGUAGE']); } -header('Content-Type: text/html; charset=utf-8'); // We use UTF-8 for proper international characters handling. /** * Checking session state (i.e. is the user still logged in) @@ -731,17 +730,10 @@ function showLinkList($PAGE, $LINKSDB, $conf, $pluginManager) { * * @param ConfigManager $conf Configuration Manager instance. * @param PluginManager $pluginManager Plugin Manager instance, + * @param LinkDB $LINKSDB */ -function renderPage($conf, $pluginManager) +function renderPage($conf, $pluginManager, $LINKSDB) { - $LINKSDB = new LinkDB( - $conf->get('resource.datastore'), - isLoggedIn(), - $conf->get('privacy.hide_public_links'), - $conf->get('redirector.url'), - $conf->get('redirector.encode_url') - ); - $updater = new Updater( read_updates_file($conf->get('resource.updates')), $LINKSDB, @@ -918,10 +910,6 @@ function renderPage($conf, $pluginManager) $feedGenerator->setLocale(strtolower(setlocale(LC_COLLATE, 0))); $feedGenerator->setHideDates($conf->get('privacy.hide_timestamps') && !isLoggedIn()); $feedGenerator->setUsePermalinks(isset($_GET['permalinks']) || !$conf->get('feed.rss_permalinks')); - $pshUrl = $conf->get('config.PUBSUBHUB_URL'); - if (!empty($pshUrl)) { - $feedGenerator->setPubsubhubUrl($pshUrl); - } $data = $feedGenerator->buildData(); // Process plugin hook. @@ -938,7 +926,7 @@ function renderPage($conf, $pluginManager) exit; } - // Display openseach plugin (XML) + // Display opensearch plugin (XML) if ($targetPage == Router::$PAGE_OPENSEARCH) { header('Content-Type: application/xml; charset=utf-8'); $PAGE->assign('serverurl', index_url($_SERVER)); @@ -1142,6 +1130,8 @@ function renderPage($conf, $pluginManager) $conf->set('feed.rss_permalinks', !empty($_POST['enableRssPermalinks'])); $conf->set('updates.check_updates', !empty($_POST['updateCheck'])); $conf->set('privacy.hide_public_links', !empty($_POST['hidePublicLinks'])); + $conf->set('api.enabled', !empty($_POST['apiEnabled'])); + $conf->set('api.secret', escape($_POST['apiSecret'])); try { $conf->write(isLoggedIn()); } @@ -1170,6 +1160,8 @@ function renderPage($conf, $pluginManager) $PAGE->assign('enable_rss_permalinks', $conf->get('feed.rss_permalinks', false)); $PAGE->assign('enable_update_check', $conf->get('updates.check_updates', true)); $PAGE->assign('hide_public_links', $conf->get('privacy.hide_public_links', false)); + $PAGE->assign('api_enabled', $conf->get('api.enabled', true)); + $PAGE->assign('api_secret', $conf->get('api.secret')); $PAGE->renderPage('configure'); exit; } @@ -1293,7 +1285,6 @@ function renderPage($conf, $pluginManager) $LINKSDB[$id] = $link; $LINKSDB->save($conf->get('resource.page_cache')); - pubsubhub($conf); // If we are called from the bookmarklet, we must close the popup: if (isset($_GET['source']) && ($_GET['source']=='bookmarklet' || $_GET['source']=='firefoxsocialapi')) { @@ -1610,8 +1601,8 @@ function renderPage($conf, $pluginManager) function buildLinkList($PAGE,$LINKSDB, $conf, $pluginManager) { // Used in templates - $searchtags = !empty($_GET['searchtags']) ? escape($_GET['searchtags']) : ''; - $searchterm = !empty($_GET['searchterm']) ? escape($_GET['searchterm']) : ''; + $searchtags = !empty($_GET['searchtags']) ? escape(normalize_spaces($_GET['searchtags'])) : ''; + $searchterm = !empty($_GET['searchterm']) ? escape(normalize_spaces($_GET['searchterm'])) : ''; // Smallhash filter if (! empty($_SERVER['QUERY_STRING']) @@ -1658,7 +1649,7 @@ function buildLinkList($PAGE,$LINKSDB, $conf, $pluginManager) } else { $link['updated_timestamp'] = ''; } - $taglist = explode(' ', $link['tags']); + $taglist = preg_split('/\s+/', $link['tags'], -1, PREG_SPLIT_NO_EMPTY); uasort($taglist, 'strcasecmp'); $link['taglist'] = $taglist; // Check for both signs of a note: starting with ? and 7 chars long. @@ -1954,6 +1945,14 @@ function install($conf) $conf->set('general.title', 'Shared links on '.escape(index_url($_SERVER))); } $conf->set('updates.check_updates', !empty($_POST['updateCheck'])); + $conf->set('api.enabled', !empty($_POST['enableApi'])); + $conf->set( + 'api.secret', + generate_api_secret( + $conf->get('credentials.login'), + $conf->get('credentials.salt') + ) + ); try { // Everything is ok, let's create config file. $conf->write(isLoggedIn()); @@ -2216,4 +2215,32 @@ if (isset($_SERVER['QUERY_STRING']) && startsWith($_SERVER['QUERY_STRING'], 'do= if (!isset($_SESSION['LINKS_PER_PAGE'])) { $_SESSION['LINKS_PER_PAGE'] = $conf->get('general.links_per_page', 20); } -renderPage($conf, $pluginManager); + +$linkDb = new LinkDB( + $conf->get('resource.datastore'), + isLoggedIn(), + $conf->get('privacy.hide_public_links'), + $conf->get('redirector.url'), + $conf->get('redirector.encode_url') +); + +$container = new \Slim\Container(); +$container['conf'] = $conf; +$container['plugins'] = $pluginManager; +$app = new \Slim\App($container); + +// REST API routes +$app->group('/api/v1', function() { + $this->get('/info', '\Shaarli\Api\Controllers\Info:getInfo'); +})->add('\Shaarli\Api\ApiMiddleware'); + +$response = $app->run(true); +// Hack to make Slim and Shaarli router work together: +// If a Slim route isn't found, we call renderPage(). +if ($response->getStatusCode() == 404) { + // We use UTF-8 for proper international characters handling. + header('Content-Type: text/html; charset=utf-8'); + renderPage($conf, $pluginManager, $linkDb); +} else { + $app->respond($response); +}