aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/front/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'application/front/controllers')
-rw-r--r--application/front/controllers/DailyController.php74
1 files changed, 74 insertions, 0 deletions
diff --git a/application/front/controllers/DailyController.php b/application/front/controllers/DailyController.php
index 271c0ee2..4a0735aa 100644
--- a/application/front/controllers/DailyController.php
+++ b/application/front/controllers/DailyController.php
@@ -5,6 +5,7 @@ declare(strict_types=1);
5namespace Shaarli\Front\Controller; 5namespace Shaarli\Front\Controller;
6 6
7use DateTime; 7use DateTime;
8use DateTimeImmutable;
8use Shaarli\Bookmark\Bookmark; 9use Shaarli\Bookmark\Bookmark;
9use Slim\Http\Request; 10use Slim\Http\Request;
10use Slim\Http\Response; 11use Slim\Http\Response;
@@ -18,6 +19,8 @@ use Slim\Http\Response;
18 */ 19 */
19class DailyController extends ShaarliController 20class DailyController extends ShaarliController
20{ 21{
22 public static $DAILY_RSS_NB_DAYS = 8;
23
21 /** 24 /**
22 * Controller displaying all bookmarks published in a single day. 25 * Controller displaying all bookmarks published in a single day.
23 * It take a `day` date query parameter (format YYYYMMDD). 26 * It take a `day` date query parameter (format YYYYMMDD).
@@ -88,6 +91,77 @@ class DailyController extends ShaarliController
88 } 91 }
89 92
90 /** 93 /**
94 * Daily RSS feed: 1 RSS entry per day giving all the bookmarks on that day.
95 * Gives the last 7 days (which have bookmarks).
96 * This RSS feed cannot be filtered and does not trigger plugins yet.
97 */
98 public function rss(Request $request, Response $response): Response
99 {
100 $response = $response->withHeader('Content-Type', 'application/rss+xml; charset=utf-8');
101
102 $pageUrl = page_url($this->container->environment);
103 $cache = $this->container->pageCacheManager->getCachePage($pageUrl);
104
105 $cached = $cache->cachedVersion();
106 if (!empty($cached)) {
107 return $response->write($cached);
108 }
109
110 $days = [];
111 foreach ($this->container->bookmarkService->search() as $bookmark) {
112 $day = $bookmark->getCreated()->format('Ymd');
113
114 // Stop iterating after DAILY_RSS_NB_DAYS entries
115 if (count($days) === static::$DAILY_RSS_NB_DAYS && !isset($days[$day])) {
116 break;
117 }
118
119 $days[$day][] = $bookmark;
120 }
121
122 // Build the RSS feed.
123 $indexUrl = escape(index_url($this->container->environment));
124
125 $formatter = $this->container->formatterFactory->getFormatter();
126 $formatter->addContextData('index_url', $indexUrl);
127
128 $dataPerDay = [];
129
130 /** @var Bookmark[] $bookmarks */
131 foreach ($days as $day => $bookmarks) {
132 $dayDatetime = DateTimeImmutable::createFromFormat(Bookmark::LINK_DATE_FORMAT, $day.'_000000');
133 $dataPerDay[$day] = [
134 'date' => $dayDatetime,
135 'date_rss' => $dayDatetime->format(DateTime::RSS),
136 'date_human' => format_date($dayDatetime, false, true),
137 'absolute_url' => $indexUrl . '/daily?day=' . $day,
138 'links' => [],
139 ];
140
141 foreach ($bookmarks as $key => $bookmark) {
142 $dataPerDay[$day]['links'][$key] = $formatter->format($bookmark);
143
144 // Make permalink URL absolute
145 if ($bookmark->isNote()) {
146 $dataPerDay[$day]['links'][$key]['url'] = $indexUrl . $bookmark->getUrl();
147 }
148 }
149 }
150
151 $this->assignView('title', $this->container->conf->get('general.title', 'Shaarli'));
152 $this->assignView('index_url', $indexUrl);
153 $this->assignView('page_url', $pageUrl);
154 $this->assignView('hide_timestamps', $this->container->conf->get('privacy.hide_timestamps', false));
155 $this->assignView('days', $dataPerDay);
156
157 $rssContent = $this->render('dailyrss');
158
159 $cache->cache($rssContent);
160
161 return $response->write($rssContent);
162 }
163
164 /**
91 * We need to spread the articles on 3 columns. 165 * We need to spread the articles on 3 columns.
92 * did not want to use a JavaScript lib like http://masonry.desandro.com/ 166 * did not want to use a JavaScript lib like http://masonry.desandro.com/
93 * so I manually spread entries with a simple method: I roughly evaluate the 167 * so I manually spread entries with a simple method: I roughly evaluate the