Show
Ignore:
Timestamp:
04/17/08 07:14:54 (20 months ago)
Author:
fumiakiy
Message:

Implemented comments retrieval via Atom PP. BugId:79334

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/release-35/lib/MT/Atom.pm

    r1823 r1947  
    7272    my ($host) = $blog->site_url =~ m!^https?://([^/:]+)(:\d+)?/!; 
    7373 
     74    unless ( $entry->atom_id ) { 
     75        # atom_id is not there - probably because 
     76        # the entry is in HOLD state 
     77        $entry->atom_id($entry->make_atom_id()); 
     78        # call update directly because MT::Entry::save 
     79        # is overkill for the purpose. 
     80        $entry->update if $entry->atom_id(); 
     81    } 
     82 
    7483    $atom->id($entry->atom_id); 
    7584    #$atom->draft('true') if $entry->status != MT::Entry::RELEASE(); 
     
    94103}  
    95104 
     105sub new_with_comment { 
     106    my $class = shift; 
     107    my ( $comment, %param ) = @_; 
     108    my $rfc_compat = $param{Version} && $param{Version} eq '1'; 
     109 
     110    my $entry = $comment->entry; 
     111    return unless $entry; 
     112    my $blog = $comment->blog; 
     113    return unless $blog; 
     114 
     115    my $atom = $class->new(%param); 
     116    $atom->title(encode_text($entry->title, undef, 'utf-8')); 
     117    $atom->content(encode_text($comment->text, undef, 'utf-8')); 
     118    # Old Atom API gets application/xhtml+xml for compatibility -- but why 
     119    # do we say it's that when all we're guaranteed is it's an opaque blob 
     120    # of text? So use 'html' for new RFC compatible output. 
     121    # XML::Atom::Content intelligently determines content-type for rfc compat. 
     122    unless ( $rfc_compat ) { 
     123        $atom->content->type('application/xhtml+xml'); 
     124    } 
     125 
     126    my $atom_author = new XML::Atom::Person(%param); 
     127    $atom_author->name(encode_text($comment->author, undef, 'utf-8')); 
     128    $atom_author->email($comment->email) if $comment->email; 
     129    my $author_url_field = $rfc_compat ? 'uri' : 'url'; 
     130    $atom_author->$author_url_field($comment->url) if $comment->url; 
     131    $atom->author($atom_author); 
     132 
     133    my $co = _create_issued($comment->created_on, $blog); 
     134    $atom->issued($co); 
     135    my $upd = $comment->modified_on; 
     136    if ( $upd ) { 
     137        $atom->updated( _create_issued( $upd, $blog ) ); 
     138    } 
     139    else { 
     140        $atom->updated( $co ); 
     141    } 
     142    $atom->add_link({ rel => 'alternate', type => 'text/html', 
     143                      href => $entry->archive_url . '#comment-' . $comment->id }); 
     144    my ($host) = $blog->site_url =~ m!^https?://([^/:]+)(:\d+)?/!; 
     145 
     146    $atom->id($entry->atom_id . '/' . $comment->id); 
     147    $atom; 
     148} 
     149 
    961501; 
    97151__END__