// 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\Item\count_by_feed($feed_id); $feed = Model\Feed\get($feed_id); $order = Request\param('order', 'updated'); $direction = Request\param('direction', Model\Config\get('items_sorting_direction')); $items = Model\Item\get_all_by_feed($feed_id, $offset, Model\Config\get('items_per_page'), $order, $direction); Response\html(Template\layout('feed_items', array('favicons' => Model\Feed\get_favicons(array($feed['id'])), 'original_marks_read' => Model\Config\get('original_marks_read'), 'order' => $order, 'direction' => $direction, 'display_mode' => Model\Config\get('items_display_mode'), 'feed' => $feed, 'items' => $items, 'nb_items' => $nb_items, 'nb_unread_items' => Model\Item\count_by_status('unread'), 'offset' => $offset, 'items_per_page' => Model\Config\get('items_per_page'), 'menu' => 'feed-items', 'title' => '(' . $nb_items . ') ' . $feed['title']))); }); // Ajax call to download an item (fetch the full content from the original website) Router\post_action('download-item', function () { $id = Request\param('id'); $item = Model\Item\get($id); $feed = Model\Feed\get($item['feed_id']); $download = Model\Item\download_content_id($id); $download['content'] = Model\Proxy\addProxyToTags($download['content'], $item['url'], Model\Config\get('image_proxy'), $feed['cloak_referrer']); Response\json($download); }); // Ajax call change item status Router\post_action('change-item-status', function () { $id = Request\param('id'); Response\json(array('item_id' => $id, 'status' => Model\Item\switch_status($id))); }); // Ajax call to mark item read Router\post_action('mark-item-read', function () { Model\Item\set_read(Request\param('id')); Response\json(array('Ok')); }); // Ajax call to mark item as removed
$values += array('enabled' => 0, 'download_content' => 0, 'rtl' => 0, 'cloak_referrer' => 0, 'feed_group_ids' => array(), 'create_group' => ''); list($valid, $errors) = Model\Feed\validate_modification($values); if ($valid) { if (Model\Feed\update($values)) { Session\flash(t('Your subscription has been updated.')); Response\redirect('?action=feeds'); } else { Session\flash_error(t('Unable to edit your subscription.')); } } Response\html(Template\layout('edit_feed', array('values' => $values, 'errors' => $errors, 'nb_unread_items' => Model\Item\count_by_status('unread'), 'groups' => Model\Group\get_all(), 'menu' => 'feeds', 'title' => t('Edit subscription')))); }); // Confirmation box to remove a feed Router\get_action('confirm-remove-feed', function () { $id = Request\int_param('feed_id'); Response\html(Template\layout('confirm_remove_feed', array('feed' => Model\Feed\get($id), 'nb_unread_items' => Model\Item\count_by_status('unread'), 'menu' => 'feeds', 'title' => t('Confirmation')))); }); // Remove a feed Router\get_action('remove-feed', function () { $id = Request\int_param('feed_id'); if ($id && Model\Feed\remove($id)) { Session\flash(t('This subscription has been removed successfully.')); } else { Session\flash_error(t('Unable to remove this subscription.')); } Response\redirect('?action=feeds'); }); // Refresh one feed and redirect to unread items Router\get_action('refresh-feed', function () { $feed_id = Request\int_param('feed_id'); $redirect = Request\param('redirect', 'unread');
use JsonRPC\Server; use PicoFeed\PicoFeedException; use Model\Config; $server = new Server(); $server->authentication(array(Config\get('username') => Config\get('api_token'))); // 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) {
if (!$feeds) { return $feeds; } $groups = Model\Group\get_feeds_map(); foreach ($feeds as &$feed) { $feed_id = $feed['id']; $feed['feed_group_ids'] = array(); if (isset($groups[$feed_id])) { $feed['feed_group_ids'] = $groups[$feed_id]; } } return $feeds; }); // Get one feed $server->register('feed.info', function ($feed_id) { $result = Model\Feed\get($feed_id); $result['feed_group_ids'] = Model\Group\get_feed_group_ids($feed_id); return $result; }); // 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; });