Esempio n. 1
0
 /**
  * Creates a new Zend\Feed\Writer\Entry data container for use. This is NOT
  * added to the current feed automatically, but is necessary to create a
  * container with some initial values preset based on the current feed data.
  *
  * @return \Zend\Feed\Writer\Entry
  */
 public function createEntry()
 {
     $entry = new Entry();
     if ($this->getEncoding()) {
         $entry->setEncoding($this->getEncoding());
     }
     $entry->setType($this->getType());
     return $entry;
 }
Esempio n. 2
0
 public function testGetCommentCountReturnsNullIfDateNotSet()
 {
     $entry = new Writer\Entry();
     $this->assertTrue(is_null($entry->getCommentCount()));
 }
Esempio n. 3
0
 /**
  * @expectedException Zend\Feed\Writer\Exception\ExceptionInterface
  */
 public function testSetSummaryThrowsExceptionWhenValueExceeds255Chars()
 {
     $entry = new Writer\Entry();
     $entry->setItunesSummary(str_repeat('a', 4001));
 }
Esempio n. 4
0
 if ($model === null) {
     return Response::make('Not Found', 404);
 }
 $feed = new Feed();
 $feed->setTitle($model->getAttribute('title'))->setDescription($model->getAttribute('description'))->setBaseUrl(Url::to('/'))->setGenerator('OctoberCMS/Adrenth.RssFetcher')->setId('Adrenth.RssFecther.' . $model->getAttribute('id'))->setLink(Url::to('/feeds/' . $path))->setFeedLink(Url::to('/feeds/' . $path), $model->getAttribute('type'))->setDateModified()->addAuthor(['name' => 'OctoberCMS']);
 /** @type Collection $sources */
 $sources = $model->sources;
 $ids = Arr::pluck($sources->toArray(), 'id');
 $items = [];
 Source::with(['items' => function ($builder) use(&$items, $model) {
     $items = $builder->where('is_published', '=', 1)->whereDate('pub_date', '=', date('Y-m-d'))->orderBy('pub_date', 'desc')->limit($model->getAttribute('max_items'))->get();
 }])->whereIn('id', $ids)->where('is_enabled', '=', 1)->get();
 /** @type Item $item */
 foreach ($items as $item) {
     try {
         $entry = new Entry();
         $entry->setId((string) $item->getAttribute('id'))->setTitle($item->getAttribute('title'))->setDescription($item->getAttribute('description'))->setLink($item->getAttribute('link'))->setDateModified($item->getAttribute('pub_date'));
         $comments = $item->getAttribute('comments');
         if (!empty($comments)) {
             $entry->setCommentLink($comments);
         }
         $category = $item->getAttribute('category');
         if (!empty($category)) {
             $entry->addCategory(['term' => $category]);
         }
         $feed->addEntry($entry);
     } catch (InvalidArgumentException $e) {
         continue;
     }
 }
 return Response::make($feed->export($model->getAttribute('type')), 200, ['Content-Type' => sprintf('application/%s+xml', $model->getAttribute('type'))]);
Esempio n. 5
0
 /**
  * Populates a feed entry with data coming from Version objects.
  *
  * @param \Zend\Feed\Writer\Entry $entry
  * @param Version                 $version
  */
 protected function populateVersionData(Entry $entry, Version $version)
 {
     $entry->setTitle($entry->getTitle() . " ({$version->getVersion()})");
     $entry->setId($entry->getId() . ' ' . $version->getVersion());
     $entry->setDateModified($version->getReleasedAt());
     $entry->setDateCreated($version->getReleasedAt());
     foreach ($version->getAuthors() as $author) {
         /** @var $author \Packagist\WebBundle\Entity\Author */
         if ($author->getName()) {
             $entry->addAuthor(array('name' => $author->getName()));
         }
     }
 }
Esempio n. 6
0
 /**
  * RSS feed
  *
  * @param Request $request
  *
  * @return Response
  *
  * @Route("/blog/rss", name="blog_rss")
  */
 public function rssAction(Request $request)
 {
     $feed = new Feed();
     $config = $this->container->getParameter('stfalcon_blog.config');
     $feed->setTitle($config['rss']['title']);
     $feed->setDescription($config['rss']['description']);
     $feed->setLink($this->generateUrl('blog_rss', array(), true));
     $posts = $this->get('doctrine')->getManager()->getRepository("StfalconBlogBundle:Post")->getAllPublishedPosts($request->getLocale());
     /** @var Post $post */
     foreach ($posts as $post) {
         $entry = new Entry();
         $entry->setTitle($post->getTitle());
         $entry->setLink($this->generateUrl('blog_post_view', array('slug' => $post->getSlug()), true));
         $feed->addEntry($entry);
     }
     $response = new Response($feed->export('rss'));
     $response->headers->add(array('Content-Type' => 'application/xml'));
     return $response;
 }
Esempio n. 7
0
 public function testFluentInterface()
 {
     $entry = new Writer\Entry();
     $result = $entry->addAuthor(array('name' => 'foo'))->addAuthors(array(array('name' => 'foo')))->setEncoding('utf-8')->setCopyright('copyright')->setContent('content')->setDateCreated(null)->setDateModified(null)->setDescription('description')->setId('1')->setLink('http://www.example.com')->setCommentCount(1)->setCommentLink('http://www.example.com')->setCommentFeedLink(array('uri' => 'http://www.example.com', 'type' => 'rss'))->setCommentFeedLinks(array(array('uri' => 'http://www.example.com', 'type' => 'rss')))->setTitle('title')->addCategory(array('term' => 'category'))->addCategories(array(array('term' => 'category')))->setEnclosure(array('uri' => 'http://www.example.com'))->setType('type')->setSource(new \Zend\Feed\Writer\Source());
     $this->assertSame($result, $entry);
 }
Esempio n. 8
0
 /**
  * @covers Zend\Feed\Writer\Entry::getSource
  * @covers Zend\Feed\Writer\Entry::createSource
  */
 public function testGetSource()
 {
     $entry = new Writer\Entry();
     $source = $entry->getSource();
     $this->assertNull($source);
     $entry->setSource($entry->createSource());
     $this->assertInstanceOf('Zend\\Feed\\Writer\\Source', $entry->getSource());
 }