2013-12-23 02:55:53 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use PicoFarad\Router;
|
|
|
|
use PicoFarad\Response;
|
|
|
|
use PicoFarad\Request;
|
|
|
|
use PicoFarad\Session;
|
2014-03-17 02:56:43 +01:00
|
|
|
use PicoFarad\Template;
|
2013-12-23 02:55:53 +01:00
|
|
|
|
|
|
|
// Ajax call to add or remove a bookmark
|
|
|
|
Router\post_action('bookmark', function() {
|
|
|
|
|
|
|
|
$id = Request\param('id');
|
|
|
|
$value = Request\int_param('value');
|
|
|
|
|
2014-03-30 03:03:05 +02:00
|
|
|
Response\json(array(
|
|
|
|
'id' => $id,
|
|
|
|
'value' => $value,
|
|
|
|
'result' => Model\Item\set_bookmark_value($id, $value),
|
|
|
|
));
|
2013-12-23 02:55:53 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// Add new bookmark
|
|
|
|
Router\get_action('bookmark', function() {
|
|
|
|
|
|
|
|
$id = Request\param('id');
|
|
|
|
$menu = Request\param('menu', 'unread');
|
|
|
|
$source = Request\param('source', 'unread');
|
|
|
|
$offset = Request\int_param('offset', 0);
|
|
|
|
$feed_id = Request\int_param('feed_id', 0);
|
|
|
|
|
|
|
|
Model\Item\set_bookmark_value($id, Request\int_param('value'));
|
|
|
|
|
|
|
|
if ($source === 'show') {
|
|
|
|
Response\Redirect('?action=show&menu='.$menu.'&id='.$id);
|
|
|
|
}
|
|
|
|
|
|
|
|
Response\Redirect('?action='.$menu.'&offset='.$offset.'&feed_id='.$feed_id.'#item-'.$id);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Display bookmarks page
|
|
|
|
Router\get_action('bookmarks', function() {
|
|
|
|
|
|
|
|
$offset = Request\int_param('offset', 0);
|
|
|
|
$nb_items = Model\Item\count_bookmarks();
|
|
|
|
|
|
|
|
Response\html(Template\layout('bookmarks', array(
|
|
|
|
'order' => '',
|
|
|
|
'direction' => '',
|
2014-05-29 16:57:23 +02:00
|
|
|
'display_mode' => Model\Config\get('items_display_mode'),
|
2013-12-23 02:55:53 +01:00
|
|
|
'items' => Model\Item\get_bookmarks($offset, Model\Config\get('items_per_page')),
|
|
|
|
'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'),
|
2013-12-23 02:55:53 +01:00
|
|
|
'menu' => 'bookmarks',
|
|
|
|
'title' => t('Bookmarks').' ('.$nb_items.')'
|
|
|
|
)));
|
|
|
|
});
|
2014-02-08 20:13:14 +01:00
|
|
|
|
|
|
|
// Display bookmark feeds
|
|
|
|
Router\get_action('bookmark-feed', function() {
|
|
|
|
|
|
|
|
// 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
|
|
|
|
$writer = new PicoFeed\Writers\Atom;
|
|
|
|
$writer->title = t('Bookmarks').' - Miniflux';
|
|
|
|
$writer->site_url = Helper\get_current_base_url();
|
|
|
|
$writer->feed_url = $writer->site_url.'?action=bookmark-feed&token='.urlencode($feed_token);
|
|
|
|
|
|
|
|
$bookmarks = Model\Item\get_bookmarks();
|
|
|
|
|
|
|
|
foreach ($bookmarks as $bookmark) {
|
|
|
|
|
|
|
|
$article = Model\Item\get($bookmark['id']);
|
|
|
|
|
|
|
|
$writer->items[] = array(
|
|
|
|
'id' => $article['id'],
|
|
|
|
'title' => $article['title'],
|
|
|
|
'updated' => $article['updated'],
|
|
|
|
'url' => $article['url'],
|
|
|
|
'content' => $article['content'],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Response\xml($writer->execute());
|
|
|
|
});
|