miniflux-legacy/controllers/config.php

238 lines
8.0 KiB
PHP
Raw Normal View History

<?php
2014-02-08 20:13:14 +01:00
use PicoDb\Database;
// Display a form to add a new database
2016-04-18 01:44:45 +02:00
Router\get_action('new-db', function () {
if (ENABLE_MULTIPLE_DB) {
Response\html(Template\layout('new_db', array(
'errors' => array(),
2014-11-08 03:44:20 +01:00
'values' => array(
'csrf' => Helper\generate_csrf(),
2014-11-08 03:44:20 +01:00
),
'nb_unread_items' => Model\Item\count_by_status('unread'),
'menu' => 'config',
'title' => t('New database')
)));
}
2014-11-19 01:16:14 +01:00
Response\redirect('?action=database');
});
// Create a new database
2016-04-18 01:44:45 +02:00
Router\post_action('new-db', function () {
if (ENABLE_MULTIPLE_DB) {
$values = Request\values();
Helper\check_csrf_values($values);
list($valid, $errors) = Model\Database\validate($values);
if ($valid) {
if (Model\Database\create(strtolower($values['name']).'.sqlite', $values['username'], $values['password'])) {
Session\flash(t('Database created successfully.'));
2016-04-18 01:44:45 +02:00
} else {
Session\flash_error(t('Unable to create the new database.'));
}
2014-11-19 01:16:14 +01:00
Response\redirect('?action=database');
}
Response\html(Template\layout('new_db', array(
'errors' => $errors,
'values' => $values + array('csrf' => Helper\generate_csrf()),
'nb_unread_items' => Model\Item\count_by_status('unread'),
'menu' => 'config',
'title' => t('New database')
)));
}
2014-11-19 01:16:14 +01:00
Response\redirect('?action=database');
});
// Confirmation box before auto-update
2016-04-18 01:44:45 +02:00
Router\get_action('confirm-auto-update', function () {
2014-11-08 16:07:24 +01:00
Response\html(Template\layout('confirm_auto_update', array(
'nb_unread_items' => Model\Item\count_by_status('unread'),
2014-11-08 16:07:24 +01:00
'menu' => 'config',
'title' => t('Confirmation')
)));
});
2014-03-30 21:59:26 +02:00
// Auto-update
2016-04-18 01:44:45 +02:00
Router\get_action('auto-update', function () {
2014-03-30 21:59:26 +02:00
if (ENABLE_AUTO_UPDATE) {
if (Model\AutoUpdate\execute(Model\Config\get('auto_update_url'))) {
Session\flash(t('Miniflux is updated!'));
} else {
2014-03-30 21:59:26 +02:00
Session\flash_error(t('Unable to update Miniflux, check the console for errors.'));
}
}
Response\redirect('?action=config');
});
// Re-generate tokens
2016-04-18 01:44:45 +02:00
Router\get_action('generate-tokens', function () {
if (Helper\check_csrf(Request\param('csrf'))) {
2014-11-08 03:44:20 +01:00
Model\Config\new_tokens();
}
Response\redirect('?action=config');
});
// Optimize the database manually
2016-04-18 01:44:45 +02:00
Router\get_action('optimize-db', function () {
if (Helper\check_csrf(Request\param('csrf'))) {
2015-08-15 03:33:39 +02:00
Database::getInstance('db')->getConnection()->exec('VACUUM');
2014-11-08 03:44:20 +01:00
}
2014-11-19 01:16:14 +01:00
Response\redirect('?action=database');
});
// Download the compressed database
2016-04-18 01:44:45 +02:00
Router\get_action('download-db', function () {
if (Helper\check_csrf(Request\param('csrf'))) {
2014-11-08 03:44:20 +01:00
Response\force_download('db.sqlite.gz');
Response\binary(gzencode(file_get_contents(Model\Database\get_path())));
}
});
// Display preferences page
2016-04-18 01:44:45 +02:00
Router\get_action('config', function () {
Response\html(Template\layout('config', array(
'errors' => array(),
'values' => Model\Config\get_all() + array('csrf' => Helper\generate_csrf()),
'languages' => Model\Config\get_languages(),
2014-02-26 01:03:46 +01:00
'timezones' => Model\Config\get_timezones(),
'autoflush_read_options' => Model\Config\get_autoflush_read_options(),
'autoflush_unread_options' => Model\Config\get_autoflush_unread_options(),
'paging_options' => Model\Config\get_paging_options(),
'theme_options' => Model\Config\get_themes(),
'sorting_options' => Model\Config\get_sorting_directions(),
'display_mode' => Model\Config\get_display_mode(),
2016-02-27 20:21:18 +01:00
'item_title_link' => Model\Config\get_item_title_link(),
'redirect_nothing_to_read_options' => Model\Config\get_nothing_to_read_redirections(),
'nb_unread_items' => Model\Item\count_by_status('unread'),
'menu' => 'config',
'title' => t('Preferences')
)));
});
// Update preferences
2016-04-18 01:44:45 +02:00
Router\post_action('config', function () {
$values = Request\values() + array('nocontent' => 0, 'image_proxy' => 0, 'favicons' => 0, 'debug_mode' => 0, 'original_marks_read' => 0);
Helper\check_csrf_values($values);
list($valid, $errors) = Model\Config\validate_modification($values);
if ($valid) {
if (Model\Config\save($values)) {
Session\flash(t('Your preferences are updated.'));
2016-04-18 01:44:45 +02:00
} else {
Session\flash_error(t('Unable to update your preferences.'));
}
Response\redirect('?action=config');
}
Response\html(Template\layout('config', array(
'errors' => $errors,
'values' => Model\Config\get_all() + array('csrf' => Helper\generate_csrf()),
'languages' => Model\Config\get_languages(),
2014-02-26 01:03:46 +01:00
'timezones' => Model\Config\get_timezones(),
2015-01-03 22:58:19 +01:00
'autoflush_read_options' => Model\Config\get_autoflush_read_options(),
'autoflush_unread_options' => Model\Config\get_autoflush_unread_options(),
'paging_options' => Model\Config\get_paging_options(),
'theme_options' => Model\Config\get_themes(),
'sorting_options' => Model\Config\get_sorting_directions(),
2014-02-08 20:13:14 +01:00
'redirect_nothing_to_read_options' => Model\Config\get_nothing_to_read_redirections(),
'display_mode' => Model\Config\get_display_mode(),
2016-02-27 20:21:18 +01:00
'item_title_link' => Model\Config\get_item_title_link(),
'nb_unread_items' => Model\Item\count_by_status('unread'),
'menu' => 'config',
'title' => t('Preferences')
)));
});
// Get configuration parameters (AJAX request)
2016-04-18 01:44:45 +02:00
Router\post_action('get-config', function () {
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
$return = array();
$options = Request\values();
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
if (empty($options)) {
$return = Model\Config\get_all();
2016-04-18 01:44:45 +02:00
} else {
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
foreach ($options as $name) {
$return[$name] = Model\Config\get($name);
}
}
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($return);
});
// Display help page
2016-04-18 01:44:45 +02:00
Router\get_action('help', function () {
Response\html(Template\layout('help', array(
'config' => Model\Config\get_all(),
'nb_unread_items' => Model\Item\count_by_status('unread'),
'menu' => 'config',
'title' => t('Preferences')
)));
});
// Display about page
2016-04-18 01:44:45 +02:00
Router\get_action('about', function () {
Response\html(Template\layout('about', array(
'csrf' => Helper\generate_csrf(),
'config' => Model\Config\get_all(),
'db_name' => Model\Database\select(),
'nb_unread_items' => Model\Item\count_by_status('unread'),
'menu' => 'config',
'title' => t('Preferences')
)));
});
2014-11-19 01:16:14 +01:00
// Display database page
2016-04-18 01:44:45 +02:00
Router\get_action('database', function () {
2014-11-19 01:16:14 +01:00
Response\html(Template\layout('database', array(
'csrf' => Helper\generate_csrf(),
2014-11-19 01:16:14 +01:00
'config' => Model\Config\get_all(),
'db_size' => filesize(\Model\Database\get_path()),
'nb_unread_items' => Model\Item\count_by_status('unread'),
2014-11-19 01:16:14 +01:00
'menu' => 'config',
'title' => t('Preferences')
2014-11-19 01:16:14 +01:00
)));
});
// Display API page
2016-04-18 01:44:45 +02:00
Router\get_action('api', function () {
Response\html(Template\layout('api', array(
'config' => Model\Config\get_all(),
'nb_unread_items' => Model\Item\count_by_status('unread'),
'menu' => 'config',
'title' => t('Preferences')
)));
});
2014-12-24 16:47:24 +01:00
// Display bookmark services page
2016-04-18 01:44:45 +02:00
Router\get_action('services', function () {
2014-12-24 16:47:24 +01:00
Response\html(Template\layout('services', array(
'errors' => array(),
'values' => Model\Config\get_all() + array('csrf' => Helper\generate_csrf()),
2014-12-24 16:47:24 +01:00
'menu' => 'config',
'title' => t('Preferences')
2014-12-24 16:47:24 +01:00
)));
});
// Update bookmark services
2016-04-18 01:44:45 +02:00
Router\post_action('services', function () {
2014-12-24 19:50:20 +01:00
$values = Request\values() + array('pinboard_enabled' => 0, 'instapaper_enabled' => 0);
Helper\check_csrf_values($values);
2014-12-24 16:47:24 +01:00
if (Model\Config\save($values)) {
Session\flash(t('Your preferences are updated.'));
2016-04-18 01:44:45 +02:00
} else {
2014-12-24 16:47:24 +01:00
Session\flash_error(t('Unable to update your preferences.'));
}
Response\redirect('?action=services');
});