aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/front/controller/visitor
diff options
context:
space:
mode:
Diffstat (limited to 'application/front/controller/visitor')
-rw-r--r--application/front/controller/visitor/BookmarkListController.php63
-rw-r--r--application/front/controller/visitor/DailyController.php2
-rw-r--r--application/front/controller/visitor/PictureWallController.php12
3 files changed, 29 insertions, 48 deletions
diff --git a/application/front/controller/visitor/BookmarkListController.php b/application/front/controller/visitor/BookmarkListController.php
index fe8231be..321ca813 100644
--- a/application/front/controller/visitor/BookmarkListController.php
+++ b/application/front/controller/visitor/BookmarkListController.php
@@ -36,7 +36,6 @@ class BookmarkListController extends ShaarliVisitorController
36 36
37 $searchTags = normalize_spaces($request->getParam('searchtags') ?? ''); 37 $searchTags = normalize_spaces($request->getParam('searchtags') ?? '');
38 $searchTerm = escape(normalize_spaces($request->getParam('searchterm') ?? '')); 38 $searchTerm = escape(normalize_spaces($request->getParam('searchterm') ?? ''));
39 ;
40 39
41 // Filter bookmarks according search parameters. 40 // Filter bookmarks according search parameters.
42 $visibility = $this->container->sessionManager->getSessionParameter('visibility'); 41 $visibility = $this->container->sessionManager->getSessionParameter('visibility');
@@ -44,39 +43,26 @@ class BookmarkListController extends ShaarliVisitorController
44 'searchtags' => $searchTags, 43 'searchtags' => $searchTags,
45 'searchterm' => $searchTerm, 44 'searchterm' => $searchTerm,
46 ]; 45 ];
47 $linksToDisplay = $this->container->bookmarkService->search(
48 $search,
49 $visibility,
50 false,
51 !!$this->container->sessionManager->getSessionParameter('untaggedonly')
52 ) ?? [];
53
54 // ---- Handle paging.
55 $keys = [];
56 foreach ($linksToDisplay as $key => $value) {
57 $keys[] = $key;
58 }
59
60 $linksPerPage = $this->container->sessionManager->getSessionParameter('LINKS_PER_PAGE', 20) ?: 20;
61 46
62 // Select articles according to paging. 47 // Select articles according to paging.
63 $pageCount = (int) ceil(count($keys) / $linksPerPage) ?: 1; 48 $page = (int) ($request->getParam('page') ?? 1);
64 $page = (int) $request->getParam('page') ?? 1;
65 $page = $page < 1 ? 1 : $page; 49 $page = $page < 1 ? 1 : $page;
66 $page = $page > $pageCount ? $pageCount : $page; 50 $linksPerPage = $this->container->sessionManager->getSessionParameter('LINKS_PER_PAGE', 20) ?: 20;
67 51
68 // Start index. 52 $searchResult = $this->container->bookmarkService->search(
69 $i = ($page - 1) * $linksPerPage; 53 $search,
70 $end = $i + $linksPerPage; 54 $visibility,
55 false,
56 !!$this->container->sessionManager->getSessionParameter('untaggedonly'),
57 false,
58 ['offset' => $linksPerPage * ($page - 1), 'limit' => $linksPerPage]
59 ) ?? [];
71 60
72 $linkDisp = [];
73 $save = false; 61 $save = false;
74 while ($i < $end && $i < count($keys)) { 62 $links = [];
75 $save = $this->updateThumbnail($linksToDisplay[$keys[$i]], false) || $save; 63 foreach ($searchResult->getBookmarks() as $key => $bookmark) {
76 $link = $formatter->format($linksToDisplay[$keys[$i]]); 64 $save = $this->updateThumbnail($bookmark, false) || $save;
77 65 $links[$key] = $formatter->format($bookmark);
78 $linkDisp[$keys[$i]] = $link;
79 $i++;
80 } 66 }
81 67
82 if ($save) { 68 if ($save) {
@@ -86,15 +72,10 @@ class BookmarkListController extends ShaarliVisitorController
86 // Compute paging navigation 72 // Compute paging navigation
87 $searchtagsUrl = $searchTags === '' ? '' : '&searchtags=' . urlencode($searchTags); 73 $searchtagsUrl = $searchTags === '' ? '' : '&searchtags=' . urlencode($searchTags);
88 $searchtermUrl = $searchTerm === '' ? '' : '&searchterm=' . urlencode($searchTerm); 74 $searchtermUrl = $searchTerm === '' ? '' : '&searchterm=' . urlencode($searchTerm);
75 $page = $searchResult->getPage();
89 76
90 $previous_page_url = ''; 77 $previousPageUrl = !$searchResult->isLastPage() ? '?page=' . ($page + 1) . $searchtermUrl . $searchtagsUrl : '';
91 if ($i !== count($keys)) { 78 $nextPageUrl = !$searchResult->isFirstPage() ? '?page=' . ($page - 1) . $searchtermUrl . $searchtagsUrl : '';
92 $previous_page_url = '?page=' . ($page + 1) . $searchtermUrl . $searchtagsUrl;
93 }
94 $next_page_url = '';
95 if ($page > 1) {
96 $next_page_url = '?page=' . ($page - 1) . $searchtermUrl . $searchtagsUrl;
97 }
98 79
99 $tagsSeparator = $this->container->conf->get('general.tags_separator', ' '); 80 $tagsSeparator = $this->container->conf->get('general.tags_separator', ' ');
100 $searchTagsUrlEncoded = array_map('urlencode', tags_str2array($searchTags, $tagsSeparator)); 81 $searchTagsUrlEncoded = array_map('urlencode', tags_str2array($searchTags, $tagsSeparator));
@@ -104,16 +85,16 @@ class BookmarkListController extends ShaarliVisitorController
104 $data = array_merge( 85 $data = array_merge(
105 $this->initializeTemplateVars(), 86 $this->initializeTemplateVars(),
106 [ 87 [
107 'previous_page_url' => $previous_page_url, 88 'previous_page_url' => $previousPageUrl,
108 'next_page_url' => $next_page_url, 89 'next_page_url' => $nextPageUrl,
109 'page_current' => $page, 90 'page_current' => $page,
110 'page_max' => $pageCount, 91 'page_max' => $searchResult->getLastPage(),
111 'result_count' => count($linksToDisplay), 92 'result_count' => $searchResult->getTotalCount(),
112 'search_term' => escape($searchTerm), 93 'search_term' => escape($searchTerm),
113 'search_tags' => escape($searchTags), 94 'search_tags' => escape($searchTags),
114 'search_tags_url' => $searchTagsUrlEncoded, 95 'search_tags_url' => $searchTagsUrlEncoded,
115 'visibility' => $visibility, 96 'visibility' => $visibility,
116 'links' => $linkDisp, 97 'links' => $links,
117 ] 98 ]
118 ); 99 );
119 100
diff --git a/application/front/controller/visitor/DailyController.php b/application/front/controller/visitor/DailyController.php
index 29492a5f..3739ec16 100644
--- a/application/front/controller/visitor/DailyController.php
+++ b/application/front/controller/visitor/DailyController.php
@@ -100,7 +100,7 @@ class DailyController extends ShaarliVisitorController
100 $days = []; 100 $days = [];
101 $format = DailyPageHelper::getFormatByType($type); 101 $format = DailyPageHelper::getFormatByType($type);
102 $length = DailyPageHelper::getRssLengthByType($type); 102 $length = DailyPageHelper::getRssLengthByType($type);
103 foreach ($this->container->bookmarkService->search() as $bookmark) { 103 foreach ($this->container->bookmarkService->search()->getBookmarks() as $bookmark) {
104 $day = $bookmark->getCreated()->format($format); 104 $day = $bookmark->getCreated()->format($format);
105 105
106 // Stop iterating after DAILY_RSS_NB_DAYS entries 106 // Stop iterating after DAILY_RSS_NB_DAYS entries
diff --git a/application/front/controller/visitor/PictureWallController.php b/application/front/controller/visitor/PictureWallController.php
index 23553ee6..9c8f07d7 100644
--- a/application/front/controller/visitor/PictureWallController.php
+++ b/application/front/controller/visitor/PictureWallController.php
@@ -30,19 +30,19 @@ class PictureWallController extends ShaarliVisitorController
30 ); 30 );
31 31
32 // Optionally filter the results: 32 // Optionally filter the results:
33 $links = $this->container->bookmarkService->search($request->getQueryParams()); 33 $bookmarks = $this->container->bookmarkService->search($request->getQueryParams())->getBookmarks();
34 $linksToDisplay = []; 34 $links = [];
35 35
36 // Get only bookmarks which have a thumbnail. 36 // Get only bookmarks which have a thumbnail.
37 // Note: we do not retrieve thumbnails here, the request is too heavy. 37 // Note: we do not retrieve thumbnails here, the request is too heavy.
38 $formatter = $this->container->formatterFactory->getFormatter('raw'); 38 $formatter = $this->container->formatterFactory->getFormatter('raw');
39 foreach ($links as $key => $link) { 39 foreach ($bookmarks as $key => $bookmark) {
40 if (!empty($link->getThumbnail())) { 40 if (!empty($bookmark->getThumbnail())) {
41 $linksToDisplay[] = $formatter->format($link); 41 $links[] = $formatter->format($bookmark);
42 } 42 }
43 } 43 }
44 44
45 $data = ['linksToDisplay' => $linksToDisplay]; 45 $data = ['linksToDisplay' => $links];
46 $this->executePageHooks('render_picwall', $data, TemplatePage::PICTURE_WALL); 46 $this->executePageHooks('render_picwall', $data, TemplatePage::PICTURE_WALL);
47 47
48 foreach ($data as $key => $value) { 48 foreach ($data as $key => $value) {