Пример #1
0
// 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');
});
Пример #2
0
    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');
    }
});
Пример #3
0
<?php

// Display history page
Router\get_action('history', function () {
    $offset = Request\int_param('offset', 0);
    $nb_items = Model\Item\count_by_status('read');
    $items = Model\Item\get_all_by_status('read', array(), $offset, Model\Config\get('items_per_page'), 'updated', Model\Config\get('items_sorting_direction'));
    Response\html(Template\layout('history', array('favicons' => Model\Favicon\get_item_favicons($items), 'original_marks_read' => Model\Config\get('original_marks_read'), 'items' => $items, 'order' => '', 'direction' => '', 'display_mode' => Model\Config\get('items_display_mode'), 'nb_items' => $nb_items, 'nb_unread_items' => Model\Item\count_by_status('unread'), 'offset' => $offset, 'items_per_page' => Model\Config\get('items_per_page'), 'nothing_to_read' => Request\int_param('nothing_to_read'), 'menu' => 'history', 'title' => t('History') . ' (' . $nb_items . ')')));
});
// Confirmation box to flush history
Router\get_action('confirm-flush-history', function () {
    Response\html(Template\layout('confirm_flush_items', array('nb_unread_items' => Model\Item\count_by_status('unread'), 'menu' => 'history', 'title' => t('Confirmation'))));
});
// Flush history
Router\get_action('flush-history', function () {
    Model\Item\mark_all_as_removed();
    Response\redirect('?action=history');
});
Пример #4
0
Router\get_action('bookmarks', function () {
    $offset = Request\int_param('offset', 0);
    $nb_items = Model\Item\count_bookmarks();
    $items = Model\Item\get_bookmarks($offset, Model\Config\get('items_per_page'));
    Response\html(Template\layout('bookmarks', array('favicons' => Model\Favicon\get_item_favicons($items), 'original_marks_read' => Model\Config\get('original_marks_read'), 'order' => '', 'direction' => '', 'display_mode' => Model\Config\get('items_display_mode'), 'items' => $items, 'nb_items' => $nb_items, 'offset' => $offset, 'items_per_page' => Model\Config\get('items_per_page'), 'nothing_to_read' => Request\int_param('nothing_to_read'), 'nb_unread_items' => Model\Item\count_by_status('unread'), 'menu' => 'bookmarks', 'title' => t('Bookmarks') . ' (' . $nb_items . ')')));
});
// Display bookmark feeds
Router\get_action('bookmark-feed', function () {
    // Select database if the parameter is set
    $database = Request\param('database');
    if (!empty($database)) {
        Model\Database\select($database);
    }
    // Check token
    $feed_token = Model\Config\get('feed_token');
    $request_token = Request\param('token');
    if ($feed_token !== $request_token) {
        Response\text('Access Forbidden', 403);
    }
    // Build Feed
    $writer = new Atom();
    $writer->title = t('Bookmarks') . ' - Miniflux';
    $writer->site_url = Helper\get_current_base_url();
    $writer->feed_url = $writer->site_url . '?action=bookmark-feed&token=' . urlencode($feed_token);
    $bookmarks = Model\Item\get_bookmarks();
    foreach ($bookmarks as $bookmark) {
        $article = Model\Item\get($bookmark['id']);
        $writer->items[] = array('id' => $article['id'], 'title' => $article['title'], 'updated' => $article['updated'], 'url' => $article['url'], 'content' => $article['content']);
    }
    Response\xml($writer->execute());
});
Пример #5
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');
    $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));
});
Пример #6
0
<?php

// Flush console messages
Router\get_action('flush-console', function () {
    @unlink(DEBUG_FILENAME);
    Response\redirect('?action=console');
});
// Display console
Router\get_action('console', function () {
    Response\html(Template\layout('console', array('content' => @file_get_contents(DEBUG_FILENAME), 'nb_unread_items' => Model\Item\count_by_status('unread'), 'menu' => 'config', 'title' => t('Console'))));
});
Пример #7
0
<?php

// 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())));
});
Пример #8
0
        }
    } elseif (Model\RememberMe\has_cookie()) {
        Model\RememberMe\refresh();
    }
    // Load translations
    $language = Model\Config\get('language') ?: 'en_US';
    Translator\load($language);
    // Set timezone
    date_default_timezone_set(Model\Config\get('timezone') ?: 'UTC');
    // HTTP secure headers
    Response\csp(array('media-src' => '*', 'img-src' => '* data:', 'frame-src' => Model\Config\get_iframe_whitelist(), 'referrer' => 'no-referrer'));
    Response\xframe();
    Response\xss();
    Response\nosniff();
    if (ENABLE_HSTS && Helper\is_secure_connection()) {
        Response\hsts();
    }
});
// Show help
Router\get_action('show-help', function () {
    Response\html(Template\load('show_help'));
});
// Show the menu for the mobile view
Router\get_action('more', function () {
    Response\html(Template\layout('show_more', array('menu' => 'more')));
});
// Image proxy (avoid SSL mixed content warnings)
Router\get_action('proxy', function () {
    Model\Proxy\download(rawurldecode(Request\param('url')));
    exit;
});