line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Kwiki::Trackback; |
2
|
1
|
|
|
1
|
|
31079
|
use Kwiki::Plugin '-Base'; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
use Kwiki::Installer '-base'; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
const class_id => 'trackback'; |
6
|
|
|
|
|
|
|
const class_title => 'Trackback'; |
7
|
|
|
|
|
|
|
const cgi_class => 'Kwiki::Trackback::CGI'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub register { |
12
|
|
|
|
|
|
|
my $registry = shift; |
13
|
|
|
|
|
|
|
$registry->add(action => 'trackback_ping'); |
14
|
|
|
|
|
|
|
$registry->add(widget => 'trackback_pings', |
15
|
|
|
|
|
|
|
template => 'trackbacks.html', |
16
|
|
|
|
|
|
|
show_for => 'display', |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
$registry->add(status => 'trackback_info', |
19
|
|
|
|
|
|
|
template => 'trackback_info.html', |
20
|
|
|
|
|
|
|
show_for => 'display', |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
super; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
## minimize extent of cgi processing ##### |
27
|
|
|
|
|
|
|
# receive a ping |
28
|
|
|
|
|
|
|
sub trackback_ping { |
29
|
|
|
|
|
|
|
my $page_id = $self->cgi->trackback_id; |
30
|
|
|
|
|
|
|
my $content = $self->ping_content; |
31
|
|
|
|
|
|
|
$self->trackback_ping_receive($page_id, $content); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
# |
34
|
|
|
|
|
|
|
# extra ping contents |
35
|
|
|
|
|
|
|
sub ping_content { |
36
|
|
|
|
|
|
|
+{ url => $self->cgi->url, |
37
|
|
|
|
|
|
|
title => $self->cgi->title, |
38
|
|
|
|
|
|
|
blog_name => $self->cgi->blog_name, |
39
|
|
|
|
|
|
|
excerpt => substr($self->cgi->excerpt, 0, 100), |
40
|
|
|
|
|
|
|
}; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
# |
43
|
|
|
|
|
|
|
########################################## |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub trackback_ping_receive { |
47
|
|
|
|
|
|
|
my $page_id = shift; |
48
|
|
|
|
|
|
|
my $content = shift; |
49
|
|
|
|
|
|
|
require Net::Trackback::Message; |
50
|
|
|
|
|
|
|
my $msg = Net::Trackback::Message->new(); |
51
|
|
|
|
|
|
|
# don't trackback for just anybody |
52
|
|
|
|
|
|
|
if ($self->hub->pages->new_from_name($page_id)->exists) { |
53
|
|
|
|
|
|
|
$self->store_ping($page_id, $content) |
54
|
|
|
|
|
|
|
? $msg->code(0) |
55
|
|
|
|
|
|
|
: $msg->code(1); |
56
|
|
|
|
|
|
|
} else { |
57
|
|
|
|
|
|
|
$msg->code(1); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
$msg->to_xml; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub store_ping { |
63
|
|
|
|
|
|
|
my $id = shift; |
64
|
|
|
|
|
|
|
my $content = shift; |
65
|
|
|
|
|
|
|
require Storable; |
66
|
|
|
|
|
|
|
Storable::lock_store( |
67
|
|
|
|
|
|
|
$content, |
68
|
|
|
|
|
|
|
$self->path_to_store($id) . '/' . $self->md5_name($id, $content), |
69
|
|
|
|
|
|
|
); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub md5_name { |
73
|
|
|
|
|
|
|
require Digest::MD5; |
74
|
|
|
|
|
|
|
use bytes; |
75
|
|
|
|
|
|
|
my $id = shift; |
76
|
|
|
|
|
|
|
my $content = shift; |
77
|
|
|
|
|
|
|
Digest::MD5::md5_hex($id . $content->{url} . time); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub path_to_store { |
82
|
|
|
|
|
|
|
my $id = shift; |
83
|
|
|
|
|
|
|
my $dir = $self->plugin_directory . '/' . $id; |
84
|
|
|
|
|
|
|
mkdir($dir); # XXX better to skip the stat or not? |
85
|
|
|
|
|
|
|
return $dir; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# return a list of trackbacks for presentation |
90
|
|
|
|
|
|
|
sub trackbacks { |
91
|
|
|
|
|
|
|
my $page_id = $self->hub->pages->current->id; |
92
|
|
|
|
|
|
|
[ |
93
|
|
|
|
|
|
|
map{ Storable::lock_retrieve($_) } |
94
|
|
|
|
|
|
|
sort { $a->mtime <=> $b->mtime } |
95
|
|
|
|
|
|
|
io($self->path_to_store($page_id))->all_files |
96
|
|
|
|
|
|
|
]; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub identifier { |
100
|
|
|
|
|
|
|
my $url = CGI::url(-full => 1); |
101
|
|
|
|
|
|
|
$url . '?' . $self->hub->pages->current->uri; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub ping_url { |
105
|
|
|
|
|
|
|
my $url = CGI::url(-full => 1); |
106
|
|
|
|
|
|
|
$url . '?action=trackback_ping;trackback_id=' . |
107
|
|
|
|
|
|
|
$self->hub->pages->current->uri; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
package Kwiki::Trackback::CGI; |
111
|
|
|
|
|
|
|
use base 'Kwiki::CGI'; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
cgi 'trackback_id'; |
114
|
|
|
|
|
|
|
cgi 'trackback_ping'; |
115
|
|
|
|
|
|
|
cgi 'url'; |
116
|
|
|
|
|
|
|
cgi 'title'; |
117
|
|
|
|
|
|
|
cgi 'excerpt'; |
118
|
|
|
|
|
|
|
cgi 'blog_name'; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
package Kwiki::Trackback; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
__DATA__ |