$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'); $offset = Request\int_param('offset', 0); $feed_id = Request\int_param('feed_id', 0); Model\Item\set_unread($id); 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); $feed_id = Request\int_param('feed_id', 0); Model\Item\set_removed($id); Response\Redirect('?action=' . $redirect . '&offset=' . $offset . '&feed_id=' . $feed_id); }); Router\post_action('latest-feeds-items', function () { $items = Model\Item\get_latest_feeds_items(); $nb_unread_items = Model\Item\count_by_status('unread'); $feeds = array_reduce($items, function ($result, $item) { $result[$item['id']] = array('time' => $item['updated'] ?: 0, 'status' => $item['status']); return $result; }, array()); Response\json(array('feeds' => $feeds, 'nbUnread' => $nb_unread_items)); });
<?php use PicoFarad\Router; use PicoFarad\Response; use PicoFarad\Request; use PicoFarad\Session; use PicoFarad\Template; use PicoFeed\Syndication\Atom; // Ajax call to add or remove a bookmark Router\post_action('bookmark', function () { $id = Request\param('id'); $value = Request\int_param('value'); Response\json(array('id' => $id, 'value' => $value, 'result' => Model\Item\set_bookmark_value($id, $value))); }); // Add new bookmark Router\get_action('bookmark', function () { $id = Request\param('id'); $menu = Request\param('menu', 'unread'); $source = Request\param('source', 'unread'); $offset = Request\int_param('offset', 0); $feed_id = Request\int_param('feed_id', 0); Model\Item\set_bookmark_value($id, Request\int_param('value')); if ($source === 'show') { Response\Redirect('?action=show&menu=' . $menu . '&id=' . $id); } Response\Redirect('?action=' . $menu . '&offset=' . $offset . '&feed_id=' . $feed_id . '#item-' . $id); }); // Display bookmarks page Router\get_action('bookmarks', function () { $offset = Request\int_param('offset', 0); $nb_items = Model\Item\count_bookmarks();
Model\Config\write_debug(); if (isset($feed_id) && $feed_id !== false) { Session\flash(t('Subscription added successfully.')); Response\redirect('?action=feed-items&feed_id=' . $feed_id); } else { if (!isset($error_message)) { $error_message = t('Error occured.'); } Session\flash_error($error_message); } Response\html(Template\layout('add', array('values' => $values + array('csrf' => Model\Config\generate_csrf()), 'nb_unread_items' => Model\Item\count_by_status('unread'), 'groups' => Model\Group\get_all(), 'menu' => 'feeds', 'title' => t('Subscriptions')))); }); // OPML export Router\get_action('export', function () { Response\force_download('feeds.opml'); Response\xml(Model\Feed\export_opml()); }); // OPML import form Router\get_action('import', function () { Response\html(Template\layout('import', array('errors' => array(), 'nb_unread_items' => Model\Item\count_by_status('unread'), 'menu' => 'feeds', 'title' => t('OPML Import')))); }); // OPML importation Router\post_action('import', function () { if (Model\Feed\import_opml(Request\file_content('file'))) { Session\flash(t('Your feeds have been imported.')); Response\redirect('?action=feeds'); } else { Session\flash_error(t('Unable to import your OPML file.')); Response\redirect('?action=import'); } });
// 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'); });
<?php use PicoFarad\Router; use PicoFarad\Response; use PicoFarad\Request; use PicoFarad\Template; // Logout and destroy session Router\get_action('logout', function () { Model\User\logout(); Response\redirect('?action=login'); }); // Display form login Router\get_action('login', function () { if (Model\User\is_loggedin()) { Response\redirect('?action=unread'); } Response\html(Template\load('login', array('errors' => array(), 'values' => array('csrf' => Model\Config\generate_csrf()), 'databases' => Model\Database\get_list(), 'current_database' => Model\Database\select()))); }); // Check credentials and redirect to unread items Router\post_action('login', function () { $values = Request\values(); Model\Config\check_csrf_values($values); list($valid, $errors) = Model\User\validate_login($values); if ($valid) { Response\redirect('?action=unread'); } Response\html(Template\load('login', array('errors' => $errors, 'values' => $values + array('csrf' => Model\Config\generate_csrf()), 'databases' => Model\Database\get_list(), 'current_database' => Model\Database\select()))); });