package Kwiki::Trackback; use Kwiki::Plugin '-Base'; use Kwiki::Installer '-base'; const class_id => 'trackback'; const class_title => 'Trackback'; const cgi_class => 'Kwiki::Trackback::CGI'; our $VERSION = '0.01'; sub register { my $registry = shift; $registry->add(action => 'trackback_ping'); $registry->add(widget => 'trackback_pings', template => 'trackbacks.html', show_for => 'display', ); $registry->add(status => 'trackback_info', template => 'trackback_info.html', show_for => 'display', ); super; } ## minimize extent of cgi processing ##### # receive a ping sub trackback_ping { my $page_id = $self->cgi->trackback_id; my $content = $self->ping_content; $self->trackback_ping_receive($page_id, $content); } # # extra ping contents sub ping_content { +{ url => $self->cgi->url, title => $self->cgi->title, blog_name => $self->cgi->blog_name, excerpt => substr($self->cgi->excerpt, 0, 100), }; } # ########################################## sub trackback_ping_receive { my $page_id = shift; my $content = shift; require Net::Trackback::Message; my $msg = Net::Trackback::Message->new(); # don't trackback for just anybody if ($self->hub->pages->new_from_name($page_id)->exists) { $self->store_ping($page_id, $content) ? $msg->code(0) : $msg->code(1); } else { $msg->code(1); } $msg->to_xml; } sub store_ping { my $id = shift; my $content = shift; require Storable; Storable::lock_store( $content, $self->path_to_store($id) . '/' . $self->md5_name($id, $content), ); } sub md5_name { require Digest::MD5; use bytes; my $id = shift; my $content = shift; Digest::MD5::md5_hex($id . $content->{url} . time); } sub path_to_store { my $id = shift; my $dir = $self->plugin_directory . '/' . $id; mkdir($dir); # XXX better to skip the stat or not? return $dir; } # return a list of trackbacks for presentation sub trackbacks { my $page_id = $self->hub->pages->current->id; [ map{ Storable::lock_retrieve($_) } sort { $a->mtime <=> $b->mtime } io($self->path_to_store($page_id))->all_files ]; } sub identifier { my $url = CGI::url(-full => 1); $url . '?' . $self->hub->pages->current->uri; } sub ping_url { my $url = CGI::url(-full => 1); $url . '?action=trackback_ping;trackback_id=' . $self->hub->pages->current->uri; } package Kwiki::Trackback::CGI; use base 'Kwiki::CGI'; cgi 'trackback_id'; cgi 'trackback_ping'; cgi 'url'; cgi 'title'; cgi 'excerpt'; cgi 'blog_name'; package Kwiki::Trackback; __DATA__ =head1 NAME Kwiki::Trackback - Provide a trackback server within Kwiki and a place to display those trackbacks. =head1 DESCRIPTION Trackback is a protocol developed by Six Apart to facillitate conversation amongst disparate content sources. It was first used between blogs, but is useful for proactively telling any piece of content that something out there is talking about it. You can see Kwiki::Trackback in action at L =head1 AUTHORS Chris Dent, =head1 SEE ALSO L =head1 COPYRIGHT AND LICENSE Copyright (C) 2005, Chris Dent This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut __template/tt2/trackbacks.html__
Trackback URL [% trackbacks = hub.trackback.trackbacks %] [% IF trackbacks.size %]

TRACKBACKS

[% FOREACH link = trackbacks %]
[% link.excerpt %]
[% END %] [% END %]
__template/tt2/trackback_info.html__