Coder Social home page Coder Social logo

feedbundle's Introduction

FeedBundle

A Symfony bundle to build RSS/Atom feeds from entities

SensioLabsInsight

Build Status Latest Stable Version Total Downloads

Features

  • Generate XML feeds (RSS & Atom formats)
  • Easy to configure & use
  • Items based on your entities
  • Add groups of items
  • Add enclosure media tags
  • Translate your feed data
  • Read XML feeds and populate your Symfony entities
  • Dump your feeds into a file via a Symfony console command

Installation

Add the package to your composer.json file

"eko/feedbundle": "dev-master",

Add this to to the config/bundles.php file:

<?php

return [
    // ...
    Eko\FeedBundle\EkoFeedBundle::class => ['all' => true],
];

Configuration (only 3 quick steps!)

1) Create a file: config/packages/eko_feed.yml

The following configuration lines are required:

eko_feed:
    hydrator: your_hydrator.custom.service # Optional, if you use entity hydrating with a custom hydrator
    translation_domain: test # Optional, if you want to use a custom translation domain
    feeds:
        article:
            title:       'My articles/posts'
            description: 'Latests articles'
            link:        'http://vincent.composieux.fr'
            encoding:    'utf-8'
            author:      'Vincent Composieux' # Only required for Atom feeds

You can also set link as a Symfony route:

link:
    route_name: acme_blog_main_index
    route_params: {id: 2} # necessary if route contains required parameters

2) Implement the ItemInterface

Each entities you will use to generate an RSS feed needs to implement Eko\FeedBundle\Item\Writer\ItemInterface or Eko\FeedBundle\Item\Writer\RoutedItemInterface as demonstrated in this example for an Article entity of a blog:

Option A: Eko\FeedBundle\Item\Writer\ItemInterface

<?php

namespace Bundle\BlogBundle\Entity;

use Eko\FeedBundle\Item\Writer\ItemInterface;

/**
 * Bundle\BlogBundle\Entity\Article
 */
class Article implements ItemInterface
{

In this same entity, just implement those required methods:

  • public function getFeedItemTitle() { … } : this method returns entity item title
  • public function getFeedItemDescription() { … } : this method returns entity item description (or content)
  • public function getFeedItemPubDate() { … } : this method returns entity item publication date
  • public function getFeedItemLink() { … } : this method returns entity item link (URL)

Option B: Eko\FeedBundle\Item\Writer\RoutedItemInterface

Alternatively, if you need to make use of the router service to generate the link for your entity you can use the following interface. You don't need to worry about injecting the router to your entity.

<?php

namespace Bundle\BlogBundle\Entity;

use Eko\FeedBundle\Item\Writer\RoutedItemInterface;

/**
 * Bundle\BlogBundle\Entity\Article
 */
class Article implements RoutedItemInterface
{

In this entity, you'll need to implement the following methods:

  • public function getFeedItemTitle() { … } : this method returns entity item title
  • public function getFeedItemDescription() { … } : this method returns entity item description (or content)
  • public function getFeedItemPubDate() { … } : this method returns entity item publication date
  • public function getFeedItemRouteName() { … } : this method returns the name of the route
  • public function getFeedItemRouteParameters() { … } : this method must return an array with the parameters that are required for the route
  • public function getFeedItemUrlAnchor() { … } : this method returns the anchor that will be appended to the router-generated url. Note: can be an empty string.

3) Generate the feed!

The action now takes place in your controller. Just declare a new action with those examples lines:

<?php

namespace App\Controller;

use Eko\FeedBundle\Feed\FeedManager;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class BlogController extends AbstractController
{
    /**
     * @var FeedManager
     */
    protected $feedManager;

    /**
     * Constructor.
     * 
     * @param FeedManager $feedManager
     */
    public function __construct(FeedManager $feedManager)
    {
        $this->feedManager = $feedManager;
    }

    /**
     * Generate the article feed
     * 
     * @Route("/feed.rss", name="app_feed")
     *
     * @return Response XML Feed
     */
    public function feed()
    {
        $articles = $this->getDoctrine()->getRepository('BundleBlogBundle:Article')->findAll();

        $feed = $this->feedManager->get('article');
        $feed->addFromArray($articles);

        return new Response($feed->render('rss')); // or 'atom'
    }
}

Please note that for better performances you can add a cache control.

Moreover, entities objects can be added separately with add method:

<?php
$feed = $this->get('eko_feed.feed.manager')->get('article');
$feed->add($article);

Go further with your feeds

Add some custom channel fields

You can add custom fields to main channel by adding them this way:

<?php
$feed = $this->get('eko_feed.feed.manager')->get('article');
$feed->add(new FakeEntity());
$feed->addChannelField(new ChannelField('custom_name', 'custom_value'));

Add some custom items fields

Add custom item fields

You can add custom items fields for your entities nodes by adding them this way:

<?php
$feed = $this->get('eko_feed.feed.manager')->get('article');
$feed->add(new FakeEntity());
$feed->addItemField(new ItemField('fake_custom', 'getFeedItemCustom'));

Of course, getFeedItemCustom() method needs to be declared in your entity.

Add a group of custom item fields (optionally, with attributes)

You can also add group item fields using this way, if your method returns an array:

<?php
$feed = $this->get('eko_feed.feed.manager')->get('article');
$feed->add(new FakeEntity());
$feed->addItemField(
    new GroupItemField(
        'categories',
        new ItemField('category', 'getFeedCategoriesCustom', array(), array('category-attribute', 'test'),
        array('categories-attribute', 'getAttributeValue')
    )
);

or even, multiple item fields in a group, like this:

$feed->addItemField(
    new GroupItemField('author', array(
        new ItemField('name', 'getFeedItemAuthorName', array('cdata' => true)),
        new ItemField('email', 'getFeedItemAuthorEmail')
    )
);

or even, nested group item field in a group, like this:

$feed->addItemField(
    new GroupItemField('authors', array(
        new GroupItemField('author', array(
            new ItemField('name', 'Vincent', array('cdata' => true)),
            new ItemField('email', '[email protected]')
        )),
        new GroupItemField('author', array(
            new ItemField('name', 'Audrey', array('cdata' => true)),
            new ItemField('email', '[email protected]')
        ))
    )
);
Add a group of custom channel fields

As you can do for item fields, you can also add a custom group of channel fields like this:

$feed->addChannelField(
    new GroupChannelField('author', array(
        new ChannelField('name', 'My author name'),
        new ChannelField('email', '[email protected]')
    )
);
Add custom media item fields

Media enclosure can be added using the MediaItemField field type as below:

<?php
$feed = $this->get('eko_feed.feed.manager')->get('article');
$feed->add(new FakeEntity());
$feed->addItemField(new MediaItemField('getFeedMediaItem'));

The getFeedMediaItem() method must return an array with the following keys: type, length & value:

/**
 * Returns a custom media field
 *
 * @return string
 */
public function getFeedMediaItem()
{
    return array(
        'type'   => 'image/jpeg',
        'length' => 500,
        'value'  => 'http://website.com/image.jpg'
    );
}

This media items can also be grouped using GroupItemField.

Dump your feeds by using the Symfony console command

You can dump your feeds into a .xml file if you don't want to generate it on the fly by using the php app/console eko:feed:dump Symfony command.

Here are the options :

Option Description
--name Feed name defined in eko_feed configuration
--entity Entity to use to generate the feed
--filename Defines feed filename
--orderBy Order field to sort by using findBy() method
--direction Direction to give to sort field with findBy() method
--format Formatter to use to generate, "rss" is default
--limit Defines a limit of entity items to retrieve
Host Defines the host base to generate absolute Url

An example with all the options:

php app/console eko:feed:dump --name=article --entity=AcmeDemoBundle:Fake --filename=test.xml --format=atom --orderBy=id --direction=DESC www.myhost.com

This will result:

Start dumping "article" feed from "AcmeDemoBundle:Fake" entity...
done!
Feed has been dumped and located in "/Users/vincent/dev/perso/symfony/web/test.xml"

Dump your feeds by using the Eko\FeedBundle\Service\FeedDumpService

You can dump your feeds by simply using the "Eko\FeedBundle\Service\FeedDumpService" service. Used by the dump command, you have the same value to set. If you already have you items feed ready, you can dump it using the setItems().

<?php

use Eko\FeedBundle\Service\FeedDumpService;

$feedDumpService = $this->get(FeedDumpService::class);
$feedDumpService
        ->setName($name)
        //You can set an entity
        //->setEntity($entity)
        // Or set you Items
        ->setItems($MyOwnItemList)
        ->setFilename($filename)
        ->setFormat($format)
        ->setLimit($limit)
        ->setDirection($direction)
        ->setOrderBy($orderBy)
    ;

$feedDumpService->dump();

For any question, do not hesitate to contact me and/or participate.

Read an XML feed and populate an entity

If you only want to read an XML feed, here is the way:

<?php
$reader = $this->get('eko_feed.feed.reader');
$reader->setHydrator(new DefaultHydrator());
$feed = $reader->load('http://php.net/feed.atom')->get();

$feed will be a \Zend\Feed\Reader\Feed\FeedInterface that you can manipulate.


You can also populate an entity from an XML feed. This is very easy.

Just load the feed and call the populate method with your entity name which needs to implement Eko\FeedBundle\Item\Reader\ItemInterface, take a look on this example:

<?php
$reader = $this->get('eko_feed.feed.reader');
$reader->setHydrator(new DefaultHydrator());
$items = $reader->load('http://php.net/feed.atom')->populate('MyNamespace\Entity\Name');

In this example, $items will be an array that will contains an array with your entities populated with the given feed content.

Use a custom hydrator to populate your entity

You can also write your own hydrator and use it this way:

$reader = $this->get('eko_feed.feed.reader');
$reader->setHydrator(new MyCustomHydrator());

$items = $reader->load('http://php.net/feed.atom')->populate('MyNamespace\Entity\Name');

This way, your custom hydrator will be used instead of the Eko\FeedBundle\Hydrator\DefaultHydrator

Define a custom feed formatter

You can define your own feed formatter by using the following tag:

<service id="acme.my_bundle.formatter.custom" class="Acme\MyBundle\Feed\Formatter\CustomFormatter">
    <tag name="eko_feed.formatter" format="custom"></tag>

    <argument type="service" id="translator" />
</service>

Then, use it by simply calling $feed->render('custom').

Contributors

feedbundle's People

Contributors

abame avatar adel-e avatar bamarni avatar bitdeli-chef avatar catchamonkey avatar claretcrab avatar clemherreman avatar dependabot-preview[bot] avatar eko avatar etiennecallies avatar franmomu avatar jakon89 avatar lsmith77 avatar nvbooster avatar qsomazzi avatar robmasters avatar scullwm avatar sebastianblum avatar stanislavkukucka avatar thierrymarianne avatar wouterj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

feedbundle's Issues

RssFormatter is not rendering the Atom namespace at the top of the feed

According to w3c validator, the feed should contain the atom namespace.
here is the spec: http://validator.w3.org/feed/docs/warning/MissingAtomSelfLink.html

So when i tried to validate my RSS generated Feed, it was validated because the Atom namespace is messing.

this the current rendering:
<rss version="2.0">

Instead of this, we need to get:
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">

So, jusr add in the RssFormatter:
$root->setAttribute('xmlns:atom', "http://www.w3.org/2005/Atom");

and the feed channel section, add:
<atom:link href="http://example.com/feed.xml" rel="self" type="application/rss+xml" />

here we need to put the href of the feed as config variable.

Thank you !

Install with 5.3.3 >= PHP version <= 5.3.23

As discussed in #28, since some Zend updates this Bundle needs PHP >= 5.3.23.
Though... As it's only needed for compatibility with latests Zend updates, how could I install this Bundle with my PHP 5.3.3 ?
Is the only solution cloning this Bundle ?

Allow channel/link to come from a route name and parameters

This means that you'd configure it something like this:

eko_feed:
    feeds:
        post:
            link:
                type: route
                route_name: acme_blog_main_index
                route_params: {}

Of course it might vary, but the idea is that I don't have to hard-code a link URL or use a parameter, the latter of which I am currently doing:

eko_feed:
    feeds:
        post:
            link:        'http://%acme_blog_hostname%/'

one feed, several entities?

Hi, thanks a lot for the bundle.

I need generate a rss feed with several entities, is it possible?

thanks a lot

Bug in attribute value assignment

I believe there is a bug in Formatter/Formatter.php - on line 300, where the value is supposed to be set for an attribute, $item->getFeedItemLink() is being used in place of the value:

$element->setAttribute($field->get('attribute_name'), $item->getFeedItemLink());

should be

$element->setAttribute($field->get('attribute_name'), $value); 

In case I'm misunderstanding how it's supposed to work, I am setting up the item with attributes like this:

$feed->addItemField(new ItemField('media:thumbnail', 'getFeedImageThumbnail', 
    array('attribute' => true,'attribute_name' => 'url')
));

and expect an xml element like:

<media:thumbnail url="http://example.com/image.jpg"/>

Thanks again for your work here

GroupItemField with attributes

Hi, first thanks for this very useful bundle. I figured out how to add attributes to a custom ItemField, what I need to do now is take it a step further and nest other tags beneath that. For example, i can get my <foo bar="whatever"> tag like so:

$feed->addItemField(new ItemField('foo', 'getBar', array(
    'attribute' => true,
    'attribute_name' => 'bar',
));

But what I ultimately need is this, and don't see a way yet to add attributes to GroupItemFields:

<foo bar="whatever">
  <baz>Something Else</baz>
  <bop>Another Thing</bop>
  <boop>And Another</boop>
</foo>

One suggestion would be an option to pass either a string or an instance of ItemField as the first parameter of GroupItemField::construct(). In the case of a string, the current behavior remains (a simple tag like <string> is used for the parent tag), but if an ItemField object is passed, then IT gets used as the parent tag. This would solve my problem, and potentially others?

So in this case, the code would look something like:

$parent = new ItemField('foo', 'getBar', array(
    'attribute' => true,
    'attribute_name' => 'bar',
));

$feed->addGroupItemField($parent, array(
    new ItemField('baz', 'getBaz'),
    new ItemField('bop', 'getBop'),
    new ItemField('boop', 'getBoop'),
));

Thoughts?

order pubDate seem not be respected

with generated rss on the fly, pubDate order seem not to be respected

Want newest first and older after

Is there a way to override order with "on the fly" method ?

Flexible configuration.

Hi
Is exists solution to avoid 'static' config, for example:

eko_feed:
    feeds:
        article:
            title:       'My articles/posts'
            description: 'Latests articles'
            link:        'http://vincent.composieux.fr'
            encoding:    'utf-8'
            author:      'Vincent Composieux' # Only required for Atom feeds

and do it dynamically for each request?

dynamic route_params?

Hi, is there any possibility to configure dynamic route_params? e.g. I have the following use case:

URL: /order/12345/delivery (where 12345 represents an unique order number) should return the following ATOM feed:

`

<title>order/delivery-feed</title>

<subtitle>xxx</subtitle>

<link href="/order/12345/delivery" rel="self" type="application/rss+xml"/>

<updated>2016-09-05T09:45:25+02:00</updated>

<id>/order/12345/delivery</id>

<author>

    <name>xxx</name>

</author>
`

The issue is, that in config.yml I can only configure static routing params, e.g

link:
route_name: order_delivery
route_params:
id: xyz

And this would result in

<link href="/order/xyz/delivery" rel="self" type="application/rss+xml"/>

Please tell me, how can I inject the order number 12345 into the feed itself?

BR

Daniel

Tag a new release version

Hi, would it be possible tag a new version whenever you can to get rid of the deprecations notices? Thanks

How to use a proxy for $reader->load()?

My server has to use a proxy when reading feed.
Is it possible to configure the reader to use a proxy?

Or do I have to/can I use a workaround? E.g. load the content of the feed via another library, put it into a file and use the $reader->($localFilePath)?

Add content in an Item, without calling a method in the Entity.

Hi.
I would like to know if there is any way to add some content in an Item, without calling a method in the Entity.
On my code, each entity Article as a "modules" property, which is an Array Collection of differents set of other entities ( in order for the user to be able to build flexible content).

Basically, i would like to add content in an Item, the same way i can add content to the Channel with the following method :
$feed->addChannelField(new ChannelField('custom_name', 'custom_value'));

Thanks for reader me.

Ludo

Documentation

Salut,
Pouvez-vous expliquer comment ajouter de nouveaux champs.
J'aimerai ajouter plusieurs élément "category" dans les éléments "item".

Merci.


Hy !

Can you add some explanation about the possibility of adding new field?
I want to add multiple field "category" into the "item" element.

Thanks

php 7 with symfony 4 I have messages "is abandoned"

Hello,

In php 7 with symfony 4 I have messages "is abandoned" like that

Package container-interop/container-interop is abandoned, you should avoid using it. Use psr/container instead.
Package zendframework/zend-stdlib is abandoned, you should avoid using it. Use laminas/laminas-stdlib instead.
Package zendframework/zend-validator is abandoned, you should avoid using it. Use laminas/laminas-validator instead.
Package zendframework/zend-escaper is abandoned, you should avoid using it. Use laminas/laminas-escaper instead.
Package zendframework/zend-uri is abandoned, you should avoid using it. Use laminas/laminas-uri instead.
Package zendframework/zend-loader is abandoned, you should avoid using it. Use laminas/laminas-loader instead.
Package zendframework/zend-http is abandoned, you should avoid using it. Use laminas/laminas-http instead.
Package zendframework/zend-servicemanager is abandoned, you should avoid using it. Use laminas/laminas-servicemanager instead.
Package zendframework/zend-feed is abandoned, you should avoid using it. Use laminas/laminas-feed instead.

Can you fix it?

Missing command.xml file

The last commit introduced the following error:

  The file "command.xml" does not exist (in: [...]/vendor/eko/feedbundle/DependencyInjection/..  
  /Resources/config). 

The call to that file was added by the last merge but the corresponding file was not. So you should either add the missing file or remove the call...

Ability to output relational data from entities

Hi, I was wondering if you have incorporated the ability to output the relations within the entities. For example, if i had a many to many relation in my article entity to tags, then the feed can output the tags array ? is this possible?

thanks ( and great bundle btw )

About getFeedItemLink method

Hi, I think the method getFeedItemLink for generating the entity url is not sufficient. The url should be generated through the router. For example I have field "slug" handled by Doctrine Extensions sluggable and it's just a key, not a complete entity url.

Having problem adding RSS feeds to Entity

Hi,

I am trying to save the RSS feeds being fetched to my database, following the instructions this is the code inside my controller

       $reader = $this->get('eko_feed.feed.reader');       
        $items = $reader->load('http://rss.indeed.com/rss?q=Singapore')->populate('AppBundle\Entity\Rss');

This is my Rss Entity

title = $title;
    }


    /**
     * Returns a description or content
     *
     * @return string
     */
    public function setFeedItemDescription($description)
    {
        $this->description = $description;
    }

    /**
     * Returns item link
     *
     * @return string
     */
    public function setFeedItemLink($link)
    {
        $this->link = $link;
    }

    /**
     * Returns publication date
     *
     * @return \DateTime
     */
    public function setFeedItemPubDate(\DateTime $date)
    {
        $this->date = $date;
    }

    /**
     * Get title
     *
     * @return string
     */
    public function getTitle()
    {
        return $this->title;
    }

    /**
     * Get description
     *
     * @return string
     */
    public function getDescription()
    {
        return $this->description;
    }

    /**
     * Get link
     *
     * @return string
     */
    public function getLink()
    {
        return $this->link;
    }

    /**
     * Get publication date
     *
     * @return \DateTime
     */
    public function getPublicationDate()
    {
        return $this->date;
    }
    
    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set title
     *
     * @param string $title
     * @return Rss
     */
    public function setTitle($title)
    {
        $this->title = $title;

        return $this;
    }

    /**
     * Set description
     *
     * @param string $description
     * @return Rss
     */
    public function setDescription($description)
    {
        $this->description = $description;

        return $this;
    }

    /**
     * Set link
     *
     * @param string $link
     * @return Rss
     */
    public function setLink($link)
    {
        $this->link = $link;

        return $this;
    }

    /**
     * Set date
     *
     * @param \DateTime $date
     * @return Rss
     */
    public function setDate($date)
    {
        $this->date = $date;

        return $this;
    }

    /**
     * Get date
     *
     * @return \DateTime 
     */
    public function getDate()
    {
        return $this->date;
    }
    

    /**
     * Set publicationDate
     *
     * @param \DateTime $publicationDate
     * @return Rss
     */
    public function setPublicationDate($publicationDate)
    {
        $this->publicationDate = $publicationDate;

        return $this;
    }

    /**
     * Get feedItemTitle
     *
     * @return string 
     */
    public function getFeedItemTitle()
    {
        return $this->feedItemTitle;
    }

    /**
     * Get feedItemDescription
     *
     * @return string 
     */
    public function getFeedItemDescription()
    {
        return $this->feedItemDescription;
    }

    /**
     * Get feedItemLink
     *
     * @return string 
     */
    public function getFeedItemLink()
    {
        return $this->feedItemLink;
    }

    /**
     * Get feedItemPubDate
     *
     * @return \DateTime 
     */
    public function getFeedItemPubDate()
    {
        return $this->feedItemPubDate;
    }
}

When i run the action the error i get is as following and i don't understand why. What am i doing wrong?

Error: Call to a member function hydrate() on null

Should it be possible to add more fields to channel?

Note: I've not researched RSS too much, so I'm not sure if it's even valid, but currently there's no way to add, say, a copyright, generator, or language field to the channel since title, description and link are hard-coded in an array in the RSSFormatter.

Atom entry author

Hi,

Thanks for the good work.

I didn't find the way to add the complete author tag within entries in an atom feed.

Something like:

<entry>
    ...
    <author>
        <name>author's name</name>
        [<email>author's email</email>]
    </author>
</entry>

Thanks in advance for your help.

Offline generation

A command must be created to generated feed on disk and not at runtime.

Tagging a released version

Once dev-zend is merged into master, do you think it will become possible to tag a released version in the near future (like next month)?
we plan to tag stable releases of the cmf bundles in march, once symfony 2.2 became stable. the more dependencies provide tagged versions, the easier for us to model the dependencies.

FeedDumpService instance error

When executing the command which uses the FeedDumpService the following error occurs:

[Symfony\Component\Debug\Exception\ContextErrorException] Catchable Fatal Error: Argument 2 passed to Eko\FeedBundle\Service\FeedDumpService::__construct() must be an instance of Doctrine\ORM\EntityManager, instance of Ehealth\DoctrineEncryptionBundle\ORM\EntityManagerDecorator given, calle d in /run/shm/ehealthsoa/cache/dev/appDevDebugProjectContainer.php on line 2535 and defined

This error can be resolved by changing the typehint for Doctrine to: EntityManagerInterface in the FeedDumpService::__constructor();

Hope this helps.

add support of enclosure/media

I know, this can be a bit tricky but I would love to have support of enclosure to add item image.

RSS 2.0

<enclosure 
         type="image/jpeg"
         url="http://www.example.org/myimage.jpg"
         length="1234" />

Atom ?

<link rel="enclosure" 
          type="image/jpeg"
          title="My nice picture"
          href="http://www.example.org/myimage.jpg"
          length="1234" />

I looked at the Field class and see that is not possible "Out of the box".
Did you have any idea or advice on how to implement this ?

[ErrorException] Warning: fopen(): Filename cannot be empty

Hi
I act according to the instructions for use from feed bundle, but I run command

php app/console eko:feed:dump --name=article --entity=YoutabsGeneralModelBundle:Article --filename=rss.xml --format=atom --orderBy=id --direction=DESC

I have a error :

[ErrorException]
Warning: fopen(): Filename cannot be empty in C:\projects\shafajoo\vendor\e
ko\feedbundle\Eko\FeedBundle\Command\FeedDumpCommand.php line 77

I don't know ?

Custom channel field

I was custom channel field in RSS but I can not find any where How I can add custom item field under custom channel field ?
Like this:

<image>
     <url>www.xyz.com</url>
     <title>XYZ</title>
     <description>abcdefgh</description>
</image>

Any help !

Add additional information from external RSS feed

Hi @eko,

I am trying to use this bundle for jobboard where the bundle will be setup to fetch jobs based on rss. At present I can see and persist the following information to the database

- feed_item_title
- feed_item_description
- feed_item_link
- feed_item_pub_date

But I need more information like, city, country, etc.. (the rss feeds we will be fetching provide this information) so I have few questions

  1. Do I need to create custom hydrator?
  2. It is my understanding that inside the hydrator I should be able to access the details i need (city, state and country), if this is true then how do I access it?

For example inside DefaultHydrator I can see that you are doing the following
$entity->setFeedItemTitle($entry->getTitle());

How do you know that you have access to $entry->getTitle() because when I var_dump $entry all i see is as following

object(Zend\Feed\Reader\Entry\Rss)[263]
  protected 'xpathQueryRdf' => string '//rss:item[1]' (length=13)
  protected 'xpathQueryRss' => string '//item[1]' (length=9)
  protected 'data' => 
    array (size=1)
      'type' => string 'rss-20' (length=6)
  protected 'domDocument' => 
    object(DOMDocument)[36]
  protected 'entry' => 
    object(DOMElement)[266]
  protected 'entryKey' => int 0
  protected 'xpath' => 
    object(DOMXPath)[265]
  protected 'extensions' => 
    array (size=7)
      'Slash\Entry' => 
        object(Zend\Feed\Reader\Extension\Slash\Entry)[370]
          protected 'data' => 
            array (size=1)
              ...
          protected 'domDocument' => 
            object(DOMDocument)[36]
              ...
          protected 'entry' => 
            object(DOMElement)[266]
              ...
          protected 'entryKey' => int 0
          protected 'xpath' => 
            object(DOMXPath)[265]
              ...
          protected 'xpathPrefix' => string '//item[1]' (length=9)
      'WellFormedWeb\Entry' => 
        object(Zend\Feed\Reader\Extension\WellFormedWeb\Entry)[376]
          protected 'data' => 
            array (size=1)
              ...
          protected 'domDocument' => 
            object(DOMDocument)[36]
              ...
          protected 'entry' => 
            object(DOMElement)[266]
              ...
          protected 'entryKey' => int 0
          protected 'xpath' => 
            object(DOMXPath)[265]
              ...
          protected 'xpathPrefix' => string '//item[1]' (length=9)
      'Thread\Entry' => 
        object(Zend\Feed\Reader\Extension\Thread\Entry)[369]
          protected 'data' => 
            array (size=1)
              ...
          protected 'domDocument' => 
            object(DOMDocument)[36]
              ...
          protected 'entry' => 
            object(DOMElement)[266]
              ...
          protected 'entryKey' => int 0
          protected 'xpath' => 
            object(DOMXPath)[265]
              ...
          protected 'xpathPrefix' => string '//item[1]' (length=9)
      'Podcast\Entry' => 
        object(Zend\Feed\Reader\Extension\Podcast\Entry)[372]
          protected 'data' => 
            array (size=1)
              ...
          protected 'domDocument' => 
            object(DOMDocument)[36]
              ...
          protected 'entry' => 
            object(DOMElement)[266]
              ...
          protected 'entryKey' => int 0
          protected 'xpath' => 
            object(DOMXPath)[265]
              ...
          protected 'xpathPrefix' => string '//item[1]' (length=9)
      'DublinCore\Entry' => 
        object(Zend\Feed\Reader\Extension\DublinCore\Entry)[373]
          protected 'data' => 
            array (size=1)
              ...
          protected 'domDocument' => 
            object(DOMDocument)[36]
              ...
          protected 'entry' => 
            object(DOMElement)[266]
              ...
          protected 'entryKey' => int 0
          protected 'xpath' => 
            object(DOMXPath)[265]
              ...
          protected 'xpathPrefix' => string '//item[1]' (length=9)
      'Content\Entry' => 
        object(Zend\Feed\Reader\Extension\Content\Entry)[374]
          protected 'data' => 
            array (size=1)
              ...
          protected 'domDocument' => 
            object(DOMDocument)[36]
              ...
          protected 'entry' => 
            object(DOMElement)[266]
              ...
          protected 'entryKey' => int 0
          protected 'xpath' => 
            object(DOMXPath)[265]
              ...
          protected 'xpathPrefix' => string '//item[1]' (length=9)
      'Atom\Entry' => 
        object(Zend\Feed\Reader\Extension\Atom\Entry)[375]
          protected 'data' => 
            array (size=1)
              ...
          protected 'domDocument' => 
            object(DOMDocument)[36]
              ...
          protected 'entry' => 
            object(DOMElement)[266]
              ...
          protected 'entryKey' => int 0
          protected 'xpath' => 
            object(DOMXPath)[265]
              ...
          protected 'xpathPrefix' => string '//item[1]' (length=9)

I do not see any object here that gives access to title, content or link and so on.

So a bottom line is how do I see what all elements I have that I can pass to my Entity?

I hope my question is clear :)

eko_feed.yml ignored on Symfony 5.3, php 8

Specified feed 'paints' is not defined in your configuration.

In : config/packages/eko_feed.yml

eko_feed:
    feeds:
        paints:
            title:       'My latest things'
            description: 'Here are my latetst things'
            link:        'https://whatever.com'
            encoding:    'utf-8'
            author:      'Myself'

(Tried with eko_feed.yaml filename too)

In the controller

    #[Route('/feed.rss', name: 'app_feed')]
    public function feed()
    {
        $realisations = $this->getDoctrine()->getRepository('App:Peinture')->findAll();

        $feed = $this->feedManager->get('paints');
        $feed->addFromArray($realisations);

        return new Response($feed->render('rss')); // or 'atom'
    }

[Reader] Unable to enable crypto on TCP connection

Problem

Sometimes you can get an error when trying to request a feed using https.

 [Zend\Http\Client\Adapter\Exception\RuntimeException]                                       
  Unable to enable crypto on TCP connection domain.tld: make sure the "sslca  
  file" or "sslcapath" option are properly set for the environment.                           

  [ErrorException]                                                                          
  stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:  
  error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed    

Workaround

If you doesn't care about SSL certificates you can do this:

Using ...

use Zend\Feed\Reader\Reader as ZendFeedReader;
use Zend\Http\Client as ZendHttpClient;

Controller / Command:

        /** @var \Eko\FeedBundle\Feed\Reader $FeedReader */
        $FeedReader = $this->getContainer()->get('eko_feed.feed.reader');


        $httpClientOptions = array(
            'adapter'      => 'Zend\Http\Client\Adapter\Socket',
            'persistent'=>false,

            'sslverifypeer' => false,
            'sslallowselfsigned' => true,
            'sslusecontext'=>true,

            'ssl' => array(
            'verify_peer' => false,
            'allow_self_signed' => true,
            'capture_peer_cert' => true,
            ),

            'useragent' => 'Feed Reader',
        );

        ZendFeedReader::setHttpClient(new ZendHttpClient(null, $httpClientOptions));

        /** @var \Zend\Feed\Reader\Feed\FeedInterface $Feed */
        $Feed = $FeedReader->load('domain.tld/rss')->get();

Adding a list of objects

Hi,

I have a news article rss feed.

One news item has an array of multiple links, containing a title + url.
So I would like to add to my news item

<links>
<link>
<title>My title</title>
<url>My Url<url>
</link>
...
</links>

In my action I do this:
$news = $news_repo->getAllNews($locale);
$feedManager = $this->get('eko_feed.feed.manager');
$feed = $feedManager->get('news');
$feed->addFromArray($news);

I can add extra ItemFields and MediaItemFields.
But I don't know how I can add an array of multiple link objects containing title + url.

I have this in my entity:

   public function getLinkItems()
   {
    $items = array();


    foreach ($links as $link){
            $title = $link->getTitle();
            $url = $link->getUrl();

            $items[] =
               array(
                new ItemField('url', $url),
                new ItemField('title', $title),
            );
     }
        
    

    return $items;
}

And this in my action, but of course this is not correct:
$feed->addItemField( new GroupItemField('links', 'getLinkItems') );

Is there a way to do this?

Thanks.

Avoid using DomDocument

The way feed is generated is not good as the buffer is kept in memory and then flush to the client.

You should implement a streamed solution, so there is no buffer on the php side, and the TTFB will be better.

Translator

I need to serve a RSS feed of a multi-language site.
What about adding translator service?

Symfony 5 does not connect EkoFeedBundle

php 7.4.11, symfony 5.1.7, eko dev-master
EkoFeedBundle stopped working after symfony update.
Installed according to your manual https://github.com/eko/FeedBundle#installation

php bin/console eko:feed:dump

                                                              
  There are no commands defined in the "eko:feed" namespace.  
                                                              

2020-10-28T15:05:19+03:00 [info] User Deprecated: Creating Doctrine\ORM\Mapping\UnderscoreNamingStrategy without making it number aware is deprecated and will be removed in Doctrine ORM 3.0.
2020-10-28T15:05:19+03:00 [info] User Deprecated: Not passing a connection provider as the first constructor argument is deprecated

At run php bin/console debug:container and php bin/console debug:autowiring EkoFeedBundle not found, it feels like resources are not available

Use MediaItemField

Hello,

Since few days, I have this error :

mod_fcgid: stderr: PHP Catchable fatal error: Argument 1 passed to Eko\FeedBundle\Feed\Feed::addItemField() must be an instance of Eko\FeedBundle\Field\Item\ItemFieldInterface, instance of Eko\FeedBundle\Field\MediaItemField given

This is my controller :

public function feedAction()
{
    $annonces = $this->getDoctrine()->getRepository('LgmAnnonceBundle:Annonce')->derniereAnnonce();

    $feed = $this->get('eko_feed.feed.manager')->get('annonces');

    $feed->addFromArray($annonces);
    $feed->addItemField(new MediaItemField('getFeedMediaItem'));

    $response = new Response($feed->render('atom'));
    $response->headers->set('Content-Type', 'application/rss+xml');
    return $response;
}

I don't understand where is the source of the problem...

I have the same configuration of documentation. If someone can help me!

Thanks,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.