diff options
Diffstat (limited to 'index.php')
-rw-r--r-- | index.php | 81 |
1 files changed, 51 insertions, 30 deletions
@@ -514,7 +514,8 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history, $sessionManager, | |||
514 | read_updates_file($conf->get('resource.updates')), | 514 | read_updates_file($conf->get('resource.updates')), |
515 | $LINKSDB, | 515 | $LINKSDB, |
516 | $conf, | 516 | $conf, |
517 | $loginManager->isLoggedIn() | 517 | $loginManager->isLoggedIn(), |
518 | $_SESSION | ||
518 | ); | 519 | ); |
519 | try { | 520 | try { |
520 | $newUpdates = $updater->update(); | 521 | $newUpdates = $updater->update(); |
@@ -529,7 +530,7 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history, $sessionManager, | |||
529 | die($e->getMessage()); | 530 | die($e->getMessage()); |
530 | } | 531 | } |
531 | 532 | ||
532 | $PAGE = new PageBuilder($conf, $LINKSDB, $sessionManager->generateToken(), $loginManager->isLoggedIn()); | 533 | $PAGE = new PageBuilder($conf, $_SESSION, $LINKSDB, $sessionManager->generateToken(), $loginManager->isLoggedIn()); |
533 | $PAGE->assign('linkcount', count($LINKSDB)); | 534 | $PAGE->assign('linkcount', count($LINKSDB)); |
534 | $PAGE->assign('privateLinkcount', count_private($LINKSDB)); | 535 | $PAGE->assign('privateLinkcount', count_private($LINKSDB)); |
535 | $PAGE->assign('plugin_errors', $pluginManager->getErrors()); | 536 | $PAGE->assign('plugin_errors', $pluginManager->getErrors()); |
@@ -611,38 +612,13 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history, $sessionManager, | |||
611 | $links = $LINKSDB->filterSearch($_GET); | 612 | $links = $LINKSDB->filterSearch($_GET); |
612 | $linksToDisplay = array(); | 613 | $linksToDisplay = array(); |
613 | 614 | ||
614 | $thumbnailer = new Thumbnailer($conf); | ||
615 | |||
616 | |||
617 | $newThumbnailsCpt = 0; | ||
618 | // Get only links which have a thumbnail. | 615 | // Get only links which have a thumbnail. |
616 | // Note: we do not retrieve thumbnails here, the request is too heavy. | ||
619 | foreach($links as $key => $link) | 617 | foreach($links as $key => $link) |
620 | { | 618 | { |
621 | // Not a note, | ||
622 | // and (never retrieved yet or no valid cache file) | ||
623 | if ($link['url'][0] != '?' | ||
624 | && (! isset($link['thumbnail']) || ($link['thumbnail'] !== false && ! is_file($link['thumbnail']))) | ||
625 | ) { | ||
626 | $item = $LINKSDB[$key]; | ||
627 | $item['thumbnail'] = $thumbnailer->get($link['url']); | ||
628 | $LINKSDB[$key] = $item; | ||
629 | $newThumbnailsCpt++; | ||
630 | } | ||
631 | |||
632 | if (isset($link['thumbnail']) && $link['thumbnail'] !== false) { | 619 | if (isset($link['thumbnail']) && $link['thumbnail'] !== false) { |
633 | $linksToDisplay[] = $link; // Add to array. | 620 | $linksToDisplay[] = $link; // Add to array. |
634 | } | 621 | } |
635 | |||
636 | // If we retrieved new thumbnails, we update the database every 20 links. | ||
637 | // Downloading everything the first time may take a very long time | ||
638 | if ($newThumbnailsCpt == 20) { | ||
639 | $LINKSDB->save($conf->get('resource.page_cache')); | ||
640 | $newThumbnailsCpt = 0; | ||
641 | } | ||
642 | } | ||
643 | |||
644 | if ($newThumbnailsCpt > 0) { | ||
645 | $LINKSDB->save($conf->get('resource.page_cache')); | ||
646 | } | 622 | } |
647 | 623 | ||
648 | $data = array( | 624 | $data = array( |
@@ -1036,7 +1012,15 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history, $sessionManager, | |||
1036 | $conf->set('api.enabled', !empty($_POST['enableApi'])); | 1012 | $conf->set('api.enabled', !empty($_POST['enableApi'])); |
1037 | $conf->set('api.secret', escape($_POST['apiSecret'])); | 1013 | $conf->set('api.secret', escape($_POST['apiSecret'])); |
1038 | $conf->set('translation.language', escape($_POST['language'])); | 1014 | $conf->set('translation.language', escape($_POST['language'])); |
1039 | $conf->set('thumbnails.enabled', extension_loaded('gd') && !empty($_POST['enableThumbnails'])); | 1015 | |
1016 | $thumbnailsEnabled = extension_loaded('gd') && !empty($_POST['enableThumbnails']); | ||
1017 | $conf->set('thumbnails.enabled', $thumbnailsEnabled); | ||
1018 | |||
1019 | if (! $conf->get('thumbnails.enabled') && $thumbnailsEnabled) { | ||
1020 | $_SESSION['warnings'][] = t( | ||
1021 | 'You have enabled thumbnails. <a href="?do=thumbs_update">Please synchonize them</a>.' | ||
1022 | ); | ||
1023 | } | ||
1040 | 1024 | ||
1041 | try { | 1025 | try { |
1042 | $conf->write($loginManager->isLoggedIn()); | 1026 | $conf->write($loginManager->isLoggedIn()); |
@@ -1521,6 +1505,43 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history, $sessionManager, | |||
1521 | exit; | 1505 | exit; |
1522 | } | 1506 | } |
1523 | 1507 | ||
1508 | // -------- Thumbnails Update | ||
1509 | if ($targetPage == Router::$PAGE_THUMBS_UPDATE) { | ||
1510 | $ids = []; | ||
1511 | foreach ($LINKSDB as $link) { | ||
1512 | // A note or not HTTP(S) | ||
1513 | if ($link['url'][0] === '?' || ! startsWith(strtolower($link['url']), 'http')) { | ||
1514 | continue; | ||
1515 | } | ||
1516 | $ids[] = $link['id']; | ||
1517 | } | ||
1518 | $PAGE->assign('ids', $ids); | ||
1519 | $PAGE->assign('pagetitle', t('Thumbnail update') .' - '. $conf->get('general.title', 'Shaarli')); | ||
1520 | $PAGE->renderPage('thumbnails'); | ||
1521 | exit; | ||
1522 | } | ||
1523 | |||
1524 | // -------- Single Thumbnail Update | ||
1525 | if ($targetPage == Router::$AJAX_THUMB_UPDATE) { | ||
1526 | if (! isset($_POST['id']) || ! ctype_digit($_POST['id'])) { | ||
1527 | http_response_code(400); | ||
1528 | exit; | ||
1529 | } | ||
1530 | $id = (int) $_POST['id']; | ||
1531 | if (empty($LINKSDB[$id])) { | ||
1532 | http_response_code(404); | ||
1533 | exit; | ||
1534 | } | ||
1535 | $thumbnailer = new Thumbnailer($conf); | ||
1536 | $link = $LINKSDB[$id]; | ||
1537 | $link['thumbnail'] = $thumbnailer->get($link['url']); | ||
1538 | $LINKSDB[$id] = $link; | ||
1539 | $LINKSDB->save($conf->get('resource.page_cache')); | ||
1540 | |||
1541 | echo json_encode($link); | ||
1542 | exit; | ||
1543 | } | ||
1544 | |||
1524 | // -------- Otherwise, simply display search form and links: | 1545 | // -------- Otherwise, simply display search form and links: |
1525 | showLinkList($PAGE, $LINKSDB, $conf, $pluginManager, $loginManager); | 1546 | showLinkList($PAGE, $LINKSDB, $conf, $pluginManager, $loginManager); |
1526 | exit; | 1547 | exit; |
@@ -1777,7 +1798,7 @@ function install($conf, $sessionManager, $loginManager) { | |||
1777 | exit; | 1798 | exit; |
1778 | } | 1799 | } |
1779 | 1800 | ||
1780 | $PAGE = new PageBuilder($conf, null, $sessionManager->generateToken()); | 1801 | $PAGE = new PageBuilder($conf, $_SESSION, null, $sessionManager->generateToken()); |
1781 | list($continents, $cities) = generateTimeZoneData(timezone_identifiers_list(), date_default_timezone_get()); | 1802 | list($continents, $cities) = generateTimeZoneData(timezone_identifiers_list(), date_default_timezone_get()); |
1782 | $PAGE->assign('continents', $continents); | 1803 | $PAGE->assign('continents', $continents); |
1783 | $PAGE->assign('cities', $cities); | 1804 | $PAGE->assign('cities', $cities); |