Example #1
0
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.');
    } catch (PicoFeed\Client\InvalidCertificateException $e) {
        $error_message = t('Invalid SSL certificate.');
    } catch (PicoFeed\Client\InvalidUrlException $e) {
        // picoFeed uses this exception for multiple reasons, but doesn't
        // provide an exception code to distinguish what exactly happend here
        $error_message = $e->getMessage();
    } catch (PicoFeed\Client\MaxRedirectException $e) {
        $error_message = t('Maximum number of HTTP redirections exceeded.');
    } catch (PicoFeed\Client\MaxSizeException $e) {
        $error_message = t('The content size exceeds to maximum allowed size.');
    } catch (PicoFeed\Client\TimeoutException $e) {
        $error_message = t('Connection timeout.');
    } catch (PicoFeed\Parser\MalformedXmlException $e) {
Example #2
0
// Get version
$server->register('app.version', function () {
    return array('version' => APP_VERSION);
});
// Get all feeds
$server->register('feed.list', function () {
    return Model\Feed\get_all();
});
// Get one feed
$server->register('feed.info', function ($feed_id) {
    return Model\Feed\get($feed_id);
});
// Add a new feed
$server->register('feed.create', function ($url) {
    try {
        $result = Model\Feed\create($url);
    } catch (PicoFeedException $e) {
        $result = false;
    } catch (UnexpectedValueException $e) {
        $result = false;
    }
    Model\Config\write_debug();
    return $result;
});
// Delete a feed
$server->register('feed.delete', function ($feed_id) {
    return Model\Feed\remove($feed_id);
});
// Delete all feeds
$server->register('feed.delete_all', function () {
    return Model\Feed\remove_all();
Example #3
0
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('download_content' => 0, 'rtl' => 0, 'cloak_referrer' => 0);
    $url = trim($url);
    $feed_id = Model\Feed\create($url, $values['download_content'], $values['rtl'], $values['cloak_referrer']);
    if ($feed_id) {
        Session\flash(t('Subscription added successfully.'));
        Response\redirect('?action=feed-items&feed_id=' . $feed_id);
    } else {
        Session\flash_error(t('Unable to find a subscription.'));
    }
    Response\html(Template\layout('add', array('values' => array('url' => $url, 'csrf' => Model\Config\generate_csrf()), 'nb_unread_items' => Model\Item\count_by_status('unread'), '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 () {