2013-12-23 02:55:53 +01:00
|
|
|
<?php
|
|
|
|
|
2016-04-18 01:34:54 +02:00
|
|
|
use PicoFeed\Syndication\AtomFeedBuilder;
|
|
|
|
use PicoFeed\Syndication\AtomItemBuilder;
|
2013-12-23 02:55:53 +01:00
|
|
|
|
|
|
|
// Ajax call to add or remove a bookmark
|
2016-04-18 01:44:45 +02:00
|
|
|
Router\post_action('bookmark', function () {
|
2013-12-23 02:55:53 +01:00
|
|
|
$id = Request\param('id');
|
|
|
|
$value = Request\int_param('value');
|
|
|
|
|
2014-03-30 03:03:05 +02:00
|
|
|
Response\json(array(
|
|
|
|
'id' => $id,
|
|
|
|
'value' => $value,
|
2016-08-19 03:44:36 +02:00
|
|
|
'result' => Model\Bookmark\set_flag($id, $value),
|
2014-03-30 03:03:05 +02:00
|
|
|
));
|
2013-12-23 02:55:53 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// Add new bookmark
|
2016-04-18 01:44:45 +02:00
|
|
|
Router\get_action('bookmark', function () {
|
2013-12-23 02:55:53 +01:00
|
|
|
$id = Request\param('id');
|
2016-08-05 20:21:40 +02:00
|
|
|
$menu = Request\param('menu');
|
|
|
|
$redirect = Request\param('redirect', 'unread');
|
2013-12-23 02:55:53 +01:00
|
|
|
$offset = Request\int_param('offset', 0);
|
|
|
|
$feed_id = Request\int_param('feed_id', 0);
|
|
|
|
|
2016-08-19 03:44:36 +02:00
|
|
|
Model\Bookmark\set_flag($id, Request\int_param('value'));
|
2013-12-23 02:55:53 +01:00
|
|
|
|
2016-08-05 20:21:40 +02:00
|
|
|
if ($redirect === 'show') {
|
2016-04-18 01:34:54 +02:00
|
|
|
Response\redirect('?action=show&menu='.$menu.'&id='.$id);
|
2013-12-23 02:55:53 +01:00
|
|
|
}
|
|
|
|
|
2016-08-05 20:21:40 +02:00
|
|
|
Response\redirect('?action='.$redirect.'&offset='.$offset.'&feed_id='.$feed_id.'#item-'.$id);
|
2013-12-23 02:55:53 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// Display bookmarks page
|
2016-04-18 01:44:45 +02:00
|
|
|
Router\get_action('bookmarks', function () {
|
2013-12-23 02:55:53 +01:00
|
|
|
$offset = Request\int_param('offset', 0);
|
2016-02-28 15:39:16 +01:00
|
|
|
$group_id = Request\int_param('group_id', null);
|
|
|
|
$feed_ids = array();
|
2016-04-18 01:34:54 +02:00
|
|
|
|
2016-05-03 10:45:07 +02:00
|
|
|
if ($group_id !== null) {
|
2016-02-28 15:39:16 +01:00
|
|
|
$feed_ids = Model\Group\get_feeds_by_group($group_id);
|
|
|
|
}
|
2016-04-18 01:34:54 +02:00
|
|
|
|
2016-08-19 03:44:36 +02:00
|
|
|
$nb_items = Model\Bookmark\count_items($feed_ids);
|
|
|
|
$items = Model\Bookmark\get_all_items(
|
2016-02-28 15:39:16 +01:00
|
|
|
$offset,
|
|
|
|
Model\Config\get('items_per_page'),
|
|
|
|
$feed_ids
|
|
|
|
);
|
2013-12-23 02:55:53 +01:00
|
|
|
|
|
|
|
Response\html(Template\layout('bookmarks', array(
|
2016-01-10 01:04:42 +01:00
|
|
|
'favicons' => Model\Favicon\get_item_favicons($items),
|
2015-01-29 23:28:18 +01:00
|
|
|
'original_marks_read' => Model\Config\get('original_marks_read'),
|
2013-12-23 02:55:53 +01:00
|
|
|
'order' => '',
|
|
|
|
'direction' => '',
|
2014-05-29 16:57:23 +02:00
|
|
|
'display_mode' => Model\Config\get('items_display_mode'),
|
2016-02-27 20:21:18 +01:00
|
|
|
'item_title_link' => Model\Config\get('item_title_link'),
|
2016-02-28 15:39:16 +01:00
|
|
|
'group_id' => $group_id,
|
2014-12-24 23:54:27 +01:00
|
|
|
'items' => $items,
|
2013-12-23 02:55:53 +01:00
|
|
|
'nb_items' => $nb_items,
|
|
|
|
'offset' => $offset,
|
|
|
|
'items_per_page' => Model\Config\get('items_per_page'),
|
2013-12-23 19:33:16 +01:00
|
|
|
'nothing_to_read' => Request\int_param('nothing_to_read'),
|
2014-11-15 14:32:31 +01:00
|
|
|
'nb_unread_items' => Model\Item\count_by_status('unread'),
|
2013-12-23 02:55:53 +01:00
|
|
|
'menu' => 'bookmarks',
|
2016-02-28 15:39:16 +01:00
|
|
|
'groups' => Model\Group\get_all(),
|
2013-12-23 02:55:53 +01:00
|
|
|
'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 () {
|
2015-12-07 23:57:57 +01:00
|
|
|
// Select database if the parameter is set
|
|
|
|
$database = Request\param('database');
|
2016-04-18 01:34:54 +02:00
|
|
|
|
2015-12-07 23:57:57 +01:00
|
|
|
if (!empty($database)) {
|
|
|
|
Model\Database\select($database);
|
|
|
|
}
|
|
|
|
|
2014-02-08 20:13:14 +01:00
|
|
|
// Check token
|
|
|
|
$feed_token = Model\Config\get('feed_token');
|
|
|
|
$request_token = Request\param('token');
|
|
|
|
|
|
|
|
if ($feed_token !== $request_token) {
|
|
|
|
Response\text('Access Forbidden', 403);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build Feed
|
2016-08-19 03:44:36 +02:00
|
|
|
$bookmarks = Model\Bookmark\get_all_items();
|
2014-02-08 20:13:14 +01:00
|
|
|
|
2016-04-18 01:34:54 +02:00
|
|
|
$feedBuilder = AtomFeedBuilder::create()
|
|
|
|
->withTitle(t('Bookmarks').' - Miniflux')
|
|
|
|
->withFeedUrl(Helper\get_current_base_url().'?action=bookmark-feed&token='.urlencode($feed_token))
|
|
|
|
->withSiteUrl(Helper\get_current_base_url())
|
|
|
|
->withDate(new DateTime())
|
|
|
|
;
|
2014-02-08 20:13:14 +01:00
|
|
|
|
2016-04-18 01:34:54 +02:00
|
|
|
foreach ($bookmarks as $bookmark) {
|
2014-02-08 20:13:14 +01:00
|
|
|
$article = Model\Item\get($bookmark['id']);
|
2016-04-18 01:34:54 +02:00
|
|
|
$articleDate = new DateTime();
|
|
|
|
$articleDate->setTimestamp($article['updated']);
|
|
|
|
|
|
|
|
$feedBuilder
|
|
|
|
->withItem(AtomItemBuilder::create($feedBuilder)
|
|
|
|
->withId($article['id'])
|
|
|
|
->withTitle($article['title'])
|
|
|
|
->withUrl($article['url'])
|
|
|
|
->withUpdatedDate($articleDate)
|
|
|
|
->withPublishedDate($articleDate)
|
|
|
|
->withContent($article['content'])
|
|
|
|
);
|
2014-02-08 20:13:14 +01:00
|
|
|
}
|
|
|
|
|
2016-04-18 01:34:54 +02:00
|
|
|
Response\xml($feedBuilder->build());
|
2014-02-08 20:13:14 +01:00
|
|
|
});
|