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;
|
|
|
|
|
|
|
|
|
|
|
|
Session\open(dirname($_SERVER['PHP_SELF']));
|
|
|
|
|
|
|
|
|
2013-07-06 16:50:37 +02:00
|
|
|
// Called before each action
|
2013-02-18 03:48:21 +01:00
|
|
|
Router\before(function($action) {
|
|
|
|
|
|
|
|
if ($action !== 'login' && ! isset($_SESSION['user'])) {
|
|
|
|
|
2013-04-12 21:57:54 +02:00
|
|
|
Response\redirect('?action=login');
|
2013-02-18 03:48:21 +01:00
|
|
|
}
|
|
|
|
|
2013-07-06 17:47:20 +02: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
|
|
|
|
2013-07-06 17:47:20 +02:00
|
|
|
// HTTP secure headers
|
2013-02-18 03:48:21 +01:00
|
|
|
Response\csp(array(
|
2013-04-05 05:33:29 +02:00
|
|
|
'img-src' => '*',
|
2013-07-06 17:47:20 +02:00
|
|
|
'frame-src' => implode(' ', array(
|
|
|
|
'http://www.youtube.com',
|
|
|
|
'https://www.youtube.com',
|
|
|
|
'http://player.vimeo.com',
|
|
|
|
'https://player.vimeo.com',
|
2013-07-19 01:24:04 +02:00
|
|
|
'http://www.dailymotion.com',
|
|
|
|
'https://www.dailymotion.com',
|
2013-07-06 17:47:20 +02:00
|
|
|
))
|
2013-02-18 03:48:21 +01:00
|
|
|
));
|
|
|
|
|
|
|
|
Response\xframe();
|
|
|
|
Response\xss();
|
|
|
|
Response\nosniff();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2013-07-06 16:50:37 +02:00
|
|
|
// Logout and destroy session
|
2013-02-18 03:48:21 +01:00
|
|
|
Router\get_action('logout', function() {
|
|
|
|
|
|
|
|
Session\close();
|
|
|
|
Response\redirect('?action=login');
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2013-07-06 16:50:37 +02:00
|
|
|
// Display form login
|
2013-02-18 03:48:21 +01:00
|
|
|
Router\get_action('login', function() {
|
|
|
|
|
2013-07-06 16:50:37 +02:00
|
|
|
if (isset($_SESSION['user'])) Response\redirect('index.php');
|
2013-02-18 03:48:21 +01:00
|
|
|
|
|
|
|
Response\html(Template\load('login', array(
|
|
|
|
'errors' => array(),
|
|
|
|
'values' => array()
|
|
|
|
)));
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2013-07-06 16:50:37 +02:00
|
|
|
// 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);
|
|
|
|
|
2013-07-06 16:50:37 +02:00
|
|
|
if ($valid) Response\redirect('?action=unread');
|
2013-02-18 03:48:21 +01:00
|
|
|
|
|
|
|
Response\html(Template\load('login', array(
|
|
|
|
'errors' => $errors,
|
|
|
|
'values' => $values
|
|
|
|
)));
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2013-07-06 16:50:37 +02:00
|
|
|
// Show item without bottom nav
|
2013-03-27 02:57:12 +01:00
|
|
|
Router\get_action('show', function() {
|
2013-05-26 19:09:34 +02:00
|
|
|
|
2013-06-01 04:01:01 +02:00
|
|
|
$id = Model\decode_item_id(Request\param('id'));
|
2013-03-27 02:57:12 +01:00
|
|
|
|
2013-06-15 05:12:08 +02:00
|
|
|
Model\set_item_read($id);
|
2013-06-04 13:38:54 +02:00
|
|
|
|
2013-06-15 05:12:08 +02:00
|
|
|
Response\html(Template\layout('show_item', array(
|
|
|
|
'item' => Model\get_item($id),
|
|
|
|
'menu' => 'show'
|
2013-06-04 13:38:54 +02:00
|
|
|
)));
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2013-07-06 16:50:37 +02:00
|
|
|
// Show item with bottom nav
|
2013-02-18 03:48:21 +01:00
|
|
|
Router\get_action('read', function() {
|
|
|
|
|
2013-06-01 04:01:01 +02:00
|
|
|
$id = Model\decode_item_id(Request\param('id'));
|
2013-03-27 02:57:12 +01:00
|
|
|
$item = Model\get_item($id);
|
2013-05-01 04:34:02 +02:00
|
|
|
$nav = Model\get_nav_item($item); // must be placed before set_item_read()
|
2013-02-18 03:48:21 +01:00
|
|
|
|
|
|
|
Model\set_item_read($id);
|
|
|
|
|
2013-06-15 05:12:08 +02:00
|
|
|
Response\html(Template\layout('show_item', array(
|
2013-06-04 13:38:54 +02:00
|
|
|
'item' => $item,
|
2013-06-15 05:12:08 +02:00
|
|
|
'item_nav' => $nav,
|
|
|
|
'menu' => 'read'
|
2013-06-04 13:38:54 +02:00
|
|
|
)));
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2013-07-06 16:50:37 +02:00
|
|
|
// Mark item as read and redirect to the listing page
|
2013-04-04 03:21:24 +02:00
|
|
|
Router\get_action('mark-item-read', function() {
|
2013-03-21 03:32:10 +01:00
|
|
|
|
2013-06-01 04:01:01 +02:00
|
|
|
$id = Model\decode_item_id(Request\param('id'));
|
2013-07-06 16:50:37 +02:00
|
|
|
$redirect = Request\param('redirect', 'unread');
|
|
|
|
$offset = Request\int_param('offset', 0);
|
|
|
|
|
2013-03-21 03:32:10 +01:00
|
|
|
Model\set_item_read($id);
|
2013-07-06 16:50:37 +02:00
|
|
|
|
|
|
|
Response\Redirect('?action='.$redirect.'&offset='.$offset);
|
2013-04-04 03:21:24 +02:00
|
|
|
});
|
2013-03-21 03:32:10 +01:00
|
|
|
|
2013-04-04 03:21:24 +02:00
|
|
|
|
2013-07-06 16:50:37 +02:00
|
|
|
// Mark item as unread and redirect to the listing page
|
2013-04-04 03:21:24 +02:00
|
|
|
Router\get_action('mark-item-unread', function() {
|
|
|
|
|
2013-06-01 04:01:01 +02:00
|
|
|
$id = Model\decode_item_id(Request\param('id'));
|
2013-07-06 16:50:37 +02:00
|
|
|
$redirect = Request\param('redirect', 'history');
|
|
|
|
$offset = Request\int_param('offset', 0);
|
|
|
|
|
2013-04-04 03:21:24 +02:00
|
|
|
Model\set_item_unread($id);
|
2013-07-06 16:50:37 +02:00
|
|
|
|
|
|
|
Response\Redirect('?action='.$redirect.'&offset='.$offset);
|
2013-03-21 03:32:10 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2013-07-06 16:50:37 +02:00
|
|
|
// Mark item as removed and redirect to the listing page
|
2013-04-23 04:44:28 +02:00
|
|
|
Router\get_action('mark-item-removed', function() {
|
|
|
|
|
2013-06-01 04:01:01 +02:00
|
|
|
$id = Model\decode_item_id(Request\param('id'));
|
2013-07-06 16:50:37 +02:00
|
|
|
$redirect = Request\param('redirect', 'history');
|
|
|
|
$offset = Request\int_param('offset', 0);
|
|
|
|
|
2013-04-23 04:44:28 +02:00
|
|
|
Model\set_item_removed($id);
|
2013-07-06 16:50:37 +02:00
|
|
|
|
|
|
|
Response\Redirect('?action='.$redirect.'&offset='.$offset);
|
2013-04-23 04:44:28 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2013-07-06 16:50:37 +02:00
|
|
|
// Ajax call to mark item read
|
2013-04-04 03:21:24 +02:00
|
|
|
Router\post_action('mark-item-read', function() {
|
2013-04-03 04:49:14 +02:00
|
|
|
|
2013-06-01 04:01:01 +02:00
|
|
|
$id = Model\decode_item_id(Request\param('id'));
|
2013-04-04 03:21:24 +02:00
|
|
|
Model\set_item_read($id);
|
|
|
|
Response\json(array('Ok'));
|
|
|
|
});
|
2013-04-03 04:49:14 +02:00
|
|
|
|
|
|
|
|
2013-07-06 16:50:37 +02:00
|
|
|
// Ajax call to mark item unread
|
2013-04-04 03:21:24 +02:00
|
|
|
Router\post_action('mark-item-unread', function() {
|
|
|
|
|
2013-06-01 04:01:01 +02:00
|
|
|
$id = Model\decode_item_id(Request\param('id'));
|
2013-04-04 03:21:24 +02:00
|
|
|
Model\set_item_unread($id);
|
2013-04-03 04:49:14 +02:00
|
|
|
Response\json(array('Ok'));
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2013-07-06 16:50:37 +02:00
|
|
|
// Ajax call to bookmark an item
|
2013-06-15 05:12:08 +02:00
|
|
|
Router\post_action('bookmark-item', function() {
|
2013-06-04 13:38:54 +02:00
|
|
|
|
|
|
|
$id = Model\decode_item_id(Request\param('id'));
|
2013-06-15 05:12:08 +02:00
|
|
|
Model\bookmark_item($id);
|
|
|
|
Response\json(array('Ok'));
|
2013-06-04 13:38:54 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2013-07-06 16:50:37 +02:00
|
|
|
// Ajax call change item status
|
|
|
|
Router\post_action('change-item-status', function() {
|
|
|
|
|
|
|
|
$id = Model\decode_item_id(Request\param('id'));
|
|
|
|
|
|
|
|
Response\json(array(
|
|
|
|
'item_id' => Model\encode_item_id($id),
|
|
|
|
'status' => Model\switch_item_status($id)
|
|
|
|
));
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Add new bookmark
|
2013-06-15 05:12:08 +02:00
|
|
|
Router\get_action('bookmark', function() {
|
2013-06-04 13:38:54 +02:00
|
|
|
|
2013-06-15 05:12:08 +02:00
|
|
|
$param_id = Request\param('id');
|
|
|
|
$id = Model\decode_item_id($param_id);
|
|
|
|
$redirect = Request\param('redirect', 'unread');
|
2013-07-06 16:50:37 +02:00
|
|
|
$offset = Request\int_param('offset', 0);
|
2013-06-15 05:12:08 +02:00
|
|
|
|
|
|
|
Model\set_bookmark_value($id, Request\int_param('value'));
|
|
|
|
|
|
|
|
if ($redirect === 'show') {
|
|
|
|
|
|
|
|
Response\Redirect('?action=show&id='.$param_id);
|
|
|
|
}
|
|
|
|
else if ($redirect === 'read') {
|
|
|
|
|
|
|
|
Response\Redirect('?action=read&id='.$param_id);
|
|
|
|
}
|
|
|
|
|
2013-07-06 16:50:37 +02:00
|
|
|
Response\Redirect('?action='.$redirect.'&offset='.$offset);
|
2013-04-03 04:49:14 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2013-07-06 16:50:37 +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(
|
2013-07-06 16:50:37 +02:00
|
|
|
'items' => Model\get_read_items($offset, Model\get_config_value('items_per_page')),
|
2013-07-06 04:37:19 +02:00
|
|
|
'nb_items' => $nb_items,
|
|
|
|
'offset' => $offset,
|
2013-07-06 16:50:37 +02:00
|
|
|
'items_per_page' => Model\get_config_value('items_per_page'),
|
2013-06-14 03:29:34 +02:00
|
|
|
'menu' => 'history',
|
2013-07-06 04:37:19 +02:00
|
|
|
'title' => t('History').' ('.$nb_items.')'
|
2013-02-18 03:48:21 +01:00
|
|
|
)));
|
2013-07-13 04:16:40 +02: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);
|
|
|
|
|
|
|
|
Response\html(Template\layout('feed_items', array(
|
|
|
|
'feed' => $feed,
|
|
|
|
'items' => Model\get_feed_items($feed_id, $offset, Model\get_config_value('items_per_page')),
|
|
|
|
'nb_items' => $nb_items,
|
|
|
|
'offset' => $offset,
|
|
|
|
'items_per_page' => Model\get_config_value('items_per_page'),
|
|
|
|
'menu' => 'feeds',
|
|
|
|
'title' => '('.$nb_items.') '.$feed['title']
|
|
|
|
)));
|
2013-02-18 03:48:21 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2013-07-06 16:50:37 +02: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-07-06 16:50:37 +02:00
|
|
|
'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,
|
2013-07-06 16:50:37 +02:00
|
|
|
'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.')'
|
2013-06-04 13:38:54 +02:00
|
|
|
)));
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2013-07-06 16:50:37 +02:00
|
|
|
// 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');
|
|
|
|
|
2013-06-01 04:01:01 +02:00
|
|
|
Response\html(Template\layout('confirm_remove_feed', array(
|
2013-03-17 23:16:25 +01:00
|
|
|
'feed' => Model\get_feed($id),
|
2013-06-14 03:29:34 +02:00
|
|
|
'menu' => 'feeds',
|
|
|
|
'title' => t('Confirmation')
|
2013-03-17 23:16:25 +01:00
|
|
|
)));
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2013-07-06 16:50:37 +02: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-02-18 03:48:21 +01:00
|
|
|
|
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');
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2013-07-06 16:50:37 +02:00
|
|
|
// 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');
|
2013-07-06 16:50:37 +02:00
|
|
|
if ($id) Model\update_feed($id);
|
2013-07-06 20:29:45 +02:00
|
|
|
Model\write_debug();
|
2013-02-18 03:48:21 +01:00
|
|
|
Response\redirect('?action=unread');
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2013-07-06 16:50:37 +02:00
|
|
|
// Ajax call to refresh one feed
|
2013-04-04 03:21:24 +02:00
|
|
|
Router\post_action('refresh-feed', function() {
|
2013-02-24 20:04:56 +01:00
|
|
|
|
2013-07-06 20:29:45 +02:00
|
|
|
$id = Request\int_param('feed_id', 0);
|
2013-02-24 20:04:56 +01:00
|
|
|
|
|
|
|
if ($id) {
|
2013-07-06 20:29:45 +02:00
|
|
|
|
|
|
|
$result = Model\update_feed($id);
|
|
|
|
Model\write_debug();
|
2013-02-24 20:04:56 +01:00
|
|
|
}
|
|
|
|
|
2013-07-06 20:29:45 +02:00
|
|
|
Response\json(array('feed_id' => $id, 'result' => $result));
|
2013-02-24 20:04:56 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2013-07-06 16:50:37 +02:00
|
|
|
// Mark all unread items as read
|
2013-04-03 04:49:14 +02:00
|
|
|
Router\get_action('mark-as-read', function() {
|
2013-02-18 03:48:21 +01:00
|
|
|
|
2013-04-03 04:49:14 +02:00
|
|
|
Model\mark_as_read();
|
2013-02-18 03:48:21 +01:00
|
|
|
Response\redirect('?action=unread');
|
|
|
|
});
|
|
|
|
|
2013-07-16 15:00:14 +02:00
|
|
|
|
2013-07-18 00:55:28 +02:00
|
|
|
// Mark sent items id as read (Ajax request)
|
|
|
|
Router\post_action('mark-items-as-read', function(){
|
2013-07-16 15:00:14 +02:00
|
|
|
|
2013-07-18 00:55:28 +02:00
|
|
|
Model\mark_items_as_read(Request\values());
|
2013-07-16 15:00:14 +02:00
|
|
|
Response\json(array('OK'));
|
|
|
|
});
|
2013-02-18 03:48:21 +01:00
|
|
|
|
2013-07-18 00:55:28 +02:00
|
|
|
|
2013-07-06 16:50:37 +02:00
|
|
|
// Confirmation box to flush history
|
2013-04-07 04:21:16 +02:00
|
|
|
Router\get_action('confirm-flush-history', function() {
|
|
|
|
|
2013-06-01 04:01:01 +02:00
|
|
|
Response\html(Template\layout('confirm_flush_items', array(
|
2013-06-14 03:29:34 +02:00
|
|
|
'menu' => 'history',
|
|
|
|
'title' => t('Confirmation')
|
2013-04-07 04:21:16 +02:00
|
|
|
)));
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2013-07-06 16:50:37 +02:00
|
|
|
// Flush history
|
2013-02-18 03:48:21 +01:00
|
|
|
Router\get_action('flush-history', function() {
|
|
|
|
|
2013-05-26 19:09:34 +02:00
|
|
|
Model\mark_as_removed();
|
2013-02-18 03:48:21 +01:00
|
|
|
Response\redirect('?action=history');
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2013-07-06 16:50:37 +02:00
|
|
|
// Refresh all feeds, used when Javascript is disabled
|
2013-02-18 03:48:21 +01:00
|
|
|
Router\get_action('refresh-all', function() {
|
|
|
|
|
|
|
|
Model\update_feeds();
|
2013-07-06 20:29:45 +02:00
|
|
|
Model\write_debug();
|
|
|
|
|
2013-04-13 03:08:55 +02:00
|
|
|
Session\flash(t('Your subscriptions are updated'));
|
2013-02-18 03:48:21 +01:00
|
|
|
Response\redirect('?action=unread');
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2013-07-06 16:50:37 +02:00
|
|
|
// Display all feeds
|
2013-02-18 03:48:21 +01:00
|
|
|
Router\get_action('feeds', function() {
|
|
|
|
|
2013-07-17 02:46:40 +02:00
|
|
|
if (! Request\int_param('disable_empty_feeds_check')) {
|
2013-07-13 02:26:47 +02:00
|
|
|
|
2013-07-17 02:46:40 +02:00
|
|
|
$empty_feeds = Model\get_empty_feeds();
|
2013-07-13 02:26:47 +02:00
|
|
|
|
2013-07-17 02:46:40 +02:00
|
|
|
if (! empty($empty_feeds)) {
|
2013-07-13 02:26:47 +02:00
|
|
|
|
2013-07-17 02:46:40 +02:00
|
|
|
$listing = array();
|
|
|
|
|
|
|
|
foreach ($empty_feeds as &$feed) {
|
|
|
|
$listing[] = '"'.$feed['title'].'"';
|
|
|
|
}
|
2013-07-13 02:26:47 +02:00
|
|
|
|
2013-07-17 02:46:40 +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
|
|
|
|
2013-07-17 02:46:40 +02:00
|
|
|
Session\flash_error($message);
|
|
|
|
}
|
2013-07-11 14:24:10 +02:00
|
|
|
}
|
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'),
|
2013-06-14 03:29:34 +02:00
|
|
|
'menu' => 'feeds',
|
|
|
|
'title' => t('Subscriptions')
|
2013-02-18 03:48:21 +01:00
|
|
|
)));
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2013-07-06 16:50:37 +02: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(),
|
2013-06-14 03:29:34 +02:00
|
|
|
'menu' => 'feeds',
|
|
|
|
'title' => t('New subscription')
|
2013-02-18 03:48:21 +01:00
|
|
|
)));
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2013-07-06 16:50:37 +02:00
|
|
|
// Add the feed
|
2013-02-18 03:48:21 +01:00
|
|
|
Router\post_action('add', function() {
|
|
|
|
|
2013-07-14 17:59:01 +02:00
|
|
|
$result = Model\import_feed(trim($_POST['url']));
|
2013-07-06 20:29:45 +02:00
|
|
|
Model\write_debug();
|
|
|
|
|
|
|
|
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' => $_POST['url']),
|
2013-06-14 03:29:34 +02:00
|
|
|
'menu' => 'feeds',
|
|
|
|
'title' => t('Subscriptions')
|
2013-02-18 03:48:21 +01:00
|
|
|
)));
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2013-07-06 16:50:37 +02:00
|
|
|
// Optimize the database manually
|
2013-03-27 02:57:12 +01:00
|
|
|
Router\get_action('optimize-db', function() {
|
|
|
|
|
|
|
|
\PicoTools\singleton('db')->getConnection()->exec('VACUUM');
|
|
|
|
Response\redirect('?action=config');
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2013-07-06 16:50:37 +02:00
|
|
|
// Download the compressed database
|
2013-03-24 15:33:20 +01:00
|
|
|
Router\get_action('download-db', function() {
|
|
|
|
|
|
|
|
Response\force_download('db.sqlite.gz');
|
2013-07-06 18:11:29 +02:00
|
|
|
Response\binary(gzencode(file_get_contents(DB_FILENAME)));
|
2013-03-24 15:33:20 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2013-07-06 16:50:37 +02: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());
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2013-07-06 16:50:37 +02:00
|
|
|
// OPML import form
|
2013-02-18 03:48:21 +01:00
|
|
|
Router\get_action('import', function() {
|
|
|
|
|
|
|
|
Response\html(Template\layout('import', array(
|
|
|
|
'errors' => array(),
|
2013-06-14 03:29:34 +02:00
|
|
|
'menu' => 'feeds',
|
|
|
|
'title' => t('OPML Import')
|
2013-02-18 03:48:21 +01:00
|
|
|
)));
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2013-07-06 16:50:37 +02: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.'));
|
2013-07-17 02:46:40 +02:00
|
|
|
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-07-06 16:50:37 +02:00
|
|
|
// 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(),
|
2013-07-06 18:11:29 +02:00
|
|
|
'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(),
|
2013-07-06 16:50:37 +02:00
|
|
|
'paging_options' => Model\get_paging_options(),
|
2013-07-17 03:58:11 +02:00
|
|
|
'theme_options' => Model\get_themes(),
|
2013-06-14 03:29:34 +02:00
|
|
|
'menu' => 'config',
|
|
|
|
'title' => t('Preferences')
|
2013-02-18 03:48:21 +01:00
|
|
|
)));
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2013-07-06 16:50:37 +02: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,
|
2013-07-06 18:11:29 +02:00
|
|
|
'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(),
|
2013-07-06 16:50:37 +02:00
|
|
|
'paging_options' => Model\get_paging_options(),
|
2013-07-17 03:58:11 +02:00
|
|
|
'theme_options' => Model\get_themes(),
|
2013-06-14 03:29:34 +02:00
|
|
|
'menu' => 'config',
|
|
|
|
'title' => t('Preferences')
|
2013-02-18 03:48:21 +01:00
|
|
|
)));
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2013-07-06 16:50:37 +02:00
|
|
|
// 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-07-06 04:37:19 +02:00
|
|
|
$offset = Request\int_param('offset', 0);
|
2013-07-06 16:50:37 +02:00
|
|
|
$items = Model\get_unread_items($offset, Model\get_config_value('items_per_page'));
|
2013-07-06 04:37:19 +02:00
|
|
|
$nb_items = Model\count_items('unread');;
|
2013-03-17 23:16:25 +01:00
|
|
|
|
2013-07-06 16:50:37 +02:00
|
|
|
if ($nb_items === 0) Response\redirect('?action=feeds¬hing_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-03-17 23:16:25 +01:00
|
|
|
'items' => $items,
|
2013-06-14 03:29:34 +02:00
|
|
|
'nb_items' => $nb_items,
|
2013-07-06 04:37:19 +02:00
|
|
|
'nb_unread_items' => $nb_items,
|
|
|
|
'offset' => $offset,
|
2013-07-06 16:50:37 +02:00
|
|
|
'items_per_page' => Model\get_config_value('items_per_page'),
|
2013-06-14 03:29:34 +02:00
|
|
|
'title' => 'miniflux ('.$nb_items.')',
|
2013-02-18 03:48:21 +01:00
|
|
|
'menu' => 'unread'
|
|
|
|
)));
|
2013-06-06 17:54:22 +02:00
|
|
|
});
|