2013-12-23 02:55:53 +01:00
|
|
|
<?php
|
|
|
|
|
2014-02-08 20:13:14 +01:00
|
|
|
// Display unread items
|
|
|
|
Router\get_action('unread', function() {
|
2014-12-16 02:38:35 +01:00
|
|
|
Model\Item\autoflush_read();
|
|
|
|
Model\Item\autoflush_unread();
|
2014-02-08 20:13:14 +01:00
|
|
|
|
|
|
|
$order = Request\param('order', 'updated');
|
|
|
|
$direction = Request\param('direction', Model\Config\get('items_sorting_direction'));
|
|
|
|
$offset = Request\int_param('offset', 0);
|
2015-08-05 01:01:21 +02:00
|
|
|
$group_id = Request\int_param('group_id', null);
|
2015-08-15 03:33:39 +02:00
|
|
|
$feed_ids = array();
|
2014-02-08 20:13:14 +01:00
|
|
|
|
2015-08-15 04:08:04 +02:00
|
|
|
if (! is_null($group_id)) {
|
2015-08-05 01:01:21 +02:00
|
|
|
$feed_ids = Model\Group\get_feeds_by_group($group_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
$items = Model\Item\get_all_by_status(
|
|
|
|
'unread',
|
|
|
|
$feed_ids,
|
|
|
|
$offset,
|
|
|
|
Model\Config\get('items_per_page'),
|
|
|
|
$order,
|
|
|
|
$direction
|
|
|
|
);
|
2014-02-08 20:13:14 +01:00
|
|
|
|
2015-08-05 01:01:21 +02:00
|
|
|
$nb_items = Model\Item\count_by_status('unread', $feed_ids);
|
|
|
|
$nb_unread_items = Model\Item\count_by_status('unread');
|
|
|
|
|
|
|
|
if ($nb_unread_items === 0) {
|
2014-02-08 20:13:14 +01:00
|
|
|
$action = Model\Config\get('redirect_nothing_to_read');
|
|
|
|
Response\redirect('?action='.$action.'¬hing_to_read=1');
|
|
|
|
}
|
|
|
|
|
|
|
|
Response\html(Template\layout('unread_items', 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'),
|
2014-02-08 20:13:14 +01:00
|
|
|
'order' => $order,
|
|
|
|
'direction' => $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'),
|
2015-08-05 01:01:21 +02:00
|
|
|
'group_id' => $group_id,
|
2014-02-08 20:13:14 +01:00
|
|
|
'items' => $items,
|
|
|
|
'nb_items' => $nb_items,
|
2015-08-05 01:01:21 +02:00
|
|
|
'nb_unread_items' => $nb_unread_items,
|
2014-02-08 20:13:14 +01:00
|
|
|
'offset' => $offset,
|
|
|
|
'items_per_page' => Model\Config\get('items_per_page'),
|
|
|
|
'title' => 'Miniflux ('.$nb_items.')',
|
2015-08-05 01:01:21 +02:00
|
|
|
'menu' => 'unread',
|
|
|
|
'groups' => Model\Group\get_all()
|
2014-02-08 20:13:14 +01:00
|
|
|
)));
|
|
|
|
});
|
|
|
|
|
2013-12-23 02:55:53 +01:00
|
|
|
// Show item
|
|
|
|
Router\get_action('show', function() {
|
|
|
|
$id = Request\param('id');
|
|
|
|
$menu = Request\param('menu');
|
|
|
|
$item = Model\Item\get($id);
|
|
|
|
$feed = Model\Feed\get($item['feed_id']);
|
2015-11-19 16:31:31 +01:00
|
|
|
$group_id = Request\int_param('group_id', null);
|
2013-12-23 02:55:53 +01:00
|
|
|
|
|
|
|
Model\Item\set_read($id);
|
2014-12-11 03:12:42 +01:00
|
|
|
$item['status'] = 'read';
|
2013-12-23 02:55:53 +01:00
|
|
|
|
|
|
|
switch ($menu) {
|
|
|
|
case 'unread':
|
2015-11-19 16:31:31 +01:00
|
|
|
$nav = Model\Item\get_nav($item, array('unread'), array(1, 0), null, $group_id);
|
2013-12-23 02:55:53 +01:00
|
|
|
break;
|
|
|
|
case 'history':
|
|
|
|
$nav = Model\Item\get_nav($item, array('read'));
|
|
|
|
break;
|
|
|
|
case 'feed-items':
|
|
|
|
$nav = Model\Item\get_nav($item, array('unread', 'read'), array(1, 0), $item['feed_id']);
|
|
|
|
break;
|
|
|
|
case 'bookmarks':
|
|
|
|
$nav = Model\Item\get_nav($item, array('unread', 'read'), array(1));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-05-17 19:33:13 +02:00
|
|
|
$image_proxy = (bool) Model\Config\get('image_proxy');
|
2015-02-01 22:54:57 +01:00
|
|
|
|
|
|
|
// add the image proxy if requested and required
|
2015-05-17 19:33:13 +02:00
|
|
|
$item['content'] = Model\Proxy\rewrite_html($item['content'], $item['url'], $image_proxy, $feed['cloak_referrer']);
|
2015-02-01 22:54:57 +01:00
|
|
|
|
|
|
|
if ($image_proxy && strpos($item['enclosure_type'], 'image') === 0) {
|
2015-05-17 19:33:13 +02:00
|
|
|
$item['enclosure'] = Model\Proxy\rewrite_link($item['enclosure']);
|
2015-02-01 22:54:57 +01:00
|
|
|
}
|
|
|
|
|
2013-12-23 02:55:53 +01:00
|
|
|
Response\html(Template\layout('show_item', array(
|
2015-10-20 03:21:18 +02:00
|
|
|
'nb_unread_items' => Model\Item\count_by_status('unread'),
|
2013-12-23 02:55:53 +01:00
|
|
|
'item' => $item,
|
|
|
|
'feed' => $feed,
|
|
|
|
'item_nav' => isset($nav) ? $nav : null,
|
|
|
|
'menu' => $menu,
|
2014-12-24 21:58:24 +01:00
|
|
|
'title' => $item['title'],
|
2015-11-19 16:31:31 +01:00
|
|
|
'group_id' => $group_id,
|
2013-12-23 02:55:53 +01:00
|
|
|
)));
|
|
|
|
});
|
|
|
|
|
|
|
|
// Display feed items page
|
|
|
|
Router\get_action('feed-items', function() {
|
|
|
|
$feed_id = Request\int_param('feed_id', 0);
|
|
|
|
$offset = Request\int_param('offset', 0);
|
|
|
|
$nb_items = Model\Item\count_by_feed($feed_id);
|
|
|
|
$feed = Model\Feed\get($feed_id);
|
|
|
|
$order = Request\param('order', 'updated');
|
|
|
|
$direction = Request\param('direction', Model\Config\get('items_sorting_direction'));
|
|
|
|
$items = Model\Item\get_all_by_feed($feed_id, $offset, Model\Config\get('items_per_page'), $order, $direction);
|
|
|
|
|
|
|
|
Response\html(Template\layout('feed_items', array(
|
2016-01-12 01:53:18 +01:00
|
|
|
'favicons' => Model\Favicon\get_favicons(array($feed['id'])),
|
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' => $order,
|
|
|
|
'direction' => $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
|
|
|
'feed' => $feed,
|
|
|
|
'items' => $items,
|
|
|
|
'nb_items' => $nb_items,
|
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
|
|
|
'offset' => $offset,
|
|
|
|
'items_per_page' => Model\Config\get('items_per_page'),
|
2016-02-28 20:47:05 +01:00
|
|
|
'item_title_link' => Model\Config\get('item_title_link'),
|
2013-12-23 02:55:53 +01:00
|
|
|
'menu' => 'feed-items',
|
|
|
|
'title' => '('.$nb_items.') '.$feed['title']
|
|
|
|
)));
|
|
|
|
});
|
|
|
|
|
|
|
|
// Ajax call to download an item (fetch the full content from the original website)
|
|
|
|
Router\post_action('download-item', function() {
|
2015-02-01 22:54:57 +01:00
|
|
|
$id = Request\param('id');
|
|
|
|
|
|
|
|
$item = Model\Item\get($id);
|
|
|
|
$feed = Model\Feed\get($item['feed_id']);
|
|
|
|
|
|
|
|
$download = Model\Item\download_content_id($id);
|
2015-05-17 19:33:13 +02:00
|
|
|
$download['content'] = Model\Proxy\rewrite_html($download['content'], $item['url'], Model\Config\get('image_proxy'), $feed['cloak_referrer']);
|
2013-12-23 02:55:53 +01:00
|
|
|
|
2015-02-01 22:54:57 +01:00
|
|
|
Response\json($download);
|
2013-12-23 02:55:53 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// Ajax call to mark item read
|
|
|
|
Router\post_action('mark-item-read', function() {
|
|
|
|
Model\Item\set_read(Request\param('id'));
|
2014-07-26 14:01:25 +02:00
|
|
|
Response\json(array('Ok'));
|
|
|
|
});
|
|
|
|
|
|
|
|
// Ajax call to mark item as removed
|
|
|
|
Router\post_action('mark-item-removed', function() {
|
|
|
|
Model\Item\set_removed(Request\param('id'));
|
2013-12-23 02:55:53 +01:00
|
|
|
Response\json(array('Ok'));
|
|
|
|
});
|
|
|
|
|
|
|
|
// Ajax call to mark item unread
|
|
|
|
Router\post_action('mark-item-unread', function() {
|
|
|
|
Model\Item\set_unread(Request\param('id'));
|
|
|
|
Response\json(array('Ok'));
|
|
|
|
});
|
|
|
|
|
2015-08-05 01:01:21 +02:00
|
|
|
// Mark unread items as read
|
2015-04-05 22:27:25 +02:00
|
|
|
Router\get_action('mark-all-read', function() {
|
2015-08-05 01:01:21 +02:00
|
|
|
$group_id = Request\int_param('group_id', null);
|
|
|
|
|
|
|
|
if (!is_null($group_id)) {
|
|
|
|
Model\Item\mark_group_as_read($group_id);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Model\Item\mark_all_as_read();
|
|
|
|
}
|
|
|
|
|
2013-12-23 02:55:53 +01:00
|
|
|
Response\redirect('?action=unread');
|
|
|
|
});
|
|
|
|
|
|
|
|
// Mark all unread items as read for a specific feed
|
|
|
|
Router\get_action('mark-feed-as-read', function() {
|
2015-03-08 12:56:59 +01:00
|
|
|
$feed_id = Request\int_param('feed_id');
|
|
|
|
|
|
|
|
Model\Item\mark_feed_as_read($feed_id);
|
|
|
|
Response\redirect('?action=feed-items&feed_id='.$feed_id);
|
2015-02-26 17:33:21 +01:00
|
|
|
});
|
|
|
|
|
2015-03-08 12:56:59 +01:00
|
|
|
// Mark all unread items as read for a specific feed (Ajax request) and return
|
|
|
|
// the number of unread items. It's not possible to get the number of items
|
|
|
|
// that where marked read from the frontend, since the number of unread items
|
|
|
|
// on page 2+ is unknown.
|
2015-02-26 17:33:21 +01:00
|
|
|
Router\post_action('mark-feed-as-read', function() {
|
|
|
|
Model\Item\mark_feed_as_read(Request\int_param('feed_id'));
|
2015-03-08 12:56:59 +01:00
|
|
|
$nb_items = Model\Item\count_by_status('unread');
|
|
|
|
|
|
|
|
Response\raw($nb_items);
|
2013-12-23 02:55:53 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// Mark item as read and redirect to the listing page
|
|
|
|
Router\get_action('mark-item-read', function() {
|
|
|
|
$id = Request\param('id');
|
|
|
|
$redirect = Request\param('redirect', 'unread');
|
|
|
|
$offset = Request\int_param('offset', 0);
|
|
|
|
$feed_id = Request\int_param('feed_id', 0);
|
|
|
|
|
|
|
|
Model\Item\set_read($id);
|
2016-04-18 01:34:54 +02:00
|
|
|
Response\redirect('?action='.$redirect.'&offset='.$offset.'&feed_id='.$feed_id.'#item-'.$id);
|
2013-12-23 02:55:53 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// Mark item as unread and redirect to the listing page
|
|
|
|
Router\get_action('mark-item-unread', function() {
|
|
|
|
$id = Request\param('id');
|
|
|
|
$redirect = Request\param('redirect', 'history');
|
|
|
|
$offset = Request\int_param('offset', 0);
|
|
|
|
$feed_id = Request\int_param('feed_id', 0);
|
|
|
|
|
|
|
|
Model\Item\set_unread($id);
|
2016-04-18 01:34:54 +02:00
|
|
|
Response\redirect('?action='.$redirect.'&offset='.$offset.'&feed_id='.$feed_id.'#item-'.$id);
|
2013-12-23 02:55:53 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// Mark item as removed and redirect to the listing page
|
|
|
|
Router\get_action('mark-item-removed', function() {
|
|
|
|
$id = Request\param('id');
|
|
|
|
$redirect = Request\param('redirect', 'history');
|
|
|
|
$offset = Request\int_param('offset', 0);
|
|
|
|
$feed_id = Request\int_param('feed_id', 0);
|
|
|
|
|
|
|
|
Model\Item\set_removed($id);
|
2016-04-18 01:34:54 +02:00
|
|
|
Response\redirect('?action='.$redirect.'&offset='.$offset.'&feed_id='.$feed_id);
|
2013-12-23 02:55:53 +01:00
|
|
|
});
|
implement frontend autoupdate
Only the unread counter is updated right know.
The AutoUpdate Feature is designed on the premise of don't wasting resources. A
distinction is made between updates when Miniflux is visible or hidden.
To determine the visibility status, the Page Visibility API is used. The API is
available starting with Chrome 33, Firefox 18 and IE10. [https://developer.mozilla.org/en-US/docs/Web/Guide/User_experience/Using_the_Page_Visibility_API]
As IE9 returns an undefined, it doesn't break the compatibility at least.
If Miniflux is visible, the unread counter on the web page is updated as soon as
a mismatch between the counter and the number of unread articles in the database
is found.
If Miniflux is hidden, the timestamp of the most recent article from each feed
is compared with the value from the last run. We have an update If the timestamp
of the latest article is greater than the stored one and the latest article is
unread. The web page title is updated with a ? symbol to notify the user and the
update check pauses till Miniflux gets visible again. If Miniflux gets visible
again, the number of unread articles is queried from the database, the unread
counter on the web page is updated and finally the ? symbol is removed from the
web page title.
This way I can use my fever API client to read new articles (or at least the
latest article) while Miniflux is hidden and as I've seen the new articles
already a new articles notification is prevented.
It's intentionally that the page does not reload automatically as long as
articles are visible. If I'm in hurry, I only scroll through the articles to
spot something interesting. Most of the time I don't reach the last article.
If the page is reloaded while I'm away, I would have to scan from the top again.
If we're on a nothing_to_read page and have unread articles in the database, a
redirect to the unread page will be done.
The default update check interval is 10 minutes and can be changed on the
settings page. A zero value disables the update check entirely.
fixes #213
2014-11-27 22:36:04 +01:00
|
|
|
|
|
|
|
Router\post_action('latest-feeds-items', function() {
|
|
|
|
$items = Model\Item\get_latest_feeds_items();
|
|
|
|
$nb_unread_items = Model\Item\count_by_status('unread');
|
2015-01-29 23:28:18 +01:00
|
|
|
|
implement frontend autoupdate
Only the unread counter is updated right know.
The AutoUpdate Feature is designed on the premise of don't wasting resources. A
distinction is made between updates when Miniflux is visible or hidden.
To determine the visibility status, the Page Visibility API is used. The API is
available starting with Chrome 33, Firefox 18 and IE10. [https://developer.mozilla.org/en-US/docs/Web/Guide/User_experience/Using_the_Page_Visibility_API]
As IE9 returns an undefined, it doesn't break the compatibility at least.
If Miniflux is visible, the unread counter on the web page is updated as soon as
a mismatch between the counter and the number of unread articles in the database
is found.
If Miniflux is hidden, the timestamp of the most recent article from each feed
is compared with the value from the last run. We have an update If the timestamp
of the latest article is greater than the stored one and the latest article is
unread. The web page title is updated with a ? symbol to notify the user and the
update check pauses till Miniflux gets visible again. If Miniflux gets visible
again, the number of unread articles is queried from the database, the unread
counter on the web page is updated and finally the ? symbol is removed from the
web page title.
This way I can use my fever API client to read new articles (or at least the
latest article) while Miniflux is hidden and as I've seen the new articles
already a new articles notification is prevented.
It's intentionally that the page does not reload automatically as long as
articles are visible. If I'm in hurry, I only scroll through the articles to
spot something interesting. Most of the time I don't reach the last article.
If the page is reloaded while I'm away, I would have to scan from the top again.
If we're on a nothing_to_read page and have unread articles in the database, a
redirect to the unread page will be done.
The default update check interval is 10 minutes and can be changed on the
settings page. A zero value disables the update check entirely.
fixes #213
2014-11-27 22:36:04 +01:00
|
|
|
$feeds = array_reduce($items, function ($result, $item) {
|
|
|
|
$result[$item['id']] = array(
|
|
|
|
'time' => $item['updated'] ?: 0,
|
|
|
|
'status' => $item['status']
|
|
|
|
);
|
|
|
|
return $result;
|
|
|
|
}, array());
|
2015-01-29 23:28:18 +01:00
|
|
|
|
implement frontend autoupdate
Only the unread counter is updated right know.
The AutoUpdate Feature is designed on the premise of don't wasting resources. A
distinction is made between updates when Miniflux is visible or hidden.
To determine the visibility status, the Page Visibility API is used. The API is
available starting with Chrome 33, Firefox 18 and IE10. [https://developer.mozilla.org/en-US/docs/Web/Guide/User_experience/Using_the_Page_Visibility_API]
As IE9 returns an undefined, it doesn't break the compatibility at least.
If Miniflux is visible, the unread counter on the web page is updated as soon as
a mismatch between the counter and the number of unread articles in the database
is found.
If Miniflux is hidden, the timestamp of the most recent article from each feed
is compared with the value from the last run. We have an update If the timestamp
of the latest article is greater than the stored one and the latest article is
unread. The web page title is updated with a ? symbol to notify the user and the
update check pauses till Miniflux gets visible again. If Miniflux gets visible
again, the number of unread articles is queried from the database, the unread
counter on the web page is updated and finally the ? symbol is removed from the
web page title.
This way I can use my fever API client to read new articles (or at least the
latest article) while Miniflux is hidden and as I've seen the new articles
already a new articles notification is prevented.
It's intentionally that the page does not reload automatically as long as
articles are visible. If I'm in hurry, I only scroll through the articles to
spot something interesting. Most of the time I don't reach the last article.
If the page is reloaded while I'm away, I would have to scan from the top again.
If we're on a nothing_to_read page and have unread articles in the database, a
redirect to the unread page will be done.
The default update check interval is 10 minutes and can be changed on the
settings page. A zero value disables the update check entirely.
fixes #213
2014-11-27 22:36:04 +01:00
|
|
|
Response\json(array(
|
|
|
|
'feeds' => $feeds,
|
|
|
|
'nbUnread' => $nb_unread_items
|
|
|
|
));
|
|
|
|
});
|