aboutsummaryrefslogtreecommitdiffhomepage
path: root/index.php
diff options
context:
space:
mode:
Diffstat (limited to 'index.php')
-rw-r--r--index.php103
1 files changed, 3 insertions, 100 deletions
diff --git a/index.php b/index.php
index dbb76d3f..9dc67c4b 100644
--- a/index.php
+++ b/index.php
@@ -301,104 +301,6 @@ if (!isset($_SESSION['tokens'])) {
301} 301}
302 302
303/** 303/**
304 * Daily RSS feed: 1 RSS entry per day giving all the bookmarks on that day.
305 * Gives the last 7 days (which have bookmarks).
306 * This RSS feed cannot be filtered.
307 *
308 * @param BookmarkServiceInterface $bookmarkService
309 * @param ConfigManager $conf Configuration Manager instance
310 * @param LoginManager $loginManager LoginManager instance
311 */
312function showDailyRSS($bookmarkService, $conf, $loginManager)
313{
314 // Cache system
315 $query = $_SERVER['QUERY_STRING'];
316 $cache = new CachedPage(
317 $conf->get('config.PAGE_CACHE'),
318 page_url($_SERVER),
319 startsWith($query, 'do=dailyrss') && !$loginManager->isLoggedIn()
320 );
321 $cached = $cache->cachedVersion();
322 if (!empty($cached)) {
323 echo $cached;
324 exit;
325 }
326
327 /* Some Shaarlies may have very few bookmarks, so we need to look
328 back in time until we have enough days ($nb_of_days).
329 */
330 $nb_of_days = 7; // We take 7 days.
331 $today = date('Ymd');
332 $days = array();
333
334 foreach ($bookmarkService->search() as $bookmark) {
335 $day = $bookmark->getCreated()->format('Ymd'); // Extract day (without time)
336 if (strcmp($day, $today) < 0) {
337 if (empty($days[$day])) {
338 $days[$day] = array();
339 }
340 $days[$day][] = $bookmark;
341 }
342
343 if (count($days) > $nb_of_days) {
344 break; // Have we collected enough days?
345 }
346 }
347
348 // Build the RSS feed.
349 header('Content-Type: application/rss+xml; charset=utf-8');
350 $pageaddr = escape(index_url($_SERVER));
351 echo '<?xml version="1.0" encoding="UTF-8"?><rss version="2.0">';
352 echo '<channel>';
353 echo '<title>Daily - '. $conf->get('general.title') . '</title>';
354 echo '<link>'. $pageaddr .'</link>';
355 echo '<description>Daily shared bookmarks</description>';
356 echo '<language>en-en</language>';
357 echo '<copyright>'. $pageaddr .'</copyright>'. PHP_EOL;
358
359 $factory = new FormatterFactory($conf, $loginManager->isLoggedIn());
360 $formatter = $factory->getFormatter();
361 $formatter->addContextData('index_url', index_url($_SERVER));
362 // For each day.
363 /** @var Bookmark[] $bookmarks */
364 foreach ($days as $day => $bookmarks) {
365 $formattedBookmarks = [];
366 $dayDate = DateTime::createFromFormat(Bookmark::LINK_DATE_FORMAT, $day.'_000000');
367 $absurl = escape(index_url($_SERVER).'?do=daily&day='.$day); // Absolute URL of the corresponding "Daily" page.
368
369 // We pre-format some fields for proper output.
370 foreach ($bookmarks as $key => $bookmark) {
371 $formattedBookmarks[$key] = $formatter->format($bookmark);
372 // This page is a bit specific, we need raw description to calculate the length
373 $formattedBookmarks[$key]['formatedDescription'] = $formattedBookmarks[$key]['description'];
374 $formattedBookmarks[$key]['description'] = $bookmark->getDescription();
375
376 if ($bookmark->isNote()) {
377 $link['url'] = index_url($_SERVER) . $bookmark->getUrl(); // make permalink URL absolute
378 }
379 }
380
381 // Then build the HTML for this day:
382 $tpl = new RainTPL();
383 $tpl->assign('title', $conf->get('general.title'));
384 $tpl->assign('daydate', $dayDate->getTimestamp());
385 $tpl->assign('absurl', $absurl);
386 $tpl->assign('links', $formattedBookmarks);
387 $tpl->assign('rssdate', escape($dayDate->format(DateTime::RSS)));
388 $tpl->assign('hide_timestamps', $conf->get('privacy.hide_timestamps', false));
389 $tpl->assign('index_url', $pageaddr);
390 $html = $tpl->draw('dailyrss', true);
391
392 echo $html . PHP_EOL;
393 }
394 echo '</channel></rss><!-- Cached version of '. escape(page_url($_SERVER)) .' -->';
395
396 $cache->cache(ob_get_contents());
397 ob_end_flush();
398 exit;
399}
400
401/**
402 * Renders the linklist 304 * Renders the linklist
403 * 305 *
404 * @param pageBuilder $PAGE pageBuilder instance. 306 * @param pageBuilder $PAGE pageBuilder instance.
@@ -424,7 +326,7 @@ function showLinkList($PAGE, $linkDb, $conf, $pluginManager, $loginManager)
424 */ 326 */
425function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionManager, $loginManager) 327function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionManager, $loginManager)
426{ 328{
427 $pageCacheManager = new PageCacheManager($conf->get('resource.page_cache')); 329 $pageCacheManager = new PageCacheManager($conf->get('resource.page_cache'), $loginManager->isLoggedIn());
428 $updater = new Updater( 330 $updater = new Updater(
429 UpdaterUtils::read_updates_file($conf->get('resource.updates')), 331 UpdaterUtils::read_updates_file($conf->get('resource.updates')),
430 $bookmarkService, 332 $bookmarkService,
@@ -1715,7 +1617,7 @@ try {
1715$linkDb = new BookmarkFileService($conf, $history, $loginManager->isLoggedIn()); 1617$linkDb = new BookmarkFileService($conf, $history, $loginManager->isLoggedIn());
1716 1618
1717if (isset($_SERVER['QUERY_STRING']) && startsWith($_SERVER['QUERY_STRING'], 'do=dailyrss')) { 1619if (isset($_SERVER['QUERY_STRING']) && startsWith($_SERVER['QUERY_STRING'], 'do=dailyrss')) {
1718 showDailyRSS($linkDb, $conf, $loginManager); 1620 header('Location: ./daily-rss');
1719 exit; 1621 exit;
1720} 1622}
1721 1623
@@ -1747,6 +1649,7 @@ $app->group('', function () {
1747 $this->get('/tag-cloud', '\Shaarli\Front\Controller\TagCloudController:cloud')->setName('tagcloud'); 1649 $this->get('/tag-cloud', '\Shaarli\Front\Controller\TagCloudController:cloud')->setName('tagcloud');
1748 $this->get('/tag-list', '\Shaarli\Front\Controller\TagCloudController:list')->setName('taglist'); 1650 $this->get('/tag-list', '\Shaarli\Front\Controller\TagCloudController:list')->setName('taglist');
1749 $this->get('/daily', '\Shaarli\Front\Controller\DailyController:index')->setName('daily'); 1651 $this->get('/daily', '\Shaarli\Front\Controller\DailyController:index')->setName('daily');
1652 $this->get('/daily-rss', '\Shaarli\Front\Controller\DailyController:rss')->setName('dailyrss');
1750 1653
1751 $this->get('/add-tag/{newTag}', '\Shaarli\Front\Controller\TagController:addTag')->setName('add-tag'); 1654 $this->get('/add-tag/{newTag}', '\Shaarli\Front\Controller\TagController:addTag')->setName('add-tag');
1752})->add('\Shaarli\Front\ShaarliMiddleware'); 1655})->add('\Shaarli\Front\ShaarliMiddleware');