/**
  * Delete all logs for a given Feed.
  *
  * @param Request $request
  * @param Feed    $feed    The document Feed (retrieving for a ParamConverter with the slug)
  *
  * @return RedirectResponse
  */
 public function deleteAllAction(Request $request, Feed $feed)
 {
     $form = $this->createDeleteAllForm();
     $form->handleRequest($request);
     if ($form->isValid()) {
         $res = $this->getDocumentManager()->getRepository('Api43FeedBundle:FeedLog')->deleteAllByFeedId($feed->getId());
         $this->get('session')->getFlashBag()->add('notice', $res['n'] . ' documents deleted!');
     }
     return $this->redirect($this->generateUrl('feed_edit', array('slug' => $feed->getSlug())));
 }
 /**
  * Following the previous action, this one will actually parse the content (for both parser).
  *
  * @param Request $request
  * @param Feed    $feed    The document Feed (retrieving for a ParamConverter with the slug)
  *
  * @return string
  */
 public function previewNewAction(Request $request, Feed $feed)
 {
     $rssFeed = $this->get('simple_pie_proxy')->setUrl($feed->getLink())->init();
     try {
         $parser = $this->get('content_extractor')->init($request->get('parser'), $feed);
     } catch (\InvalidArgumentException $e) {
         throw $this->createNotFoundException($e->getMessage());
     }
     $firstItem = $rssFeed->get_item(0);
     if (!$firstItem) {
         throw $this->createNotFoundException('No item found in this feed.');
     }
     $content = $parser->parseContent($firstItem->get_permalink(), $firstItem->get_description());
     return $this->render('Api43FeedBundle:FeedItem:content.html.twig', array('title' => html_entity_decode($firstItem->get_title(), ENT_COMPAT, 'UTF-8'), 'content' => $content->content, 'modal' => false, 'url' => $content->url, 'defaultContent' => $content->useDefault));
 }
Esempio n. 3
0
 /**
  * Render the feed in specified format.
  *
  * @param Feed $feed Feed to render
  *
  * @return string
  *
  * @throws \InvalidArgumentException if given format formatter does not exists
  */
 public function render(Feed $feed)
 {
     $items = $this->dm->getRepository('Api43FeedBundle:FeedItem')->findByFeed($feed->getId(), $feed->getSortBy());
     $feedUrl = $this->router->generate('feed_xml', array('slug' => $feed->getSlug()), true);
     switch ($feed->getFormatter()) {
         case 'rss':
             $formatter = new Formatter\RssFormatter($feed, $items, $feedUrl, $this->generator);
             break;
         case 'atom':
             $formatter = new Formatter\AtomFormatter($feed, $items, $feedUrl, $this->generator);
             break;
         default:
             throw new \InvalidArgumentException(sprintf("Format '%s' is not available. Please see documentation.", $feed->getFormatter()));
     }
     return $formatter->render();
 }
Esempio n. 4
0
 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     $feedReddit = new Feed();
     $feedReddit->setName('reddit');
     $feedReddit->setDescription('reddit');
     $feedReddit->setLink('http://reddit.com/.rss');
     $feedReddit->setParser('internal');
     $feedReddit->setFormatter('rss');
     $feedReddit->setHost('http://reddit.com');
     $feedReddit->setLogo('https://www.redditstatic.com/about/assets/reddit-logo.png');
     $feedReddit->setColor('#336699');
     $feedReddit->setIsPrivate(false);
     $feedReddit->setSortBy('created_at');
     $feedReddit->setNbItems(3);
     $feedReddit->setLastItemCachedAt(new \DateTime());
     $manager->persist($feedReddit);
     $this->addReference('feed-reddit', $feedReddit);
     $feedHN = new Feed();
     $feedHN->setName('HackerNews');
     $feedHN->setDescription('');
     $feedHN->setLink('https://news.ycombinator.com/rss');
     $feedHN->setParser('internal');
     $feedHN->setFormatter('atom');
     $feedHN->setHost('news.ycombinator.com');
     $feedHN->setLogo('https://news.ycombinator.com/yc500.gif');
     $feedHN->setColor('#ff6600');
     $feedHN->setIsPrivate(false);
     $feedHN->setSortBy('published_at');
     $feedHN->setNbItems(3);
     $feedHN->setLastItemCachedAt(new \DateTime());
     $manager->persist($feedHN);
     $this->addReference('feed-hackernews', $feedHN);
     $feedMadame = new Feed();
     $feedMadame->setName('Bonjour Madame');
     $feedMadame->setDescription('TOUS LES MATINS 10h, une nouvelle photo, une nouvelle fracture de l\'oeil ');
     $feedMadame->setLink('http://feeds2.feedburner.com/BonjourMadame');
     $feedMadame->setParser('external');
     $feedMadame->setFormatter('rss');
     $feedMadame->setHost('bonjourmadame.fr');
     $feedMadame->setIsPrivate(true);
     $feedMadame->setSortBy('published_at');
     $feedMadame->setNbItems(2);
     $feedMadame->setLastItemCachedAt(new \DateTime());
     $manager->persist($feedMadame);
     $this->addReference('feed-bonjourmadame', $feedMadame);
     $feedWild = new Feed();
     $feedWild->setName('Blog Wildtrip');
     $feedWild->setDescription('');
     $feedWild->setLink('http://blog.wildtrip.net/rss.xml');
     $feedWild->setParser('internal');
     $feedWild->setFormatter('atom');
     $feedWild->setHost('blog.wildtrip.net');
     $feedWild->setIsPrivate(false);
     $feedWild->setSortBy('published_at');
     $feedWild->setNbItems(3);
     $feedWild->setLastItemCachedAt(new \DateTime());
     $manager->persist($feedWild);
     $this->addReference('feed-wild', $feedWild);
     $manager->flush();
 }