/** * Create sample data * * @return void */ public function sampleDataCommand() { $this->itemRepository->removeAll(); $this->channelRepository->removeAll(); $this->categoryRepository->removeAll(); $flow3Category = new \Planetflow3\Domain\Model\Category('FLOW3'); $this->categoryRepository->add($flow3Category); $phpCategory = new \Planetflow3\Domain\Model\Category('PHP'); $this->categoryRepository->add($phpCategory); $phoenixCategory = new \Planetflow3\Domain\Model\Category('Phoenix'); $this->categoryRepository->add($phoenixCategory); $channels = array(); $channel = new \Planetflow3\Domain\Model\Channel(); $channel->setName('news.typo3.org: FLOW3'); $channel->setUrl('http://news.typo3.org/news/teams/flow3/'); $channel->setFeedUrl('http://news.typo3.org/news/teams/flow3/rss.xml'); $channel->setDefaultCategory($flow3Category); $this->channelRepository->add($channel); $channels[] = $channel; $channel = new \Planetflow3\Domain\Model\Channel(); $channel->setName('Karsten Dambekalns - Code & Content'); $channel->setUrl('http://blog.k-fish.de'); $channel->setFeedUrl('http://blog.k-fish.de/feeds/posts/default'); $channel->setFetchedCategories(array('PHP', 'FLOW3')); $this->channelRepository->add($channel); $channels[] = $channel; $channel = new \Planetflow3\Domain\Model\Channel(); $channel->setName('networkteam Blog - FLOW3'); $channel->setUrl('http://www.networkteam.com/blog.html'); $channel->setFeedUrl('http://www.networkteam.com/rss.xml'); $channel->setFilter('FLOW3'); $channel->setDefaultCategory($flow3Category); $this->channelRepository->add($channel); $channels[] = $channel; $channel = new \Planetflow3\Domain\Model\Channel(); $channel->setName('Robert Lemke - Fluent Code Artisan'); $channel->setUrl('http://robertlemke.de/blog/'); $channel->setFeedUrl('http://robertlemke.de/blog/feeds/posts.rss.xml'); $channel->setFilter('FLOW3,PHP'); $channel->setDefaultCategory($flow3Category); $this->channelRepository->add($channel); $channels[] = $channel; $channel = new \Planetflow3\Domain\Model\Channel(); $channel->setName('t3blog.de'); $channel->setUrl('http://t3blog.de'); $channel->setFeedUrl('http://t3blog.de/feed/'); $channel->setFilter('FLOW3'); $channel->setDefaultCategory($flow3Category); $this->channelRepository->add($channel); $channels[] = $channel; $channel = new \Planetflow3\Domain\Model\Channel(); $channel->setName('layh.com'); $channel->setUrl('http://www.layh.com'); $channel->setFeedUrl('http://www.layh.com/wordpress/feed/'); $channel->setFetchedCategories(array('FLOW3')); $this->channelRepository->add($channel); $channels[] = $channel; $this->outputLine('Created default categories and channels'); }
/** * @FLOW3\SkipCsrfProtection */ public function indexAction() { $items = $this->itemRepository->findByFilter(NULL); $recentItems = $items->getQuery()->setLimit(5)->execute(); $this->view->assign('itemCount', $this->itemRepository->countAll()); $this->view->assign('recentItems', $recentItems); $this->view->assign('channelCount', $this->channelRepository->countAll()); $this->view->assign('topChannels', $this->channelRepository->findTopChannels()); }
/** * Disable action * * @param \Planetflow3\Domain\Model\Item $item */ public function disableAction(\Planetflow3\Domain\Model\Item $item) { $item->setDisabled(TRUE); $this->itemRepository->update($item); $this->addFlashMessage('Item disabled.', 'Success', \TYPO3\FLOW3\Error\Message::SEVERITY_OK); $this->redirect('index'); }
/** * Apply filters * * Should be used after an update of the filter rules to re-apply filters * to description and content of an item. * * @return void */ public function applyFiltersCommand() { $items = $this->itemRepository->findAll(); foreach ($items as $item) { $item->setDescription($item->getDescription()); $item->setContent($item->getContent()); $this->itemRepository->update($item); } }
/** * Fetches (new) items from the configured feed of a channel * * Adds new items and updates channels with a new last fetch date. * * @param \Planetflow3\Domain\Model\Channel $channel * @param \Closure $logCallback * @return void */ public function fetchItems(Channel $channel, $logCallback = NULL) { if ($logCallback === NULL) { $logCallback = function (Item $item, $message, $severity = LOG_INFO) { }; } $simplePie = $this->createSimplePie($channel); $existingUniversalIdentifiers = $channel->getItemsUniversalIdentifier(); $feedItems = $simplePie->get_items(); foreach ($feedItems as $feedItem) { $item = new Item(); $item->setUniversalIdentifier($feedItem->get_id()); if (isset($existingUniversalIdentifiers[$item->getUniversalIdentifier()])) { $logCallback($item, 'Skipped item, already fetched', LOG_DEBUG); continue; } $this->populateItemProperties($item, $feedItem); $this->populateItemCategories($item, $feedItem, $logCallback); if ($item->getCategories()->count() === 0 && $channel->getDefaultCategory() !== NULL) { $item->addCategory($channel->getDefaultCategory()); } if ($item->matchesChannel($channel)) { $language = $this->textcat->classify($item->getDescription() . ' ' . $item->getContent()); if ($language !== FALSE) { $item->setLanguage($language); $logCallback($item, 'Detected language ' . $language . ' for item', LOG_DEBUG); } $channel->addItem($item); $this->itemRepository->add($item); $logCallback($item, 'Item fetched and saved', LOG_INFO); $existingUniversalIdentifiers[$item->getUniversalIdentifier()] = TRUE; } else { $logCallback($item, 'Skipped item, filter not matched', LOG_DEBUG); } } $channel->setLastFetchDate(new \DateTime()); $this->channelRepository->update($channel); }
/** * Feed action * * Render an aggregated feed for a given language. * * @param string $language Filter by language, NULL for all languages */ public function feedAction($language = NULL) { $filter = new \Planetflow3\Domain\Dto\ItemFilter(); $filter->setLanguage($language); $filter->setDisabled(FALSE); $result = $this->itemRepository->findByFilter($filter); $query = $result->getQuery(); $query->setLimit(20); $items = $query->execute(); $this->view->assign('language', $language); $this->view->assign('items', $items); $this->response->setHeader('Content-Type', 'application/rss+xml; charset=UTF-8'); // TODO Send correct cache control including last modified }
/** * Create some test data * * @return void */ protected function createTestData() { $channel = new \Planetflow3\Domain\Model\Channel(); $channel->setName('Test channel'); $channel->setUrl('http://www.example.com'); $channel->setFeedUrl('http://www.example.com/rss.xml'); $this->channelRepository->add($channel); $item = new \Planetflow3\Domain\Model\Item(); $item->setChannel($channel); $item->setAuthor('Test author'); // $item->setCategories(array('FLOW3')); $item->setTitle('A test post'); $item->setContent('My random content'); $item->setDescription('Some description'); $item->setLanguage('en'); $item->setLink('http://www.example.com/posts/2'); $item->setPublicationDate(new \DateTime('2011-10-09 08:07:06')); $item->setUniversalIdentifier('http://www.example.com/posts/2'); $this->itemRepository->add($item); }
/** * List recent items * * @param integer $itemsPerPage * @return void */ public function itemsAction($itemsPerPage = 10) { $items = $this->itemRepository->findRecent(0, $itemsPerPage); $this->view->assign('items', $items); }