aboutsummaryrefslogtreecommitdiffhomepage
path: root/index.php
diff options
context:
space:
mode:
Diffstat (limited to 'index.php')
-rw-r--r--index.php45
1 files changed, 38 insertions, 7 deletions
diff --git a/index.php b/index.php
index 1480bbc5..b702bd13 100644
--- a/index.php
+++ b/index.php
@@ -356,7 +356,6 @@ function showDailyRSS($conf, $loginManager) {
356 $conf->get('redirector.url'), 356 $conf->get('redirector.url'),
357 $conf->get('redirector.encode_url') 357 $conf->get('redirector.encode_url')
358 ); 358 );
359 $link['thumbnail'] = thumbnail($conf, $link['url']);
360 $link['timestamp'] = $link['created']->getTimestamp(); 359 $link['timestamp'] = $link['created']->getTimestamp();
361 if (startsWith($link['url'], '?')) { 360 if (startsWith($link['url'], '?')) {
362 $link['url'] = index_url($_SERVER) . $link['url']; // make permalink URL absolute 361 $link['url'] = index_url($_SERVER) . $link['url']; // make permalink URL absolute
@@ -371,6 +370,7 @@ function showDailyRSS($conf, $loginManager) {
371 $tpl->assign('links', $links); 370 $tpl->assign('links', $links);
372 $tpl->assign('rssdate', escape($dayDate->format(DateTime::RSS))); 371 $tpl->assign('rssdate', escape($dayDate->format(DateTime::RSS)));
373 $tpl->assign('hide_timestamps', $conf->get('privacy.hide_timestamps', false)); 372 $tpl->assign('hide_timestamps', $conf->get('privacy.hide_timestamps', false));
373 $tpl->assign('index_url', $pageaddr);
374 $html = $tpl->draw('dailyrss', true); 374 $html = $tpl->draw('dailyrss', true);
375 375
376 echo $html . PHP_EOL; 376 echo $html . PHP_EOL;
@@ -433,7 +433,6 @@ function showDaily($pageBuilder, $LINKSDB, $conf, $pluginManager, $loginManager)
433 $conf->get('redirector.url'), 433 $conf->get('redirector.url'),
434 $conf->get('redirector.encode_url') 434 $conf->get('redirector.encode_url')
435 ); 435 );
436 $linksToDisplay[$key]['thumbnail'] = thumbnail($conf, $link['url']);
437 $linksToDisplay[$key]['timestamp'] = $link['created']->getTimestamp(); 436 $linksToDisplay[$key]['timestamp'] = $link['created']->getTimestamp();
438 } 437 }
439 438
@@ -1085,7 +1084,8 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history, $sessionManager,
1085 die(t('Wrong token.')); 1084 die(t('Wrong token.'));
1086 } 1085 }
1087 1086
1088 $alteredLinks = $LINKSDB->renameTag(escape($_POST['fromtag']), escape($_POST['totag'])); 1087 $toTag = isset($_POST['totag']) ? escape($_POST['totag']) : null;
1088 $alteredLinks = $LINKSDB->renameTag(escape($_POST['fromtag']), $toTag);
1089 $LINKSDB->save($conf->get('resource.page_cache')); 1089 $LINKSDB->save($conf->get('resource.page_cache'));
1090 foreach ($alteredLinks as $link) { 1090 foreach ($alteredLinks as $link) {
1091 $history->updateLink($link); 1091 $history->updateLink($link);
@@ -1237,10 +1237,10 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history, $sessionManager,
1237 $id = (int) escape($id); 1237 $id = (int) escape($id);
1238 $link = $LINKSDB[$id]; 1238 $link = $LINKSDB[$id];
1239 $pluginManager->executeHooks('delete_link', $link); 1239 $pluginManager->executeHooks('delete_link', $link);
1240 $history->deleteLink($link);
1240 unset($LINKSDB[$id]); 1241 unset($LINKSDB[$id]);
1241 } 1242 }
1242 $LINKSDB->save($conf->get('resource.page_cache')); // save to disk 1243 $LINKSDB->save($conf->get('resource.page_cache')); // save to disk
1243 $history->deleteLink($link);
1244 1244
1245 // If we are called from the bookmarklet, we must close the popup: 1245 // If we are called from the bookmarklet, we must close the popup:
1246 if (isset($_GET['source']) && ($_GET['source']=='bookmarklet' || $_GET['source']=='firefoxsocialapi')) { echo '<script>self.close();</script>'; exit; } 1246 if (isset($_GET['source']) && ($_GET['source']=='bookmarklet' || $_GET['source']=='firefoxsocialapi')) { echo '<script>self.close();</script>'; exit; }
@@ -1353,6 +1353,25 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history, $sessionManager,
1353 exit; 1353 exit;
1354 } 1354 }
1355 1355
1356 if ($targetPage == Router::$PAGE_PINLINK) {
1357 if (! isset($_GET['id']) || empty($LINKSDB[$_GET['id']])) {
1358 // FIXME! Use a proper error system.
1359 $msg = t('Invalid link ID provided');
1360 echo '<script>alert("'. $msg .'");document.location=\''. index_url($_SERVER) .'\';</script>';
1361 exit;
1362 }
1363 if (! $sessionManager->checkToken($_GET['token'])) {
1364 die('Wrong token.');
1365 }
1366
1367 $link = $LINKSDB[$_GET['id']];
1368 $link['sticky'] = ! $link['sticky'];
1369 $LINKSDB[(int) $_GET['id']] = $link;
1370 $LINKSDB->save($conf->get('resource.page_cache'));
1371 header('Location: '.index_url($_SERVER));
1372 exit;
1373 }
1374
1356 if ($targetPage == Router::$PAGE_EXPORT) { 1375 if ($targetPage == Router::$PAGE_EXPORT) {
1357 // Export links as a Netscape Bookmarks file 1376 // Export links as a Netscape Bookmarks file
1358 1377
@@ -1636,9 +1655,9 @@ function buildLinkList($PAGE, $LINKSDB, $conf, $pluginManager, $loginManager)
1636 uasort($taglist, 'strcasecmp'); 1655 uasort($taglist, 'strcasecmp');
1637 $link['taglist'] = $taglist; 1656 $link['taglist'] = $taglist;
1638 1657
1639 // Thumbnails enabled, not a note, 1658 // Logged in, thumbnails enabled, not a note,
1640 // and (never retrieved yet or no valid cache file) 1659 // and (never retrieved yet or no valid cache file)
1641 if ($thumbnailsEnabled && $link['url'][0] != '?' 1660 if ($loginManager->isLoggedIn() && $thumbnailsEnabled && $link['url'][0] != '?'
1642 && (! isset($link['thumbnail']) || ($link['thumbnail'] !== false && ! is_file($link['thumbnail']))) 1661 && (! isset($link['thumbnail']) || ($link['thumbnail'] !== false && ! is_file($link['thumbnail'])))
1643 ) { 1662 ) {
1644 $elem = $LINKSDB[$keys[$i]]; 1663 $elem = $LINKSDB[$keys[$i]];
@@ -1812,7 +1831,11 @@ function install($conf, $sessionManager, $loginManager) {
1812 exit; 1831 exit;
1813} 1832}
1814 1833
1815if (isset($_SERVER['QUERY_STRING']) && startsWith($_SERVER['QUERY_STRING'], 'do=dailyrss')) { showDailyRSS($conf); exit; } 1834if (isset($_SERVER['QUERY_STRING']) && startsWith($_SERVER['QUERY_STRING'], 'do=dailyrss')) {
1835 showDailyRSS($conf, $loginManager);
1836 exit;
1837}
1838
1816if (!isset($_SESSION['LINKS_PER_PAGE'])) { 1839if (!isset($_SESSION['LINKS_PER_PAGE'])) {
1817 $_SESSION['LINKS_PER_PAGE'] = $conf->get('general.links_per_page', 20); 1840 $_SESSION['LINKS_PER_PAGE'] = $conf->get('general.links_per_page', 20);
1818} 1841}
@@ -1855,6 +1878,7 @@ $app->group('/api/v1', function() {
1855})->add('\Shaarli\Api\ApiMiddleware'); 1878})->add('\Shaarli\Api\ApiMiddleware');
1856 1879
1857$response = $app->run(true); 1880$response = $app->run(true);
1881
1858// Hack to make Slim and Shaarli router work together: 1882// Hack to make Slim and Shaarli router work together:
1859// If a Slim route isn't found and NOT API call, we call renderPage(). 1883// If a Slim route isn't found and NOT API call, we call renderPage().
1860if ($response->getStatusCode() == 404 && strpos($_SERVER['REQUEST_URI'], '/api/v1') === false) { 1884if ($response->getStatusCode() == 404 && strpos($_SERVER['REQUEST_URI'], '/api/v1') === false) {
@@ -1862,5 +1886,12 @@ if ($response->getStatusCode() == 404 && strpos($_SERVER['REQUEST_URI'], '/api/v
1862 header('Content-Type: text/html; charset=utf-8'); 1886 header('Content-Type: text/html; charset=utf-8');
1863 renderPage($conf, $pluginManager, $linkDb, $history, $sessionManager, $loginManager); 1887 renderPage($conf, $pluginManager, $linkDb, $history, $sessionManager, $loginManager);
1864} else { 1888} else {
1889 $response = $response
1890 ->withHeader('Access-Control-Allow-Origin', '*')
1891 ->withHeader(
1892 'Access-Control-Allow-Headers',
1893 'X-Requested-With, Content-Type, Accept, Origin, Authorization'
1894 )
1895 ->withHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
1865 $app->respond($response); 1896 $app->respond($response);
1866} 1897}