miniflux-legacy/index.php

852 lines
22 KiB
PHP
Raw Normal View History

2013-02-18 03:48:21 +01:00
<?php
require 'common.php';
require 'vendor/PicoTools/Template.php';
require 'vendor/PicoTools/Helper.php';
require 'vendor/PicoFarad/Response.php';
require 'vendor/PicoFarad/Request.php';
require 'vendor/PicoFarad/Session.php';
require 'vendor/PicoFarad/Router.php';
2013-07-17 03:58:11 +02:00
require 'helpers.php';
2013-02-18 03:48:21 +01:00
use PicoFarad\Router;
use PicoFarad\Response;
use PicoFarad\Request;
use PicoFarad\Session;
use PicoTools\Template;
if (SESSION_SAVE_PATH !== '') session_save_path(SESSION_SAVE_PATH);
2013-02-18 03:48:21 +01:00
Session\open(dirname($_SERVER['PHP_SELF']));
// Called before each action
2013-02-18 03:48:21 +01:00
Router\before(function($action) {
2013-10-15 04:38:07 +02:00
$ignore_actions = array('js', 'login', 'google-auth', 'google-redirect-auth', 'mozilla-auth');
2013-02-18 03:48:21 +01:00
if (! isset($_SESSION['user']) && ! in_array($action, $ignore_actions)) {
2013-04-12 21:57:54 +02:00
Response\redirect('?action=login');
2013-02-18 03:48:21 +01:00
}
// Load translations
$language = Model\get_config_value('language') ?: 'en_US';
if ($language !== 'en_US') PicoTools\Translator\load($language);
2013-04-13 03:08:55 +02:00
// HTTP secure headers
$frame_src = \PicoFeed\Filter::$iframe_whitelist;
$frame_src[] = 'https://login.persona.org';
2013-02-18 03:48:21 +01:00
Response\csp(array(
'media-src' => '*',
'img-src' => '*',
'frame-src' => $frame_src
2013-02-18 03:48:21 +01:00
));
Response\xframe();
Response\xss();
Response\nosniff();
});
2013-10-15 04:38:07 +02:00
// Javascript assets
Router\get_action('js', function() {
$data = file_get_contents('assets/js/app.js');
$data .= file_get_contents('assets/js/feed.js');
$data .= file_get_contents('assets/js/item.js');
$data .= file_get_contents('assets/js/event.js');
$data .= file_get_contents('assets/js/nav.js');
$data .= 'Miniflux.App.Run();';
Response\js($data);
});
// Logout and destroy session
2013-02-18 03:48:21 +01:00
Router\get_action('logout', function() {
Session\close();
Response\redirect('?action=login');
});
// Display form login
2013-02-18 03:48:21 +01:00
Router\get_action('login', function() {
if (isset($_SESSION['user'])) Response\redirect('?action=unread');
2013-02-18 03:48:21 +01:00
Response\html(Template\load('login', array(
'google_auth_enable' => Model\get_config_value('auth_google_token') !== '',
'mozilla_auth_enable' => Model\get_config_value('auth_mozilla_token') !== '',
2013-02-18 03:48:21 +01:00
'errors' => array(),
'values' => array()
)));
});
// Check credentials and redirect to unread items
2013-02-18 03:48:21 +01:00
Router\post_action('login', function() {
$values = Request\values();
list($valid, $errors) = Model\validate_login($values);
if ($valid) Response\redirect('?action=unread');
2013-02-18 03:48:21 +01:00
Response\html(Template\load('login', array(
'google_auth_enable' => Model\get_config_value('auth_google_token') !== '',
'mozilla_auth_enable' => Model\get_config_value('auth_mozilla_token') !== '',
2013-02-18 03:48:21 +01:00
'errors' => $errors,
'values' => $values
)));
});
2013-07-21 17:11:41 +02:00
// Show help
Router\get_action('show-help', function() {
Response\html(Template\load('show_help'));
});
2013-08-04 20:15:32 +02:00
// Show item
2013-03-27 02:57:12 +01:00
Router\get_action('show', function() {
2013-05-26 19:09:34 +02:00
$id = Request\param('id');
2013-08-04 20:15:32 +02:00
$menu = Request\param('menu');
$item = Model\get_item($id);
$feed = Model\get_feed($item['feed_id']);
2013-03-27 02:57:12 +01:00
2013-06-15 05:12:08 +02:00
Model\set_item_read($id);
2013-08-04 20:15:32 +02:00
switch ($menu) {
case 'unread':
$nav = Model\get_nav_item($item);
$nb_unread_items = Model\count_items('unread');
2013-08-04 20:15:32 +02:00
break;
case 'history':
$nav = Model\get_nav_item($item, array('read'));
break;
case 'feed-items':
$nav = Model\get_nav_item($item, array('unread', 'read'), array(1, 0), $item['feed_id']);
2013-08-04 20:15:32 +02:00
break;
case 'bookmarks':
$nav = Model\get_nav_item($item, array('unread', 'read'), array(1));
break;
}
2013-02-18 03:48:21 +01:00
2013-06-15 05:12:08 +02:00
Response\html(Template\layout('show_item', array(
'nb_unread_items' => isset($nb_unread_items) ? $nb_unread_items : null,
'item' => $item,
'feed' => $feed,
2013-08-04 20:15:32 +02:00
'item_nav' => isset($nav) ? $nav : null,
'menu' => $menu,
'title' => $item['title']
)));
});
// 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);
2013-10-11 04:18:12 +02:00
$feed_id = Request\int_param('feed_id', 0);
Model\set_item_read($id);
2013-10-11 04:18:12 +02:00
Response\Redirect('?action='.$redirect.'&offset='.$offset.'&feed_id='.$feed_id.'#item-'.$id);
});
// 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);
2013-10-11 04:18:12 +02:00
$feed_id = Request\int_param('feed_id', 0);
Model\set_item_unread($id);
2013-10-11 04:18:12 +02:00
Response\Redirect('?action='.$redirect.'&offset='.$offset.'&feed_id='.$feed_id.'#item-'.$id);
});
// 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);
2013-10-11 04:18:12 +02:00
$feed_id = Request\int_param('feed_id', 0);
Model\set_item_removed($id);
2013-10-11 04:18:12 +02:00
Response\Redirect('?action='.$redirect.'&offset='.$offset.'&feed_id='.$feed_id);
});
// Ajax call to download an item (fetch the full content from the original website)
Router\post_action('download-item', function() {
Response\json(Model\download_item(Request\param('id')));
});
// Ajax call to mark item read
Router\post_action('mark-item-read', function() {
2013-04-03 04:49:14 +02:00
$id = Request\param('id');
Model\set_item_read($id);
Response\json(array('Ok'));
});
2013-04-03 04:49:14 +02:00
// Ajax call to mark item unread
Router\post_action('mark-item-unread', function() {
$id = Request\param('id');
Model\set_item_unread($id);
2013-04-03 04:49:14 +02:00
Response\json(array('Ok'));
});
// Ajax call change item status
Router\post_action('change-item-status', function() {
$id = Request\param('id');
Response\json(array(
'item_id' => $id,
'status' => Model\switch_item_status($id)
));
});
2013-10-15 04:38:07 +02:00
// Ajax call to add or remove a bookmark
Router\post_action('bookmark', function() {
$id = Request\param('id');
$value = Request\int_param('value');
Model\set_bookmark_value($id, $value);
Response\json(array('id' => $id, 'value' => $value));
});
// Add new bookmark
2013-06-15 05:12:08 +02:00
Router\get_action('bookmark', function() {
$id = Request\param('id');
2013-08-04 20:15:32 +02:00
$menu = Request\param('menu', 'unread');
$source = Request\param('source', 'unread');
$offset = Request\int_param('offset', 0);
2013-10-11 04:18:12 +02:00
$feed_id = Request\int_param('feed_id', 0);
2013-06-15 05:12:08 +02:00
Model\set_bookmark_value($id, Request\int_param('value'));
2013-08-04 20:15:32 +02:00
if ($source === 'show') {
Response\Redirect('?action=show&menu='.$menu.'&id='.$id);
2013-06-15 05:12:08 +02:00
}
2013-10-11 04:18:12 +02:00
Response\Redirect('?action='.$menu.'&offset='.$offset.'&feed_id='.$feed_id.'#item-'.$id);
2013-04-03 04:49:14 +02:00
});
// Display history page
2013-02-18 03:48:21 +01:00
Router\get_action('history', function() {
2013-05-26 19:09:34 +02:00
2013-07-06 04:37:19 +02:00
$offset = Request\int_param('offset', 0);
$nb_items = Model\count_items('read');
2013-05-26 19:09:34 +02:00
Response\html(Template\layout('history', array(
'items' => Model\get_items(
'read',
$offset,
Model\get_config_value('items_per_page'),
'updated',
Model\get_config_value('items_sorting_direction')
),
2013-10-15 04:38:07 +02:00
'order' => '',
'direction' => '',
2013-07-06 04:37:19 +02:00
'nb_items' => $nb_items,
'offset' => $offset,
'items_per_page' => Model\get_config_value('items_per_page'),
'menu' => 'history',
2013-07-06 04:37:19 +02:00
'title' => t('History').' ('.$nb_items.')'
2013-02-18 03:48:21 +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\count_feed_items($feed_id);
$feed = Model\get_feed($feed_id);
2013-09-15 01:05:52 +02:00
$order = Request\param('order', 'updated');
$direction = Request\param('direction', Model\get_config_value('items_sorting_direction'));
2013-09-15 01:05:52 +02:00
$items = Model\get_feed_items($feed_id, $offset, Model\get_config_value('items_per_page'), $order, $direction);
Response\html(Template\layout('feed_items', array(
2013-09-15 01:05:52 +02:00
'order' => $order,
'direction' => $direction,
'feed' => $feed,
2013-09-15 01:05:52 +02:00
'items' => $items,
'nb_items' => $nb_items,
'offset' => $offset,
'items_per_page' => Model\get_config_value('items_per_page'),
2013-09-15 01:05:52 +02:00
'menu' => 'feed-items',
'title' => '('.$nb_items.') '.$feed['title']
)));
2013-02-18 03:48:21 +01:00
});
// Display bookmarks page
2013-06-15 05:12:08 +02:00
Router\get_action('bookmarks', function() {
2013-07-06 04:37:19 +02:00
$offset = Request\int_param('offset', 0);
$nb_items = Model\count_bookmarks();
2013-06-15 05:12:08 +02:00
Response\html(Template\layout('bookmarks', array(
2013-10-15 04:38:07 +02:00
'order' => '',
'direction' => '',
'items' => Model\get_bookmarks($offset, Model\get_config_value('items_per_page')),
2013-07-06 04:37:19 +02:00
'nb_items' => $nb_items,
'offset' => $offset,
'items_per_page' => Model\get_config_value('items_per_page'),
2013-06-15 05:12:08 +02:00
'menu' => 'bookmarks',
2013-07-06 04:37:19 +02:00
'title' => t('Bookmarks').' ('.$nb_items.')'
)));
});
// Mark all unread items as read
Router\get_action('mark-as-read', function() {
Model\mark_as_read();
Response\redirect('?action=unread');
});
2013-09-15 01:05:52 +02:00
// Mark all unread items as read for a specific feed
Router\get_action('mark-feed-as-read', function() {
$feed_id = Request\int_param('feed_id');
Model\mark_feed_as_read($feed_id);
Response\redirect('?action=unread');
});
// Mark sent items id as read (Ajax request)
Router\post_action('mark-items-as-read', function(){
Model\mark_items_as_read(Request\values());
Response\json(array('OK'));
});
// Confirmation box to flush history
Router\get_action('confirm-flush-history', function() {
Response\html(Template\layout('confirm_flush_items', array(
'menu' => 'history',
'title' => t('Confirmation')
)));
});
// Flush history
Router\get_action('flush-history', function() {
Model\mark_as_removed();
Response\redirect('?action=history');
});
// Refresh all feeds, used when Javascript is disabled
Router\get_action('refresh-all', function() {
Model\update_feeds();
Session\flash(t('Your subscriptions are updated'));
Response\redirect('?action=unread');
});
// Disable content grabber for a feed
Router\get_action('disable-grabber-feed', function() {
$id = Request\int_param('feed_id');
if ($id && Model\disable_grabber_feed($id)) {
Session\flash(t('The content grabber is disabled successfully.'));
}
else {
Session\flash_error(t('Unable to disable the content grabber for this subscription.'));
}
Response\redirect('?action=feeds');
});
// Enable content grabber for a feed
Router\get_action('enable-grabber-feed', function() {
$id = Request\int_param('feed_id');
if ($id && Model\enable_grabber_feed($id)) {
Session\flash(t('The content grabber is enabled successfully.'));
}
else {
Session\flash_error(t('Unable to activate the content grabber for this subscription.'));
}
Response\redirect('?action=feeds');
});
// Confirmation box to disable a feed
Router\get_action('confirm-disable-feed', function() {
$id = Request\int_param('feed_id');
Response\html(Template\layout('confirm_disable_feed', array(
'feed' => Model\get_feed($id),
'menu' => 'feeds',
'title' => t('Confirmation')
)));
});
// Disable a feed
Router\get_action('disable-feed', function() {
$id = Request\int_param('feed_id');
if ($id && Model\disable_feed($id)) {
Session\flash(t('This subscription has been disabled successfully.'));
}
else {
Session\flash_error(t('Unable to disable this subscription.'));
}
Response\redirect('?action=feeds');
});
// Enable a feed
Router\get_action('enable-feed', function() {
$id = Request\int_param('feed_id');
if ($id && Model\enable_feed($id)) {
Session\flash(t('This subscription has been enabled successfully.'));
}
else {
Session\flash_error(t('Unable to enable this subscription.'));
}
Response\redirect('?action=feeds');
});
// Confirmation box to remove a feed
Router\get_action('confirm-remove-feed', function() {
2013-03-17 23:16:25 +01:00
$id = Request\int_param('feed_id');
Response\html(Template\layout('confirm_remove_feed', array(
2013-03-17 23:16:25 +01:00
'feed' => Model\get_feed($id),
'menu' => 'feeds',
'title' => t('Confirmation')
2013-03-17 23:16:25 +01:00
)));
});
// Remove a feed
Router\get_action('remove-feed', function() {
2013-02-18 03:48:21 +01:00
$id = Request\int_param('feed_id');
2013-03-17 23:16:25 +01:00
if ($id && Model\remove_feed($id)) {
2013-04-13 03:08:55 +02:00
Session\flash(t('This subscription has been removed successfully.'));
2013-03-17 23:16:25 +01:00
}
else {
2013-04-13 03:08:55 +02:00
Session\flash_error(t('Unable to remove this subscription.'));
2013-02-18 03:48:21 +01:00
}
Response\redirect('?action=feeds');
});
// Refresh one feed and redirect to unread items
2013-02-24 20:04:56 +01:00
Router\get_action('refresh-feed', function() {
2013-02-18 03:48:21 +01:00
$id = Request\int_param('feed_id');
if ($id) Model\update_feed($id);
2013-02-18 03:48:21 +01:00
Response\redirect('?action=unread');
});
// Ajax call to refresh one feed
Router\post_action('refresh-feed', function() {
2013-02-24 20:04:56 +01:00
$id = Request\int_param('feed_id', 0);
2013-02-24 20:04:56 +01:00
if ($id) {
$result = Model\update_feed($id);
2013-02-24 20:04:56 +01:00
}
Response\json(array('feed_id' => $id, 'result' => $result));
2013-02-24 20:04:56 +01:00
});
// Display all feeds
2013-02-18 03:48:21 +01:00
Router\get_action('feeds', function() {
if (! Request\int_param('disable_empty_feeds_check')) {
2013-07-13 02:26:47 +02:00
$empty_feeds = Model\get_empty_feeds();
2013-07-13 02:26:47 +02:00
if (! empty($empty_feeds)) {
2013-07-13 02:26:47 +02:00
$listing = array();
foreach ($empty_feeds as &$feed) {
$listing[] = '"'.$feed['title'].'"';
}
2013-07-13 02:26:47 +02:00
$message = t(
'There is %d empty feeds, there is maybe an error: %s...',
count($empty_feeds),
implode(', ', array_slice($listing, 0, 5))
);
2013-07-17 02:43:10 +02:00
Session\flash_error($message);
}
}
2013-07-13 02:26:47 +02:00
2013-02-18 03:48:21 +01:00
Response\html(Template\layout('feeds', array(
'feeds' => Model\get_feeds(),
2013-03-17 23:16:25 +01:00
'nothing_to_read' => Request\int_param('nothing_to_read'),
'menu' => 'feeds',
'title' => t('Subscriptions')
2013-02-18 03:48:21 +01:00
)));
});
// Display form to add one feed
2013-02-18 03:48:21 +01:00
Router\get_action('add', function() {
Response\html(Template\layout('add', array(
'values' => array(),
'errors' => array(),
'menu' => 'feeds',
'title' => t('New subscription')
2013-02-18 03:48:21 +01:00
)));
});
// Add a feed with the form or directly from the url, it can be used by a bookmarklet by example
Router\action('subscribe', function() {
2013-02-18 03:48:21 +01:00
if (Request\param('url')) {
$values = array();
$url = Request\param('url');
}
else {
$values = Request\values();
$url = isset($values['url']) ? $values['url'] : '';
}
$values += array('download_content' => 0);
$url = trim($url);
$result = Model\import_feed($url, $values['download_content']);
if ($result) {
2013-02-18 03:48:21 +01:00
2013-04-13 03:08:55 +02:00
Session\flash(t('Subscription added successfully.'));
2013-02-18 03:48:21 +01:00
Response\redirect('?action=feeds');
}
else {
2013-04-13 03:08:55 +02:00
Session\flash_error(t('Unable to find a subscription.'));
2013-02-18 03:48:21 +01:00
}
Response\html(Template\layout('add', array(
'values' => array('url' => $url),
'menu' => 'feeds',
'title' => t('Subscriptions')
2013-02-18 03:48:21 +01:00
)));
});
// OPML export
2013-02-18 03:48:21 +01:00
Router\get_action('export', function() {
Response\force_download('feeds.opml');
Response\xml(Model\export_feeds());
});
// OPML import form
2013-02-18 03:48:21 +01:00
Router\get_action('import', function() {
Response\html(Template\layout('import', array(
'errors' => array(),
'menu' => 'feeds',
'title' => t('OPML Import')
2013-02-18 03:48:21 +01:00
)));
});
// OPML importation
2013-02-18 03:48:21 +01:00
Router\post_action('import', function() {
if (Model\import_feeds(Request\file_content('file'))) {
2013-04-13 03:08:55 +02:00
Session\flash(t('Your feeds have been imported.'));
Response\redirect('?action=feeds&disable_empty_feeds_check=1');
2013-02-18 03:48:21 +01:00
}
else {
2013-04-13 03:08:55 +02:00
Session\flash_error(t('Unable to import your OPML file.'));
2013-06-01 20:56:20 +02:00
Response\redirect('?action=import');
2013-02-18 03:48:21 +01:00
}
});
2013-08-30 01:34:11 +02:00
// Re-generate tokens
Router\get_action('generate-tokens', function() {
Model\new_tokens();
Response\redirect('?action=config#api');
});
// Optimize the database manually
Router\get_action('optimize-db', function() {
\PicoTools\singleton('db')->getConnection()->exec('VACUUM');
Response\redirect('?action=config');
});
// Download the compressed database
Router\get_action('download-db', function() {
Response\force_download('db.sqlite.gz');
Response\binary(gzencode(file_get_contents(DB_FILENAME)));
});
// Flush console messages
Router\get_action('flush-console', function() {
@unlink(DEBUG_FILENAME);
Response\redirect('?action=console');
});
// Display console
Router\get_action('console', function() {
Response\html(Template\layout('console', array(
'content' => @file_get_contents(DEBUG_FILENAME),
'title' => t('Console')
)));
});
// Display preferences page
2013-02-18 03:48:21 +01:00
Router\get_action('config', function() {
Response\html(Template\layout('config', array(
'errors' => array(),
'values' => Model\get_config(),
'db_size' => filesize(DB_FILENAME),
2013-04-13 03:08:55 +02:00
'languages' => Model\get_languages(),
2013-05-26 19:09:34 +02:00
'autoflush_options' => Model\get_autoflush_options(),
'paging_options' => Model\get_paging_options(),
2013-07-17 03:58:11 +02:00
'theme_options' => Model\get_themes(),
'sorting_options' => Model\get_sorting_directions(),
'menu' => 'config',
'title' => t('Preferences')
2013-02-18 03:48:21 +01:00
)));
});
// Update preferences
2013-02-18 03:48:21 +01:00
Router\post_action('config', function() {
2013-07-06 04:37:19 +02:00
$values = Request\values() + array('nocontent' => 0);
2013-02-18 03:48:21 +01:00
list($valid, $errors) = Model\validate_config_update($values);
if ($valid) {
if (Model\save_config($values)) {
2013-04-13 03:08:55 +02:00
Session\flash(t('Your preferences are updated.'));
2013-02-18 03:48:21 +01:00
}
else {
2013-04-13 03:08:55 +02:00
Session\flash_error(t('Unable to update your preferences.'));
2013-02-18 03:48:21 +01:00
}
Response\redirect('?action=config');
}
Response\html(Template\layout('config', array(
'errors' => $errors,
'values' => $values,
'db_size' => filesize(DB_FILENAME),
2013-04-13 03:08:55 +02:00
'languages' => Model\get_languages(),
2013-05-26 19:09:34 +02:00
'autoflush_options' => Model\get_autoflush_options(),
'paging_options' => Model\get_paging_options(),
2013-07-17 03:58:11 +02:00
'theme_options' => Model\get_themes(),
'sorting_options' => Model\get_sorting_directions(),
'menu' => 'config',
'title' => t('Preferences')
2013-02-18 03:48:21 +01:00
)));
});
// Link to a Google Account (redirect)
Router\get_action('google-redirect-link', function() {
require 'vendor/PicoTools/AuthProvider.php';
Response\Redirect(AuthProvider\google_get_url(Helper\get_current_base_url(), '?action=google-link'));
});
// Link to a Google Account (association)
Router\get_action('google-link', function() {
require 'vendor/PicoTools/AuthProvider.php';
list($valid, $token) = AuthProvider\google_validate();
if ($valid) {
Model\save_auth_token('google', $token);
Session\flash(t('Your Google Account is linked to Miniflux.'));
}
else {
Session\flash_error(t('Unable to link Miniflux to your Google Account.'));
}
Response\redirect('?action=config');
});
// Authenticate with a Google Account (redirect)
Router\get_action('google-redirect-auth', function() {
require 'vendor/PicoTools/AuthProvider.php';
Response\Redirect(AuthProvider\google_get_url(Helper\get_current_base_url(), '?action=google-auth'));
});
// Authenticate with a Google Account (callback url)
Router\get_action('google-auth', function() {
require 'vendor/PicoTools/AuthProvider.php';
list($valid, $token) = AuthProvider\google_validate();
if ($valid && $token === Model\get_config_value('auth_google_token')) {
$_SESSION['user'] = array(
'username' => Model\get_config_value('username'),
'language' => Model\get_config_value('language'),
);
Response\redirect('?action=unread');
}
else {
Response\html(Template\load('login', array(
'google_auth_enable' => Model\get_config_value('auth_google_token') !== '',
'mozilla_auth_enable' => Model\get_config_value('auth_mozilla_token') !== '',
'errors' => array('login' => t('Unable to authenticate with Google')),
'values' => array()
)));
}
});
// Authenticate with a Mozilla Persona (ajax check)
Router\post_action('mozilla-auth', function() {
require 'vendor/PicoTools/AuthProvider.php';
list($valid, $token) = AuthProvider\mozilla_validate(Request\value('token'));
if ($valid && $token === Model\get_config_value('auth_mozilla_token')) {
$_SESSION['user'] = array(
'username' => Model\get_config_value('username'),
'language' => Model\get_config_value('language'),
);
Response\text('?action=unread');
}
else {
Response\text("?action=login");
}
});
// Link Miniflux to a Mozilla Account (ajax check)
Router\post_action('mozilla-link', function() {
require 'vendor/PicoTools/AuthProvider.php';
list($valid, $token) = AuthProvider\mozilla_validate(Request\value('token'));
if ($valid) {
Model\save_auth_token('mozilla', $token);
Session\flash(t('Your Mozilla Persona Account is linked to Miniflux.'));
}
else {
Session\flash_error(t('Unable to link Miniflux to your Mozilla Persona Account.'));
}
Response\text("?action=config");
});
// Remove account link
Router\get_action('unlink-account-provider', function() {
Model\remove_auth_token(Request\param('type'));
Response\redirect('?action=config');
});
// Display unread items
2013-02-18 03:48:21 +01:00
Router\notfound(function() {
2013-05-26 19:09:34 +02:00
Model\autoflush();
2013-09-15 01:05:52 +02:00
$order = Request\param('order', 'updated');
$direction = Request\param('direction', Model\get_config_value('items_sorting_direction'));
2013-07-06 04:37:19 +02:00
$offset = Request\int_param('offset', 0);
2013-09-15 01:05:52 +02:00
$items = Model\get_items('unread', $offset, Model\get_config_value('items_per_page'), $order, $direction);
$nb_items = Model\count_items('unread');
2013-03-17 23:16:25 +01:00
if ($nb_items === 0) Response\redirect('?action=feeds&nothing_to_read=1');
2013-03-17 23:16:25 +01:00
2013-02-18 03:48:21 +01:00
Response\html(Template\layout('unread_items', array(
2013-09-15 01:05:52 +02:00
'order' => $order,
'direction' => $direction,
2013-03-17 23:16:25 +01:00
'items' => $items,
'nb_items' => $nb_items,
2013-07-06 04:37:19 +02:00
'nb_unread_items' => $nb_items,
'offset' => $offset,
'items_per_page' => Model\get_config_value('items_per_page'),
'title' => 'Miniflux ('.$nb_items.')',
2013-02-18 03:48:21 +01:00
'menu' => 'unread'
)));
});