/** * Generate RSS feeds for current user * * @param $token * @param $user_id * @param $tag_id if $type is 'tag', the id of the tag to generate feed for * @param string $type the type of feed to generate * @param int $limit the maximum number of items (0 means all) */ public function generateFeeds($token, $user_id, $tag_id, $type = 'home', $limit = 0) { $allowed_types = array('home', 'fav', 'archive', 'tag'); $config = $this->store->getConfigUser($user_id); if ($config == null) { die(sprintf(_('User with this id (%d) does not exist.'), $user_id)); } if (!in_array($type, $allowed_types) || !isset($config['token']) || $token != $config['token']) { die(_('Uh, there is a problem while generating feed. Wrong token used?')); } $feed = new FeedWriter(RSS2); $feed->setTitle('wallabag — ' . $type . ' feed'); $feed->setLink(Tools::getPocheUrl()); $feed->setChannelElement('pubDate', date(DATE_RSS, time())); $feed->setChannelElement('generator', 'wallabag'); $feed->setDescription('wallabag ' . $type . ' elements'); if ($type == 'tag') { $entries = $this->store->retrieveEntriesByTag($tag_id, $user_id); } else { $entries = $this->store->getEntriesByView($type, $user_id); } // if $limit is set to zero, use all entries if (0 == $limit) { $limit = count($entries); } if ($entries && count($entries) > 0) { for ($i = 0; $i < min(count($entries), $limit); $i++) { $entry = $entries[$i]; $newItem = $feed->createNewItem(); $newItem->setTitle($entry['title']); $newItem->setSource(Tools::getPocheUrl() . '?view=view&id=' . $entry['id']); $newItem->setLink($entry['url']); $newItem->setDate(time()); $newItem->setDescription($entry['content']); $feed->addItem($newItem); } } else { Tools::logm("database error while generating feeds"); } $feed->genarateFeed(); exit; }