// Display help page 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 Router\get_action('about', function () { Response\html(Template\layout('about', array('csrf' => Model\Config\generate_csrf(), 'config' => Model\Config\get_all(), 'nb_unread_items' => Model\Item\count_by_status('unread'), 'menu' => 'config', 'title' => t('Preferences')))); }); // 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()), 'nb_unread_items' => Model\Item\count_by_status('unread'), 'menu' => 'config', 'title' => t('Preferences')))); }); // Display API page 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')))); }); // 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('Preferences')))); }); // Update bookmark services Router\post_action('services', function () { $values = Request\values() + array('pinboard_enabled' => 0, 'instapaper_enabled' => 0); 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'); });
Model\Item\mark_all_as_read(); Response\redirect('?action=unread'); }); // Mark all unread items as read for a specific feed Router\get_action('mark-feed-as-read', function () { Model\Item\mark_feed_as_read(Request\int_param('feed_id')); Response\redirect('?action=feeds'); }); // Mark all unread items as read for a specific feed (Ajax request) Router\post_action('mark-feed-as-read', function () { Model\Item\mark_feed_as_read(Request\int_param('feed_id')); Response\json(array('OK')); }); // Mark sent items id as read (Ajax request) Router\post_action('mark-items-as-read', function () { Model\Item\mark_items_as_read(Request\values()); Response\json(array('OK')); }); // 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); 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');
$nb_unread_items = Model\Item\count_by_status('unread'); // possible with remember me function if ($nothing_to_read === 1 && $nb_unread_items > 0) { Response\redirect('?action=unread'); } Response\html(Template\layout('feeds', array('favicons' => Model\Feed\get_all_favicons(), 'feeds' => Model\Feed\get_all_item_counts(), 'nothing_to_read' => $nothing_to_read, 'nb_unread_items' => $nb_unread_items, 'nb_failed_feeds' => Model\Feed\count_failed_feeds(), 'menu' => 'feeds', 'title' => t('Subscriptions')))); }); // Display form to add one feed Router\get_action('add', function () { $values = array('download_content' => 0, 'rtl' => 0, 'cloak_referrer' => 0, 'create_group' => '', 'feed_group_ids' => array()); Response\html(Template\layout('add', array('values' => $values + array('csrf' => Model\Config\generate_csrf()), 'errors' => array(), 'nb_unread_items' => Model\Item\count_by_status('unread'), 'groups' => Model\Group\get_all(), 'menu' => 'feeds', 'title' => t('New subscription')))); }); // Add a feed with the form or directly from the url, it can be used by a bookmarklet by example Router\action('subscribe', function () { if (Request\is_post()) { $values = Request\values(); Model\Config\check_csrf_values($values); $url = isset($values['url']) ? $values['url'] : ''; } else { $values = array(); $url = Request\param('url'); $token = Request\param('token'); if ($token !== Model\Config\get('bookmarklet_token')) { Response\text('Access Forbidden', 403); } } $values += array('url' => trim($url), 'download_content' => 0, 'rtl' => 0, 'cloak_referrer' => 0, 'create_group' => '', 'feed_group_ids' => array()); try { $feed_id = Model\Feed\create($values['url'], $values['download_content'], $values['rtl'], $values['cloak_referrer'], $values['feed_group_ids'], $values['create_group']); } catch (UnexpectedValueException $e) { $error_message = t('This subscription already exists.');