Date de publication: le lundi 31 décembre 2007 à 04h26
Dernière modification: par Pascal BOYER le jeudi 21 octobre 2010 à 23h06
« Article précédent: Importer un flux RSS : 1
» Article suivant: Importer un flux RSS : problème de publication lié au workflow
2 Importer un flux RSS
The sections below describe how to achieve RSS Import using EZ Publish 3.9.0, without using any extra RSS-related extensions.
Cet article explique comment importer un flux RSS avec eZ Publish 3.9.0 sans avoir recours à aucune extension externe supplémentaire.
2.1 Identifier le flux RSS à importer
Find the URL of the RSS feed you want to import into EZ Publish.
Rechercher l'URI du flux RSS que vous souhaitez importer dans eZ Publish.
This document uses a breaking news feed from the Australian Broadcasting Corporation's site.
Pour illustrer mon propos, ce document illustre l'exemple d'un flux de news en provenance du site ABC (
ABC
).
The URL of this RSS feed is:
L'URI de ce flux RSS est:
http://abc.net.au/news/syndicate/breakingrss.xml
Examining this URL in a browser will show the contents of this XML file, for example see below.
En examinant, dans le navigateur IE, l'affichage qu'engendre cet URI, on peut observer le code XML du fichier breakingrss.xml, comme le montre l'exemple ci-dessous:
The broad process for RSS import involves:
Le processus d'importation de flux RSS implique:
-
Configuring EZ Publish to run a php "cronjob" script so that EZ Publish can automatically collect RSS information from an external website URL;
de configurer eZ Publish afin qu'il exécute périodiquement un script PHP lui permettant de collecter automatiquement les informations RSS depuis l'URI du site web extérieur,
-
Creating a class of EZ Publish objects to receive and display the RSS items;
de créer une classe d'objet pour recevoir et afficher les éléments RSS,
-
Configuring the RSS functions of EZ Publish to automatically generate these RSS item objects from the collected RSS information;
de configurer les fonctions RSS de eZ Publish pour générer automatiquement ces objets-éléments RSS à partir des informations RSS collectées,
-
Configuring EZ Publish permissions so that users can view the RSS item objects; and finally,
de configurer les permissions de eZ Publish pour que les utilisateurs puissent voir les éléments RSS,
-
Customising views for the RSS item objects to display them effectively.
et enfin, de personnaliser les vues des éléments RSS afin qu'ils s'affichent vraiment.
2.2 Configurer les tâches planifiées
RSS functions depend on an EZ Publish site having cronjobs enabled. This involves a server-level "cronjob" that periodically runs an EZ Publish php script. For example, in a Cpanel administers hosting environment, a cronjob like the following:
Les fonctions RSS ne peuvent fonctionner que sur un site eZ Publish où les tâches planifiées sont actives. Cela implique, côté serveur, une tâche cron exécutant périodiquement un script PHP. Par exemple, à partir de l'interface d'administration CPanel, une tâche planifiée comme celle présentée ci-après:
The full text of the "Command to run" used here is:
Le texte complet du champ Commande to run est:
"cd /home/yoursite/www; /usr/local/bin/php runcronjobs.php -q 2>&1"
However this will change with hosting, server and installation arrangements. Refer to EZ Publish documentation/forums for more information.
Cependant, cette interface est différente suivant l'hébergeur, le serveur et la configuration de l'installation. Référez-vous à la documentation (ou aux forums) de eZ Publish pour plus d'informations.
NOTE: it will be helpful not to run your RSS-related cronjobs too frequently... this places unnecessary load on your hosting service / server and on the RSS feed provider. Check the site you are sourcing your RSS feed from -- they might have some information on how frequently they update their RSS feeds.
NOTE: n'exécutez pas trop fréquemment votre tâche cron RSS... cela engendre inutilement une charge sur le service/serveur d'hébergement et sur la machine distante qui fournit le flux RSS. Contrôlez les sites à partir desquels vous récupérez les sources RSS -- ils devraient conternir quelques informations sur la fréquence de mise à jour de leurs sources RSS.
2.3 Créer une classe pour les éléments RSS
Examine the RSS/XML file you have chosen in your web browser. Some elements will be irrelevant, but others will represent the material you want to incorporate into your EZ Publish site. For example, examining the ABC Breaking News RSS Feed, it can be seen that there is "Channel" information followed by the "item" elements that might be useful.
Examinez, dans votre navigateur, le fichier RSS/XML que vous avez choisi. Alors que certains éléments sont sans grand intérêt pour vous, d'autres représentent les informations que vous souhaitez inclure à votre site eZ Publish. En examinant, par exemple, le flux RSS du site ABC, on peut voir l'information Channel suivie par plusieurs éléments <item> :
(Note that this image does not show a complete file).
Notez que l'image ci-dessus n'est qu'une vue partielle du fichier.
The following steps explain how to create an object for capturing these item elements.
Les étapes décrites ci-après expliquent comment créer un objet pour rapatrier les éléments item.
2.3.1 Se connecter à l'interface d'administration
2.3.2 Créer une nouvelle classe
To do this, navigate to Setup / Classes, and then select the "Content" class group (as shown below).
Pour cela, cliquez sur l'onglet Administration puis sur le lien Classes dans le menu gauche. Cliquez ensuite sur le lien Content dans le cadre Groupes de classes, comme indiqué par l'image suivante:
This will then display a list of items in the "Content" class group. Scroll down to the bottom of this list and click on the "New Class" button.
Cela affichera la liste des classes du groupe de classes Content. Au bas de cette liste, cliquez sur le bouton Nouvelle classe:
2.3.3 Ajouter les attributs de la nouvelle classe
Give the new class a name relevant to your RSS feed, and then start to create attributes that match the RSS feed information that you want to import into EZ Publish.
Donnez à votre nouvelle classe un nom en rapport avec votre flus RSS puis ajoutez les attributs correspondant aux informations que vous voulez importer dans votre site grâce au flux RSS.
For example, to import the title, description, link and pubdate elements shown in the XML file (see below):
Par exemple, pour importer le titre ( <title>), la description ( <description>), le lien ( <link>) et la date de publication ( <pubDate>) des éléments contenus par le fichier XML (voir ci-dessous):
...we need to create object attributes equivalent to those elements. For example:
...nous devons créer les attributs d'objets équivalents à ces éléments. Voici, par exemple, la classe et ses attributs qui va nous permettre d'importer les items du fichier breakingrss.xml:
When finished creating the attributed needed, store the object.
Lorsque vous avez fini de créer les attributs nécessaires, enregistrez la classe.
2.3.4 Créer un emplacement pour les objets RSS
Navigate to the "Content Structure" area of the EZ Publish administration system, and then create a new Folder object in a location useful for your site. The RSS objects will be created within/underneath this folder. For example:
Cliquez sur l'onglet Contenus de l'interface d'administration puis créez un nouveau dossier (avec le classe folder par exemple) où vous le souhaitez dans l'arborescence de votre site. Les objets RSS seront créés sous ce dossier. Par exemple:
2.3.5 Paramétrer la fonction RSS de eZ Publish
Return to the Setup area of the EZ Publish administration site and select the RSS item from the Setup menu.
Retournez dans l'onglet Administration de l'interface d'administration et cliquez sur le lien Syndication du menu gauche Administration:
A page like the following will be displayed. Click on "New Import".
Sur la page qui s'affiche alors (ci-dessous) cliquez sur le bouton Nouvelle importation:
The following page will be displayed.
La page suivante sera affichée:
Enter the name of the import, and the source URL for the RSS feed (ie the one you identified in step 2.1, above). Then click the "Update" button.
Saisissez le nom de l'importation ainsi que l'URI source du flux RSS (celui spécifié au paragraphe 2.1). Cliquez ensuite sur le bouton Update.
The following page will then be displayed.
Le bouton Update engendre l'affichage de cette page:
Click the "Browse" button adjacent to the Destination Path text box, and then find the folder you created in step 2.3.4.
Cliquez alors sur le bouton Parcourir (image ci-dessous) adjacent au champ Chemin de destination et recherchez puis sélectionner le dossier ABC Australia -- Breaking News créé au paragraphe 2.3.4
Then, in the Class drop-down box, select the Class you created in step 2.3.3, and then click the "set" button.
Ensuite, dans la liste déroulante Classe (voir ci-dessous), sélectionnez la classe que vous avez créé au paragraphe 2.3.3 et validez avec le bouton Assigner.
With this done, a new section will appear at the bottom of the page, as shown below.
S'affiche alors deux nouvellex sections au bas de la page, comme l'illustre la capture d'écran ci-dessous:
The Title, Description, Link and Publication Date relate to the attributes created for the ABC RSS Item created in step 2.3.3.
Les menus déroulants Title, Description, Link et Publication date sont liés aux attributs ajoutés à la classe ABC RSS Item créée au paragraphe 2.3.3.
The task now is to select, from the drop boxes beside each of the attributes, the field from the XML file that relates to the data that should be loaded into that class-attribute. For example:
A présent, il faut, dans chacun des menus déroulants, sélectionner le champ du fichier XML qui correspond à l'attribut considéré ( Title, Description, Link ou Publication date). La valeur du champ XML choisi sera, par la suite, automatiquement importée dans l'attribut. Voici ce que l'on doit avoir dans le cas de notre exemple:
The other object attributes listed relate to publish / modification dates, which can be used/ignored as appropriate.
Les deux autres attributs d'objets ( Published et Modified) sont liés aux dates de publication et de modification et peuvent être utilisés ou ignorés comme bon nous semble.
The next step is to check the Active box to set the RSS import to being active, and then click "OK" to complete the work on the RSS import.
L'étape suivante consiste à rendre Actif l'importation de ce flux RSS et à terminer en validant l'ensemble de ses paramètres avec le bouton OK.
The RSS Import will then be listed as shown below.
La nouvelle importation de flux RSS apparaît alors dans la liste présentée par le cadre Imports RSS:
2.3.6 Résultat final
A présent, on lance manuellement l'exécution du script runcronjobs.php pour tester l'importation du flux RSS:
./runcronjobs.php
Running cronjobs/unpublish.php Running cronjobs/rssimport.php RSSImport ABC Breaking News: Starting. RSSImport ABC Breaking News: Object created; Liberals worse off with Costello as leader: Newspoll RSSImport ABC Breaking News: Object created; Rivers still rising in UK flood crisis RSSImport ABC Breaking News: Object created; Search resumes for missing toddler RSSImport ABC Breaking News: Object created; Aust 'influenced E Timor independence vote' RSSImport ABC Breaking News: Object created; Caution urged in drug addicts adoption scheme RSSImport ABC Breaking News: Object created; Brown refuses to rule out military action against Iran RSSImport ABC Breaking News: Object created; Taliban confirms 1 German, 4 Afghan hostages still alive RSSImport ABC Breaking News: Object created; Former Indon minister jailed over Megawati slush fund RSSImport ABC Breaking News: Object created; Last Afghan king dies RSSImport ABC Breaking News: Object created; Stranded Jetstar passengers due home today RSSImport ABC Breaking News: Object created; Downer denies Tampa 'election stunt' RSSImport ABC Breaking News: Object created; Convicted sex offender on the run RSSImport ABC Breaking News: Object created; Black Hawk 'couldn't speed up rotors before crash' RSSImport ABC Breaking News: Object created; Buckingham Palace hosts caravan club party RSSImport ABC Breaking News: Object created; Militants vow 'gift of death' for Pakistani troops RSSImport ABC Breaking News: End. 15 objects added Running cronjobs/indexcontent.php Starting processing pending search engine modifications Done Running cronjobs/hide.php Running cronjobs/subtreeexpirycleanup.php Running cronjobs/internal_drafts_cleanup.php Cleaning up internal drafts... Cleaned up 0 internal drafts
After the above steps, and with a cronjob having run, the Folder created in step 2.3.3 will now contain ABC RSS Item objects. For example:
Après avoir suivi toutes les étapes ci-dessus et après avoir exécuté le script runcronjobs.php, le dossier créé au paragraphe 2.3.4 contiendra les éléments RSS suivants:
2.4 Etapes supplémentaires
These are not documented or tested here, but the next steps include:
Elles ne sont pas documentées et testées ici, mais elles incluent:
-
Creating permission for users to view the ABC RSS Item objects (or your version of them).
La création des permissions pour que les utilisateurs puissent voir les éléments RSS,
-
Creating custom templates to display the items.
La création d'un template personnalisé pour afficher les éléments RSS.
[End of Document]














