aboutsummaryrefslogtreecommitdiffhomepage
path: root/index.php
diff options
context:
space:
mode:
Diffstat (limited to 'index.php')
-rw-r--r--index.php85
1 files changed, 58 insertions, 27 deletions
diff --git a/index.php b/index.php
index a27681dc..ff42114c 100644
--- a/index.php
+++ b/index.php
@@ -312,9 +312,7 @@ function showDailyRSS($conf, $loginManager)
312 $LINKSDB = new LinkDB( 312 $LINKSDB = new LinkDB(
313 $conf->get('resource.datastore'), 313 $conf->get('resource.datastore'),
314 $loginManager->isLoggedIn(), 314 $loginManager->isLoggedIn(),
315 $conf->get('privacy.hide_public_links'), 315 $conf->get('privacy.hide_public_links')
316 $conf->get('redirector.url'),
317 $conf->get('redirector.encode_url')
318 ); 316 );
319 317
320 /* Some Shaarlies may have very few links, so we need to look 318 /* Some Shaarlies may have very few links, so we need to look
@@ -356,13 +354,9 @@ function showDailyRSS($conf, $loginManager)
356 354
357 // We pre-format some fields for proper output. 355 // We pre-format some fields for proper output.
358 foreach ($links as &$link) { 356 foreach ($links as &$link) {
359 $link['formatedDescription'] = format_description( 357 $link['formatedDescription'] = format_description($link['description']);
360 $link['description'],
361 $conf->get('redirector.url'),
362 $conf->get('redirector.encode_url')
363 );
364 $link['timestamp'] = $link['created']->getTimestamp(); 358 $link['timestamp'] = $link['created']->getTimestamp();
365 if (startsWith($link['url'], '?')) { 359 if (is_note($link['url'])) {
366 $link['url'] = index_url($_SERVER) . $link['url']; // make permalink URL absolute 360 $link['url'] = index_url($_SERVER) . $link['url']; // make permalink URL absolute
367 } 361 }
368 } 362 }
@@ -433,11 +427,7 @@ function showDaily($pageBuilder, $LINKSDB, $conf, $pluginManager, $loginManager)
433 $taglist = explode(' ', $link['tags']); 427 $taglist = explode(' ', $link['tags']);
434 uasort($taglist, 'strcasecmp'); 428 uasort($taglist, 'strcasecmp');
435 $linksToDisplay[$key]['taglist']=$taglist; 429 $linksToDisplay[$key]['taglist']=$taglist;
436 $linksToDisplay[$key]['formatedDescription'] = format_description( 430 $linksToDisplay[$key]['formatedDescription'] = format_description($link['description']);
437 $link['description'],
438 $conf->get('redirector.url'),
439 $conf->get('redirector.encode_url')
440 );
441 $linksToDisplay[$key]['timestamp'] = $link['created']->getTimestamp(); 431 $linksToDisplay[$key]['timestamp'] = $link['created']->getTimestamp();
442 } 432 }
443 433
@@ -1074,7 +1064,6 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history, $sessionManager,
1074 $PAGE->assign('api_enabled', $conf->get('api.enabled', true)); 1064 $PAGE->assign('api_enabled', $conf->get('api.enabled', true));
1075 $PAGE->assign('api_secret', $conf->get('api.secret')); 1065 $PAGE->assign('api_secret', $conf->get('api.secret'));
1076 $PAGE->assign('languages', Languages::getAvailableLanguages()); 1066 $PAGE->assign('languages', Languages::getAvailableLanguages());
1077 $PAGE->assign('language', $conf->get('translation.language'));
1078 $PAGE->assign('gd_enabled', extension_loaded('gd')); 1067 $PAGE->assign('gd_enabled', extension_loaded('gd'));
1079 $PAGE->assign('thumbnails_mode', $conf->get('thumbnails.mode', Thumbnailer::MODE_NONE)); 1068 $PAGE->assign('thumbnails_mode', $conf->get('thumbnails.mode', Thumbnailer::MODE_NONE));
1080 $PAGE->assign('pagetitle', t('Configure') .' - '. $conf->get('general.title', 'Shaarli')); 1069 $PAGE->assign('pagetitle', t('Configure') .' - '. $conf->get('general.title', 'Shaarli'));
@@ -1176,11 +1165,15 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history, $sessionManager,
1176 $link['title'] = $link['url']; 1165 $link['title'] = $link['url'];
1177 } 1166 }
1178 1167
1179 if ($conf->get('thumbnails.mode', Thumbnailer::MODE_NONE) !== Thumbnailer::MODE_NONE) { 1168 if ($conf->get('thumbnails.mode', Thumbnailer::MODE_NONE) !== Thumbnailer::MODE_NONE
1169 && ! is_note($link['url'])
1170 ) {
1180 $thumbnailer = new Thumbnailer($conf); 1171 $thumbnailer = new Thumbnailer($conf);
1181 $link['thumbnail'] = $thumbnailer->get($url); 1172 $link['thumbnail'] = $thumbnailer->get($url);
1182 } 1173 }
1183 1174
1175 $link['sticky'] = isset($link['sticky']) ? $link['sticky'] : false;
1176
1184 $pluginManager->executeHooks('save_link', $link); 1177 $pluginManager->executeHooks('save_link', $link);
1185 1178
1186 $LINKSDB[$id] = $link; 1179 $LINKSDB[$id] = $link;
@@ -1273,6 +1266,51 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history, $sessionManager,
1273 exit; 1266 exit;
1274 } 1267 }
1275 1268
1269 // -------- User clicked either "Set public" or "Set private" bulk operation
1270 if ($targetPage == Router::$PAGE_CHANGE_VISIBILITY) {
1271 if (! $sessionManager->checkToken($_GET['token'])) {
1272 die(t('Wrong token.'));
1273 }
1274
1275 $ids = trim($_GET['ids']);
1276 if (strpos($ids, ' ') !== false) {
1277 // multiple, space-separated ids provided
1278 $ids = array_values(array_filter(preg_split('/\s+/', escape($ids))));
1279 } else {
1280 // only a single id provided
1281 $ids = [$ids];
1282 }
1283
1284 // assert at least one id is given
1285 if (!count($ids)) {
1286 die('no id provided');
1287 }
1288 // assert that the visibility is valid
1289 if (!isset($_GET['newVisibility']) || !in_array($_GET['newVisibility'], ['public', 'private'])) {
1290 die('invalid visibility');
1291 } else {
1292 $private = $_GET['newVisibility'] === 'private';
1293 }
1294 foreach ($ids as $id) {
1295 $id = (int) escape($id);
1296 $link = $LINKSDB[$id];
1297 $link['private'] = $private;
1298 $pluginManager->executeHooks('save_link', $link);
1299 $LINKSDB[$id] = $link;
1300 }
1301 $LINKSDB->save($conf->get('resource.page_cache')); // save to disk
1302
1303 $location = '?';
1304 if (isset($_SERVER['HTTP_REFERER'])) {
1305 $location = generateLocation(
1306 $_SERVER['HTTP_REFERER'],
1307 $_SERVER['HTTP_HOST']
1308 );
1309 }
1310 header('Location: ' . $location); // After deleting the link, redirect to appropriate location
1311 exit;
1312 }
1313
1276 // -------- User clicked the "EDIT" button on a link: Display link edit form. 1314 // -------- User clicked the "EDIT" button on a link: Display link edit form.
1277 if (isset($_GET['edit_link'])) { 1315 if (isset($_GET['edit_link'])) {
1278 $id = (int) escape($_GET['edit_link']); 1316 $id = (int) escape($_GET['edit_link']);
@@ -1558,7 +1596,7 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history, $sessionManager,
1558 $ids = []; 1596 $ids = [];
1559 foreach ($LINKSDB as $link) { 1597 foreach ($LINKSDB as $link) {
1560 // A note or not HTTP(S) 1598 // A note or not HTTP(S)
1561 if ($link['url'][0] === '?' || ! startsWith(strtolower($link['url']), 'http')) { 1599 if (is_note($link['url']) || ! startsWith(strtolower($link['url']), 'http')) {
1562 continue; 1600 continue;
1563 } 1601 }
1564 $ids[] = $link['id']; 1602 $ids[] = $link['id'];
@@ -1662,11 +1700,7 @@ function buildLinkList($PAGE, $LINKSDB, $conf, $pluginManager, $loginManager)
1662 $linkDisp = array(); 1700 $linkDisp = array();
1663 while ($i<$end && $i<count($keys)) { 1701 while ($i<$end && $i<count($keys)) {
1664 $link = $linksToDisplay[$keys[$i]]; 1702 $link = $linksToDisplay[$keys[$i]];
1665 $link['description'] = format_description( 1703 $link['description'] = format_description($link['description']);
1666 $link['description'],
1667 $conf->get('redirector.url'),
1668 $conf->get('redirector.encode_url')
1669 );
1670 $classLi = ($i % 2) != 0 ? '' : 'publicLinkHightLight'; 1704 $classLi = ($i % 2) != 0 ? '' : 'publicLinkHightLight';
1671 $link['class'] = $link['private'] == 0 ? $classLi : 'private'; 1705 $link['class'] = $link['private'] == 0 ? $classLi : 'private';
1672 $link['timestamp'] = $link['created']->getTimestamp(); 1706 $link['timestamp'] = $link['created']->getTimestamp();
@@ -1727,7 +1761,6 @@ function buildLinkList($PAGE, $LINKSDB, $conf, $pluginManager, $loginManager)
1727 'search_term' => $searchterm, 1761 'search_term' => $searchterm,
1728 'search_tags' => $searchtags, 1762 'search_tags' => $searchtags,
1729 'visibility' => ! empty($_SESSION['visibility']) ? $_SESSION['visibility'] : '', 1763 'visibility' => ! empty($_SESSION['visibility']) ? $_SESSION['visibility'] : '',
1730 'redirector' => $conf->get('redirector.url'), // Optional redirector URL.
1731 'links' => $linkDisp, 1764 'links' => $linkDisp,
1732 ); 1765 );
1733 1766
@@ -1877,9 +1910,7 @@ try {
1877$linkDb = new LinkDB( 1910$linkDb = new LinkDB(
1878 $conf->get('resource.datastore'), 1911 $conf->get('resource.datastore'),
1879 $loginManager->isLoggedIn(), 1912 $loginManager->isLoggedIn(),
1880 $conf->get('privacy.hide_public_links'), 1913 $conf->get('privacy.hide_public_links')
1881 $conf->get('redirector.url'),
1882 $conf->get('redirector.encode_url')
1883); 1914);
1884 1915
1885$container = new \Slim\Container(); 1916$container = new \Slim\Container();
@@ -1902,7 +1933,7 @@ $app->group('/api/v1', function () {
1902 $this->put('/tags/{tagName:[\w]+}', '\Shaarli\Api\Controllers\Tags:putTag')->setName('putTag'); 1933 $this->put('/tags/{tagName:[\w]+}', '\Shaarli\Api\Controllers\Tags:putTag')->setName('putTag');
1903 $this->delete('/tags/{tagName:[\w]+}', '\Shaarli\Api\Controllers\Tags:deleteTag')->setName('deleteTag'); 1934 $this->delete('/tags/{tagName:[\w]+}', '\Shaarli\Api\Controllers\Tags:deleteTag')->setName('deleteTag');
1904 1935
1905 $this->get('/history', '\Shaarli\Api\Controllers\History:getHistory')->setName('getHistory'); 1936 $this->get('/history', '\Shaarli\Api\Controllers\HistoryController:getHistory')->setName('getHistory');
1906})->add('\Shaarli\Api\ApiMiddleware'); 1937})->add('\Shaarli\Api\ApiMiddleware');
1907 1938
1908$response = $app->run(true); 1939$response = $app->run(true);