2009-12-11 16 views
15

J'ai besoin d'un générateur de flux RSS; devrais-je utiliser une classe ou devrais-je générer le flux moi-même?Générateur de flux RSS décent pour PHP

Si je devais générer moi-même, où est un bon endroit pour obtenir des spécifications complètes des normes?

Sinon, y at-il de bonnes classes pour le faire et le faire rapidement et bien faire?

+0

Je viens de créer un RSS Writer class qui est une carte simple à spécification rss: https://github.com/lingtalfi/RssUtil/tree/master/RssWriter – ling

Répondre

19

PHP Universal Feed Generator (supports RSS 1.0, RSS 2.0 and ATOM)

Features:

  • Generates RSS 1.0, RSS 2.0 and ATOM 1.0 feeds
  • All feeds are are validated by feed validator.
  • Supports all possible feed elements.
  • Simple and easy to define channel and feed items
  • Implements appropriate namespaces for different versions.
  • Automatically converts date formats.
  • Generates UUID for ATOM feeds.
  • Enables usage of subtags and attributes. (example: image and encloser tags)
  • Completely Object oriented in PHP5 class structure.
  • Handles CDATA encoding for required tags.
  • Nearly same code for generating all kinds of feed

Examples

+0

@Perter Lind: Set Image ajoutant la source à l'étiquette de l'image, mais le titre et le lien n'est pas ajouté à la balise d'image .. urgent s'il vous plaît répondre .. –

+0

fonction publique setImage ($ title, $ link, $ url) –

+0

Ce n'est pas le réglage du lien .. Il est seulement l'image sans lien dans ce –

2

Cette page a une réunion du générateur décent de spécifications 1.0/2.0/ATOM de sorte que vous pouvez soit l'utiliser (PHP5) ou tout simplement avoir une idée générale de ce qui est nécessaire:

Php FeedWriter

Les notes d'utilisation à le fond est assez détaillé et vous n'avez même pas à télécharger pour voir la source.

+0

Salut cballou, votre lien ne fonctionne pas ... –

+0

@Antony - Correction du lien. pas tout à fait sûr de ce qui s'est passé plus tôt, mais je me suis juste réveillé :) –

+0

Set Image ajoutant la source à l'étiquette de l'image, mais le titre et le lien n'est pas ajouté à la balise image .. urgent s'il vous plaît répondre .. –

4

Il y aura bientôt un composant pour Zend Framework appelé Zend_Feed_Writer qui semble assez intéressant. Voici un extrait d'un flux de l'un des développeurs (peut-être le?) De ce composant, Padráic Brady (link to the blog post). Il dit qu'il est actuellement dans le Zend Framework Incubateur, mais qu'une première version officielle devrait être prêt d'ici la fin du week-end:

Zend_Feed_Writer

The new kid on the block, to be added in Zend Framework 1.10, is Zend_Feed_Writer. A bit like the older Zend_Feed_Builder classes, its purpose is to generate Atom 1.0 and RSS 2.0 feeds. The difference is that, like its sibling Zend_Feed_Reader, it is standards aware and operates entirely using PHP's DOM.

Why another feed generation component? The problem is somewhat similar to the one that Zend_Feed_Reader solved. Generating an RSS and Atom feed is far more involved than sticking a bunch of elements together - each standard has its quirks, its unique features, and its own set of best practices outside of the standards. Using Zend_Feed_Builder, you relied on two things - repetition and validation. Moving away from its core focus required more work, even to the extent of subclassing, and you were always at the mercy of misinterpreting a standard.

Zend_Feed_Writer builds on the simple API of Zend_Feed_Reader (using setters rather than getters) and the concept of having the component understand the standards (so you don't have to). The component is split across two class types - a base data container to store feed data and ensure it conforms to expected formats, and a renderer to actually generate the feeds and provide feedback on standards adherence. For example, in Atom 1.0 the omission of a title will generate an exception - a title is an obligatory element under the Atom 1.0 standard. While this could be interpreted as a nuisance, the fact is that an invalid Atom 1.0 feed is worse than useless. Better you are irritated now, than later when an online validator calls you rude names :-).

The net result of this approach is that you focus on the data, and let Zend_Feed_Writer worry about what elements and attributes to use. It should, in theory (always a grand thing), be impossible for Zend_Feed_Writer to produce an invalid feed.

Of course, we also throw in the concept of Extensions, as with Zend_Feed_Reader, allowing you to add support for RSS and Atom extensions more dynamically without the need for subclassing or API arm twisting.

If you go looking for Zend_Feed_Writer, it's currently in chunks in the Incubator. I should have it entirely integrated and functional over the weekend. You can however give it a shot for writing Atom 1.0 feeds so long as you stick to the core elements (i.e. most blog feeds). RSS 2.0 support is the last piece I need to complete in full.

+0

Zend_Feed_Writer existe déjà: http://framework.zend.com/manual/fr/zend.feed.writer.html – feeela

+0

Définir l'image en ajoutant la source à la balise d'image mais le titre et le lien ne sont pas ajoutés à la balise d'image .. urgent s'il vous plaît répondre bientôt .. –