Pxxo_Widget_Atom

Ce widget permet de produire des flux de syndication au format Atom (à la RSS) et dans les formats JSON et JSON Padding

Par défaut, ce Widget affiche un lien qui permet d'accéder au flux lui-même.

Paramètres

Ce widget peut s'utiliser de deux manières :

  • Soit on donne en paramètres toutes les informations nécessaire à la production du flux
  • Soit on lui donne en paramètre le nom d'une 'callback' qui se chargera de produire le flux
Nom Type Valeur par défaut Description
id string - Identifies the feed using a universally unique and permanent URI
title string - Contains a human readable title for the feed
updated timestamp date() Indicates the last time the feed was modified in a significant way
authors array array(email ⇒ name) Names one author of the feed
content array array(type⇒ , value⇒) Contains or links to the complete content of the feed
entries array array( id⇒ title⇒ link⇒ published⇒ updated⇒ content⇒array(type⇒ value⇒) authors⇒ array(email ⇒ name) categories⇒ array(id ⇒ label) ) feed elements
feed_callback callback - Callback de production du flux
url string '?' préfixe pour l'URL du flux

Remarque

Si le paramètre feed_callback est fourni il inhibe les autres. Le flux au format JSON s'obtient en remplaçant atom par json dans l'URL produite par le widget. Le format JSONP s'obtient comme le format json mais en ajout un le paramètre &callback=quelquechose

Exemples

Méthode n°1 : On fournit toutes les informations dans les paramètres

 
require_once "Pxxo/Widget/Atom.php";
 
$params = array();
$params['id'] = 'test';
$params['title'] = 'Exemple';
$params['updated'] = time();
$params['authors'] = array(
    'truc@exemple.fr' => 'Monsieur Truc',
);
$params['content'] = array(
    'type' => 'text',
    'value' => 'Un flux de test',
);
$params['entries'] = array();
$params['entries'][] = array(
    'id' => '#1',
    'title' => 'Entry One',
    'link' => 'http://www.exemple.com/#1',
    'published' => time(),
    'updated' => time(),
    'content' => array(
        'type' => 'text',
        'value' => 'Contenu de l\'entrée Un',
    ),
    'authors' => array(
        'truc@exemple.fr' => 'Monsieur Truc',
        'bidule@exemple.fr' => 'Madame Bidule',
    ),
    'categories' => array(
        'cat1' => 'catégorie #1',
        'cat2' => 'catégorie #2',
    ),
);
$params['entries'][] = array(
    'id' => '#2',
    'title' => 'Entry Two',
    'link' => 'http://www.exemple.com/#2',
    'published' => time(),
    'updated' => time(),
    'content' => array(
        'type' => 'html',
        'value' => '<b>Contenu de l\'entrée Un</b>',
    ),
    'authors' => array(
        'truc@exemple.fr' => 'Monsieur Truc',
    ),
    'categories' => array(
        'cat1' => 'catégorie #1',
    ),
);
 
$o = new Pxxo_Widget_Atom($params);

Méthode n°2 : On délègue la production du flux à une callback

 
require_once "Pxxo/Widget/Atom.php";
 
function feed() {
    return array( 
            'version' => '1.0',
            'encoding' => 'UTF-8',
            'feed' => array(
                'xmlns' => 'http://www.w3.org/2005/Atom',
                'xmlns:openSearch' => 'http://a9.com/-/spec/opensearchrss/1.0/',
                'id' => array(
                    'value' => 'id du flux',
                ),
                'updated' => array(
                    'value' => date('Y-m-d\TH:i:s\Z'),
                ),
                'title' => array(
                    'type' => 'text',
                    'value' => 'Titre du flux',
                ),
                'link' => array(
                    array(
                        'rel' => 'self',
                        'type' => 'UTF-8',
                        'href' => 'http://www.exemple.fr',
                    ),
                ),
                'author' => array(
                    array(
                        'name' => array(
                            'value' => 'touv'
                        ),
                        'email' => array(
                            'value' => 'touv@exemple.fr'
                        ),
                    ),
                ),
                'generator' => array(
                    'version' => '1.0',
                    'uri' => 'http://www.pxxo.net/fr/doc/pxxo_widget_atom',
                    'value' => 'Pxxo_Widget_Atom',
                ),
                'openSearch:startIndex' => array( 
                    'value' => 1,
                ),
                'openSearch:itemsPerPage' => array(
                    'value' => 10,
                ),
                'openSearch:totalResults' => array(
                    'value' => 101,
                ),
                'openSearch:Query' => array(
                    'role' => null,
                    'searchTerms' => 'q',
                    'value' => 'truc',
                    'startPage' => 1,
                ),
                'content' => array(
                    'type' => 'text',
                    'value' => 'Résulat',
                ),
                'entry' => array(
                    array(
                        'id' => array(
                            'value' => '#1',
                        ),
                        'published' => array(
                            'value' =>  date('Y-m-d\TH:i:s\Z'),
                        ),
                        'updated' =>array(
                            'value' =>  date('Y-m-d\TH:i:s\Z'),
                        ),
                        'category'=> array(
                            array(
                                'scheme' => 'http://www.exemple.fr/tags/t1',
                                'term' => 't1',
                            ),
                        ),
                        'title' => array(
                            'type' => 'text',
                            'value' => 'Title1',
                        ),
                        'content' => array(
                            'type' => 'text',
                            'value' => 'Content1',
                        ),
                        'link' => array(
                            array(
                                'type' => 'text/html',
                                'href' => 'http://www.exemple.fr/1',
                            ),
                        ),
                        'author' => array(
                            array(
                                'name' => array('value' => null),
                                'email' => array('value' => null),
                            ),
                        ),
                    ),
                    array(
                        'id' => array(
                            'value' => '#1',
                        ),
                        'published' => array(
                            'value' =>  date('Y-m-d\TH:i:s\Z'),
                        ),
                        'updated' =>array(
                            'value' =>  date('Y-m-d\TH:i:s\Z'),
                        ),
                        'category'=> array(
                            array(
                                'scheme' => 'http://www.exemple.fr/tags/t1',
                                'term' => 't1',
                            ),
                        ),
                        'title' => array(
                            'type' => 'text',
                            'value' => 'Title2',
                        ),
                        'content' => array(
                            'type' => 'text',
                            'value' => 'Content2',
                        ),
                        'link' => array(
                            array(
                                'type' => 'text/html',
                                'href' => 'http://www.exemple.fr/2',
                            ),
                        ),
                        'author' => array(
                            array(
                                'name' => array('value' => null),
                                'email' => array('value' => null),
                            ),
                        ),
                    ),
                ),
            ),
        );
}
 
 
$params = array();
$params['ClassID'] = 'alt';
$params['feed_callback'] = 'feed';
 
$o = new Pxxo_Widget_Atom($params);
 
fr/doc/pxxo_widget_atom.txt · Dernière modification: 2009/09/08 14:56 par parmentf
 
 

©2003-2010 Pxxo

Partenaires : INIST-CNRS | Sourcesup | Web2.0 chat server | Micropolia | Jeux gratuits | Areno