2013-12-23 03:25:54 +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;
|
2014-02-08 20:13:14 +01:00
|
|
|
use PicoDb\Database;
|
2013-12-23 03:25:54 +01:00
|
|
|
|
2014-04-06 02:24:13 +02:00
|
|
|
// Display a form to add a new database
|
|
|
|
Router\get_action('new-db', function() {
|
|
|
|
|
|
|
|
if (ENABLE_MULTIPLE_DB) {
|
2014-04-16 00:31:59 +02:00
|
|
|
|
2014-04-06 02:24:13 +02:00
|
|
|
Response\html(Template\layout('new_db', array(
|
|
|
|
'errors' => array(),
|
2014-11-08 03:44:20 +01:00
|
|
|
'values' => array(
|
|
|
|
'csrf' => Model\Config\generate_csrf(),
|
|
|
|
),
|
2014-04-06 02:24:13 +02:00
|
|
|
'menu' => 'config',
|
|
|
|
'title' => t('New database')
|
|
|
|
)));
|
|
|
|
}
|
|
|
|
|
2014-11-19 01:16:14 +01:00
|
|
|
Response\redirect('?action=database');
|
2014-04-06 02:24:13 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// Create a new database
|
|
|
|
Router\post_action('new-db', function() {
|
|
|
|
|
2014-04-16 00:31:59 +02:00
|
|
|
if (ENABLE_MULTIPLE_DB) {
|
2014-04-06 02:24:13 +02:00
|
|
|
|
2014-04-16 00:31:59 +02:00
|
|
|
$values = Request\values();
|
2014-11-08 03:44:20 +01:00
|
|
|
Model\Config\check_csrf_values($values);
|
2014-04-16 00:31:59 +02:00
|
|
|
list($valid, $errors) = Model\Database\validate($values);
|
2014-04-06 02:24:13 +02:00
|
|
|
|
2014-04-16 00:31:59 +02:00
|
|
|
if ($valid) {
|
|
|
|
|
|
|
|
if (Model\Database\create(strtolower($values['name']).'.sqlite', $values['username'], $values['password'])) {
|
|
|
|
Session\flash(t('Database created successfully.'));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Session\flash_error(t('Unable to create the new database.'));
|
|
|
|
}
|
|
|
|
|
2014-11-19 01:16:14 +01:00
|
|
|
Response\redirect('?action=database');
|
2014-04-06 02:24:13 +02:00
|
|
|
}
|
|
|
|
|
2014-04-16 00:31:59 +02:00
|
|
|
Response\html(Template\layout('new_db', array(
|
|
|
|
'errors' => $errors,
|
2014-11-08 03:44:20 +01:00
|
|
|
'values' => $values + array('csrf' => Model\Config\generate_csrf()),
|
2014-04-16 00:31:59 +02:00
|
|
|
'menu' => 'config',
|
|
|
|
'title' => t('New database')
|
|
|
|
)));
|
2014-04-06 02:24:13 +02:00
|
|
|
}
|
|
|
|
|
2014-11-19 01:16:14 +01:00
|
|
|
Response\redirect('?action=database');
|
2014-04-06 02:24:13 +02:00
|
|
|
});
|
|
|
|
|
2014-11-08 16:07:24 +01:00
|
|
|
// Comfirmation box before auto-update
|
|
|
|
Router\get_action('confirm-auto-update', function() {
|
|
|
|
|
|
|
|
Response\html(Template\layout('confirm_auto_update', array(
|
|
|
|
'menu' => 'config',
|
|
|
|
'title' => t('Confirmation')
|
|
|
|
)));
|
|
|
|
});
|
|
|
|
|
2014-03-30 21:59:26 +02:00
|
|
|
// Auto-update
|
|
|
|
Router\get_action('auto-update', function() {
|
|
|
|
|
|
|
|
if (ENABLE_AUTO_UPDATE) {
|
|
|
|
|
|
|
|
if (Model\AutoUpdate\execute(Model\Config\get('auto_update_url'))) {
|
|
|
|
Session\flash(t('Miniflux is updated!'));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Session\flash_error(t('Unable to update Miniflux, check the console for errors.'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Response\redirect('?action=config');
|
|
|
|
});
|
|
|
|
|
2013-12-23 03:25:54 +01:00
|
|
|
// Re-generate tokens
|
|
|
|
Router\get_action('generate-tokens', function() {
|
|
|
|
|
2014-11-08 03:44:20 +01:00
|
|
|
if (Model\Config\check_csrf(Request\param('csrf'))) {
|
|
|
|
Model\Config\new_tokens();
|
|
|
|
}
|
|
|
|
|
2014-11-08 02:37:12 +01:00
|
|
|
Response\redirect('?action=api');
|
2013-12-23 03:25:54 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// Optimize the database manually
|
|
|
|
Router\get_action('optimize-db', function() {
|
|
|
|
|
2014-11-08 03:44:20 +01:00
|
|
|
if (Model\Config\check_csrf(Request\param('csrf'))) {
|
|
|
|
Database::get('db')->getConnection()->exec('VACUUM');
|
|
|
|
}
|
|
|
|
|
2014-11-19 01:16:14 +01:00
|
|
|
Response\redirect('?action=database');
|
2013-12-23 03:25:54 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// Download the compressed database
|
|
|
|
Router\get_action('download-db', function() {
|
|
|
|
|
2014-11-08 03:44:20 +01:00
|
|
|
if (Model\Config\check_csrf(Request\param('csrf'))) {
|
|
|
|
Response\force_download('db.sqlite.gz');
|
|
|
|
Response\binary(gzencode(file_get_contents(Model\Database\get_path())));
|
|
|
|
}
|
2013-12-23 03:25:54 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// Display preferences page
|
|
|
|
Router\get_action('config', function() {
|
|
|
|
|
|
|
|
Response\html(Template\layout('config', array(
|
|
|
|
'errors' => array(),
|
2014-11-08 03:44:20 +01:00
|
|
|
'values' => Model\Config\get_all() + array('csrf' => Model\Config\generate_csrf()),
|
2013-12-23 03:25:54 +01:00
|
|
|
'languages' => Model\Config\get_languages(),
|
2014-02-26 01:03:46 +01:00
|
|
|
'timezones' => Model\Config\get_timezones(),
|
2014-12-16 02:38:35 +01:00
|
|
|
'autoflush_read_options' => Model\Config\get_autoflush_read_options(),
|
|
|
|
'autoflush_unread_options' => Model\Config\get_autoflush_unread_options(),
|
2013-12-23 03:25:54 +01:00
|
|
|
'paging_options' => Model\Config\get_paging_options(),
|
|
|
|
'theme_options' => Model\Config\get_themes(),
|
|
|
|
'sorting_options' => Model\Config\get_sorting_directions(),
|
2014-05-29 16:57:23 +02:00
|
|
|
'display_mode' => Model\Config\get_display_mode(),
|
2013-12-23 19:33:16 +01:00
|
|
|
'redirect_nothing_to_read_options' => Model\Config\get_nothing_to_read_redirections(),
|
2013-12-23 03:25:54 +01:00
|
|
|
'menu' => 'config',
|
|
|
|
'title' => t('Preferences')
|
|
|
|
)));
|
|
|
|
});
|
|
|
|
|
|
|
|
// Update preferences
|
|
|
|
Router\post_action('config', function() {
|
|
|
|
|
2014-12-24 21:58:24 +01:00
|
|
|
$values = Request\values() + array('nocontent' => 0, 'image_proxy' => 0);
|
2014-11-08 03:44:20 +01:00
|
|
|
Model\Config\check_csrf_values($values);
|
2013-12-23 03:25:54 +01:00
|
|
|
list($valid, $errors) = Model\Config\validate_modification($values);
|
|
|
|
|
|
|
|
if ($valid) {
|
|
|
|
|
|
|
|
if (Model\Config\save($values)) {
|
|
|
|
Session\flash(t('Your preferences are updated.'));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Session\flash_error(t('Unable to update your preferences.'));
|
|
|
|
}
|
|
|
|
|
|
|
|
Response\redirect('?action=config');
|
|
|
|
}
|
|
|
|
|
|
|
|
Response\html(Template\layout('config', array(
|
|
|
|
'errors' => $errors,
|
2014-11-08 03:44:20 +01:00
|
|
|
'values' => Model\Config\get_all() + array('csrf' => Model\Config\generate_csrf()),
|
2013-12-23 03:25:54 +01:00
|
|
|
'languages' => Model\Config\get_languages(),
|
2014-02-26 01:03:46 +01:00
|
|
|
'timezones' => Model\Config\get_timezones(),
|
2013-12-23 03:25:54 +01:00
|
|
|
'autoflush_options' => Model\Config\get_autoflush_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(),
|
2014-05-29 16:57:23 +02:00
|
|
|
'display_mode' => Model\Config\get_display_mode(),
|
2013-12-23 03:25:54 +01:00
|
|
|
'menu' => 'config',
|
|
|
|
'title' => t('Preferences')
|
|
|
|
)));
|
|
|
|
});
|
2014-11-08 02:37:12 +01:00
|
|
|
|
|
|
|
// Display help page
|
|
|
|
Router\get_action('help', function() {
|
|
|
|
|
|
|
|
Response\html(Template\layout('help', array(
|
|
|
|
'config' => Model\Config\get_all(),
|
|
|
|
'menu' => 'config',
|
|
|
|
'title' => t('Help')
|
|
|
|
)));
|
|
|
|
});
|
|
|
|
|
|
|
|
// Display about page
|
|
|
|
Router\get_action('about', function() {
|
|
|
|
|
|
|
|
Response\html(Template\layout('about', array(
|
2014-11-08 03:44:20 +01:00
|
|
|
'csrf' => Model\Config\generate_csrf(),
|
2014-11-08 02:37:12 +01:00
|
|
|
'config' => Model\Config\get_all(),
|
|
|
|
'menu' => 'config',
|
|
|
|
'title' => t('About')
|
|
|
|
)));
|
|
|
|
});
|
|
|
|
|
2014-11-19 01:16:14 +01:00
|
|
|
// Display database page
|
|
|
|
Router\get_action('database', function() {
|
|
|
|
|
|
|
|
Response\html(Template\layout('database', array(
|
|
|
|
'csrf' => Model\Config\generate_csrf(),
|
|
|
|
'config' => Model\Config\get_all(),
|
|
|
|
'db_size' => filesize(\Model\Database\get_path()),
|
|
|
|
'menu' => 'config',
|
|
|
|
'title' => t('Database')
|
|
|
|
)));
|
|
|
|
});
|
|
|
|
|
2014-11-08 02:37:12 +01:00
|
|
|
// Display API page
|
|
|
|
Router\get_action('api', function() {
|
|
|
|
|
|
|
|
Response\html(Template\layout('api', array(
|
2014-11-08 03:44:20 +01:00
|
|
|
'csrf' => Model\Config\generate_csrf(),
|
2014-11-08 02:37:12 +01:00
|
|
|
'config' => Model\Config\get_all(),
|
|
|
|
'menu' => 'config',
|
|
|
|
'title' => t('API')
|
|
|
|
)));
|
|
|
|
});
|
2014-12-24 16:47:24 +01:00
|
|
|
|
|
|
|
// Display bookmark services page
|
|
|
|
Router\get_action('services', function() {
|
|
|
|
|
|
|
|
Response\html(Template\layout('services', array(
|
|
|
|
'errors' => array(),
|
|
|
|
'values' => Model\Config\get_all() + array('csrf' => Model\Config\generate_csrf()),
|
|
|
|
'menu' => 'config',
|
|
|
|
'title' => t('External services')
|
|
|
|
)));
|
|
|
|
});
|
|
|
|
|
|
|
|
// Update bookmark services
|
|
|
|
Router\post_action('services', function() {
|
|
|
|
|
2014-12-24 19:50:20 +01:00
|
|
|
$values = Request\values() + array('pinboard_enabled' => 0, 'instapaper_enabled' => 0);
|
2014-12-24 16:47:24 +01:00
|
|
|
Model\Config\check_csrf_values($values);
|
|
|
|
|
|
|
|
if (Model\Config\save($values)) {
|
|
|
|
Session\flash(t('Your preferences are updated.'));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Session\flash_error(t('Unable to update your preferences.'));
|
|
|
|
}
|
|
|
|
|
|
|
|
Response\redirect('?action=services');
|
|
|
|
});
|