diff options
author | ArthurHoaro <arthur@hoa.ro> | 2017-11-11 14:01:21 +0100 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2018-07-05 20:31:35 +0200 |
commit | e85b7a05a177f803ae36ba5c12835313f31177bc (patch) | |
tree | 99216fbcb3343b74eac2589d14bf75c0a6d5fb01 /index.php | |
parent | a3724717ec37d4bd54dc117ef439c8a182157882 (diff) | |
download | Shaarli-e85b7a05a177f803ae36ba5c12835313f31177bc.tar.gz Shaarli-e85b7a05a177f803ae36ba5c12835313f31177bc.tar.zst Shaarli-e85b7a05a177f803ae36ba5c12835313f31177bc.zip |
Update thumbnail integration after rebasing the branch
Diffstat (limited to 'index.php')
-rw-r--r-- | index.php | 39 |
1 files changed, 16 insertions, 23 deletions
@@ -74,13 +74,13 @@ require_once 'application/Url.php'; | |||
74 | require_once 'application/Utils.php'; | 74 | require_once 'application/Utils.php'; |
75 | require_once 'application/PluginManager.php'; | 75 | require_once 'application/PluginManager.php'; |
76 | require_once 'application/Router.php'; | 76 | require_once 'application/Router.php'; |
77 | require_once 'application/Thumbnailer.php'; | ||
78 | require_once 'application/Updater.php'; | 77 | require_once 'application/Updater.php'; |
79 | use \Shaarli\Languages; | ||
80 | use \Shaarli\ThemeUtils; | ||
81 | use \Shaarli\Config\ConfigManager; | 78 | use \Shaarli\Config\ConfigManager; |
79 | use \Shaarli\Languages; | ||
82 | use \Shaarli\Security\LoginManager; | 80 | use \Shaarli\Security\LoginManager; |
83 | use \Shaarli\Security\SessionManager; | 81 | use \Shaarli\Security\SessionManager; |
82 | use \Shaarli\ThemeUtils; | ||
83 | use \Shaarli\Thumbnailer; | ||
84 | 84 | ||
85 | // Ensure the PHP version is supported | 85 | // Ensure the PHP version is supported |
86 | try { | 86 | try { |
@@ -603,7 +603,7 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history, $sessionManager, | |||
603 | if ($targetPage == Router::$PAGE_PICWALL) | 603 | if ($targetPage == Router::$PAGE_PICWALL) |
604 | { | 604 | { |
605 | if (! $conf->get('thumbnails.enabled')) { | 605 | if (! $conf->get('thumbnails.enabled')) { |
606 | header('Location: ?'); | 606 | $PAGE->renderPage('picwall'); |
607 | exit; | 607 | exit; |
608 | } | 608 | } |
609 | 609 | ||
@@ -614,23 +614,19 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history, $sessionManager, | |||
614 | $thumbnailer = new Thumbnailer($conf); | 614 | $thumbnailer = new Thumbnailer($conf); |
615 | 615 | ||
616 | 616 | ||
617 | $cpt = 0; | 617 | $newThumbnailsCpt = 0; |
618 | // Get only links which have a thumbnail. | 618 | // Get only links which have a thumbnail. |
619 | foreach($links as $link) | 619 | foreach($links as $key => $link) |
620 | { | 620 | { |
621 | $permalink='?'.$link['shorturl']; | ||
622 | // Not a note, | 621 | // Not a note, |
623 | // and (never retrieved yet or no valid cache file) | 622 | // and (never retrieved yet or no valid cache file) |
624 | if ($link['url'][0] != '?' | 623 | if ($link['url'][0] != '?' |
625 | && (! isset($link['thumbnail']) || ($link['thumbnail'] !== false && ! is_file($link['thumbnail']))) | 624 | && (! isset($link['thumbnail']) || ($link['thumbnail'] !== false && ! is_file($link['thumbnail']))) |
626 | ) { | 625 | ) { |
627 | $link['thumbnail'] = $thumbnailer->get($link['url']); | 626 | $item = $LINKSDB[$key]; |
628 | // FIXME! we really need to get rid of ArrayAccess... | 627 | $item['thumbnail'] = $thumbnailer->get($link['url']); |
629 | $item = $LINKSDB[$link['linkdate']]; | 628 | $LINKSDB[$key] = $item; |
630 | $item['thumbnail'] = $link['thumbnail']; | 629 | $newThumbnailsCpt++; |
631 | $LINKSDB[$link['linkdate']] = $item; | ||
632 | $updateDB = true; | ||
633 | $cpt++; | ||
634 | } | 630 | } |
635 | 631 | ||
636 | if (isset($link['thumbnail']) && $link['thumbnail'] !== false) { | 632 | if (isset($link['thumbnail']) && $link['thumbnail'] !== false) { |
@@ -639,14 +635,13 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history, $sessionManager, | |||
639 | 635 | ||
640 | // If we retrieved new thumbnails, we update the database every 20 links. | 636 | // If we retrieved new thumbnails, we update the database every 20 links. |
641 | // Downloading everything the first time may take a very long time | 637 | // Downloading everything the first time may take a very long time |
642 | if (!empty($updateDB) && $cpt == 20) { | 638 | if ($newThumbnailsCpt == 20) { |
643 | $LINKSDB->save($conf->get('resource.page_cache')); | 639 | $LINKSDB->save($conf->get('resource.page_cache')); |
644 | $updateDB = false; | 640 | $newThumbnailsCpt = 0; |
645 | $cpt = 0; | ||
646 | } | 641 | } |
647 | } | 642 | } |
648 | 643 | ||
649 | if (!empty($updateDB)) { | 644 | if ($newThumbnailsCpt > 0) { |
650 | $LINKSDB->save($conf->get('resource.page_cache')); | 645 | $LINKSDB->save($conf->get('resource.page_cache')); |
651 | } | 646 | } |
652 | 647 | ||
@@ -1619,11 +1614,9 @@ function buildLinkList($PAGE, $LINKSDB, $conf, $pluginManager, $loginManager) | |||
1619 | if ($conf->get('thumbnails.enabled') && $link['url'][0] != '?' | 1614 | if ($conf->get('thumbnails.enabled') && $link['url'][0] != '?' |
1620 | && (! isset($link['thumbnail']) || ($link['thumbnail'] !== false && ! is_file($link['thumbnail']))) | 1615 | && (! isset($link['thumbnail']) || ($link['thumbnail'] !== false && ! is_file($link['thumbnail']))) |
1621 | ) { | 1616 | ) { |
1622 | $link['thumbnail'] = $thumbnailer->get($link['url']); | 1617 | $elem = $LINKSDB[$keys[$i]]; |
1623 | // FIXME! we really need to get rid of ArrayAccess... | 1618 | $elem['thumbnail'] = $thumbnailer->get($link['url']); |
1624 | $item = $LINKSDB[$keys[$i]]; | 1619 | $LINKSDB[$keys[$i]] = $elem; |
1625 | $item['thumbnail'] = $link['thumbnail']; | ||
1626 | $LINKSDB[$keys[$i]] = $item; | ||
1627 | $updateDB = true; | 1620 | $updateDB = true; |
1628 | } | 1621 | } |
1629 | 1622 | ||