miniflux-legacy/app/controllers/bookmark.php

130 lines
4.0 KiB
PHP
Raw Permalink Normal View History

<?php
namespace Miniflux\Controller;
use DateTime;
use Miniflux\Session\SessionStorage;
2016-08-25 03:17:58 +02:00
use Miniflux\Router;
use Miniflux\Response;
use Miniflux\Request;
use Miniflux\Template;
use Miniflux\Helper;
use Miniflux\Model;
use Miniflux\Handler\Service;
use PicoFeed\Syndication\AtomFeedBuilder;
use PicoFeed\Syndication\AtomItemBuilder;
// Ajax call to add or remove a bookmark
2016-04-18 01:44:45 +02:00
Router\post_action('bookmark', function () {
$user_id = SessionStorage::getInstance()->getUserId();
2016-12-26 23:19:38 +01:00
$item_id = Request\int_param('id');
$value = Request\int_param('value');
if ($value == 1) {
Service\sync($user_id, $item_id);
}
Response\json(array(
'id' => $item_id,
'value' => $value,
'result' => Model\Bookmark\set_flag($user_id, $item_id, $value),
));
});
// Add new bookmark
2016-04-18 01:44:45 +02:00
Router\get_action('bookmark', function () {
$user_id = SessionStorage::getInstance()->getUserId();
2016-12-26 23:19:38 +01:00
$item_id = Request\int_param('id');
$menu = Request\param('menu');
$redirect = Request\param('redirect', 'unread');
$offset = Request\int_param('offset', 0);
$feed_id = Request\int_param('feed_id', 0);
$value = Request\int_param('value');
if ($value == 1) {
Service\sync($user_id, $item_id);
}
Model\Bookmark\set_flag($user_id, $item_id, $value);
if ($redirect === 'show') {
Response\redirect('?action=show&menu='.$menu.'&id='.$item_id);
}
Response\redirect('?action='.$redirect.'&offset='.$offset.'&feed_id='.$feed_id.'#item-'.$item_id);
});
// Display bookmarks page
2016-04-18 01:44:45 +02:00
Router\get_action('bookmarks', function () {
$user_id = SessionStorage::getInstance()->getUserId();
$offset = Request\int_param('offset', 0);
$group_id = Request\int_param('group_id', null);
$feed_ids = array();
2016-05-03 10:45:07 +02:00
if ($group_id !== null) {
$feed_ids = Model\Group\get_feed_ids_by_group($group_id);
}
$nb_items = Model\Bookmark\count_bookmarked_items($user_id, $feed_ids);
$items = Model\Bookmark\get_bookmarked_items(
$user_id,
$offset,
Helper\config('items_per_page'),
$feed_ids
);
2017-01-21 20:40:24 +01:00
Response\html(Template\layout('bookmarks/items', array(
'favicons' => Model\Favicon\get_items_favicons($items),
'original_marks_read' => Helper\config('original_marks_read'),
'order' => '',
'direction' => '',
'display_mode' => Helper\config('items_display_mode'),
'item_title_link' => Helper\config('item_title_link'),
'group_id' => $group_id,
2014-12-24 23:54:27 +01:00
'items' => $items,
'nb_items' => $nb_items,
'offset' => $offset,
'items_per_page' => Helper\config('items_per_page'),
'nothing_to_read' => Request\int_param('nothing_to_read'),
'menu' => 'bookmarks',
'groups' => Model\Group\get_all($user_id),
'title' => t('Bookmarks').' ('.$nb_items.')'
)));
});
2014-02-08 20:13:14 +01:00
// Display bookmark feeds
2016-04-18 01:44:45 +02:00
Router\get_action('bookmark-feed', function () {
$token = Request\param('token');
$user = Model\User\get_user_by_token('feed_token', $token);
2014-02-08 20:13:14 +01:00
if (empty($user)) {
Response\text('Unauthorized', 401);
2014-02-08 20:13:14 +01:00
}
$bookmarks = Model\Bookmark\get_bookmarked_items($user['id']);
2014-02-08 20:13:14 +01:00
$feedBuilder = AtomFeedBuilder::create()
->withTitle(t('Bookmarks').' - Miniflux')
->withFeedUrl(Helper\get_current_base_url().'?action=bookmark-feed&token='.urlencode($user['feed_token']))
->withSiteUrl(Helper\get_current_base_url())
->withDate(new DateTime())
;
2014-02-08 20:13:14 +01:00
foreach ($bookmarks as $bookmark) {
$articleDate = new DateTime();
$articleDate->setTimestamp($bookmark['updated']);
$feedBuilder
->withItem(AtomItemBuilder::create($feedBuilder)
->withId($bookmark['id'])
->withTitle($bookmark['title'])
->withUrl($bookmark['url'])
->withUpdatedDate($articleDate)
->withPublishedDate($articleDate)
->withContent($bookmark['content'])
);
2014-02-08 20:13:14 +01:00
}
Response\xml($feedBuilder->build());
2014-02-08 20:13:14 +01:00
});