Daizu

 view release on metacpan or  search on metacpan

lib/Daizu/Feed.pm  view on Meta::CPAN

C<content:encoded> element.  The C<description> element will still carry
the description or extract as described above.

=item content

The full content of the article is included in the feed, even if the article
has page breaks.  Any C<daizu:fold> elements or C<daizu:page> elements in
the article's content will be ignored (and will not appear in the feed).

For Atom feeds: the article content is provided as raw XHTML in an
C<atom:content> element.

For RSS feeds: the article content is provided in a C<content:encoded>
element.  The C<description> element will still carry the description or
extract as described above.

=back

=head1 METHODS

=over

=item Daizu::Feed-E<gt>new($cms, $file, $url, $format, $type)

Return a new Daizu::Feed object and set up the basic outline of
the XML feed.  C<$file> should be a L<Daizu::File> object representing
the 'homepage' of this feed.  C<$url> should be a string containing the URL
of the feed file itself once it has been output.  C<$format> should be
either 'atom' (for S<Atom 1.0> feeds) or 'rss2' (for S<RSS 2.0> feeds).
C<$type> can be one of the feed types L<mentioned above|/FEED TYPES>
('description', 'snippet', or 'content').

=cut

sub new
{
    my ($class, $cms, $file, $url, $format, $type) = @_;
    croak "unknown feed format '$format'"
        unless $format eq 'atom' || $format eq 'rss2';
    croak "unknown feed type '$type'"
        unless $type eq 'content' || $type eq 'snippet' ||
               $type eq 'description';

    my $feed_title = $file->title;
    croak "no title available for feed, or any of its ancestors"
        unless defined $feed_title;

    my $homepage_url = $file->generator->base_url($file);
    croak "blog homepage doesn't seem to have a URL"
        unless defined $homepage_url;

    my $doc = XML::LibXML::Document->new('1.0', 'UTF-8');
    my $feed;
    my $entry_parent;
    my $updated_elem;
    if ($format eq 'atom') {    # Atom 1.0
        $feed = $doc->createElementNS($ATOM_NS, 'feed');
        $entry_parent = $feed;

        add_xml_elem($feed, title => $feed_title);
        # TODO - description should be decoded from utf-8 at some point
        add_xml_elem($feed, subtitle => $file->{description})
            if defined $file->{description};
        add_xml_elem($feed, id => $file->guid_uri);
        add_xml_elem($feed, generator => 'Daizu CMS',
            uri => 'http://www.daizucms.org/',
            version => $Daizu::VERSION,
        );
        add_xml_elem($feed, link => undef,
            rel => 'self',
            href => $url,
            type => 'application/atom+xml',
        );
        add_xml_elem($feed, link => undef,
            href => $homepage_url,
            type => 'text/html',
        );
        $updated_elem = add_xml_elem($feed, updated => undef);
    }
    else {                      # RSS 2.0
        $feed = XML::LibXML::Element->new('rss');
        $feed->setAttribute(version => '2.0');
        $feed->setNamespace($ATOM_NS, 'atom', 0);
        $feed->setNamespace('http://purl.org/rss/1.0/modules/content/',
                            'content', 0);
        $feed->setNamespace('http://purl.org/dc/elements/1.1/', 'dc', 0);

        my $channel = XML::LibXML::Element->new('channel');
        $feed->appendChild($channel);
        $entry_parent = $channel;

        add_xml_elem($channel, title => $feed_title);
        add_xml_elem($channel, link => "$homepage_url");
        add_xml_elem($channel, description =>
            defined $file->{description} ? $file->{description} : '');

        add_xml_elem($channel, generator => "http://www.daizucms.org/?v=$Daizu::VERSION");
        $updated_elem = add_xml_elem($channel, lastBuildDate => undef);

        # For the Universal Subscription Mechanism:
        #    http://www.kbcafe.com/rss/usm.html
        add_xml_elem($channel, 'atom:link' => undef,
            rel => 'self',
            href => $url,
            type => 'application/rss+xml',
            title => $feed_title,
        );
    }

    $doc->setDocumentElement($feed);

    return bless {
        cms => $cms,
        doc => $doc,
        feed_elem => $feed,
        entry_parent => $entry_parent,
        file => $file,
        format => $format,
        type => $type,
        feed_updated_elem => $updated_elem,
    }, $class;



( run in 0.943 second using v1.01-cache-2.11-cpan-600a1bdf6e4 )