line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Kwiki::GuestBook; |
2
|
1
|
|
|
1
|
|
33517
|
use Kwiki::Plugin -Base; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
use mixin 'Kwiki::Installer'; |
4
|
|
|
|
|
|
|
our $VERSION = '0.13'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
const class_id => 'guest_book'; |
7
|
|
|
|
|
|
|
const css_file => 'css/guest_book.css'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub register { |
10
|
|
|
|
|
|
|
my $registry = shift; |
11
|
|
|
|
|
|
|
$registry->add(action => 'guest_book'); |
12
|
|
|
|
|
|
|
$registry->add(prerequisite => 'user_name'); |
13
|
|
|
|
|
|
|
$registry->add(hook => 'user_name:check_user_name', post => 'update'); |
14
|
|
|
|
|
|
|
$registry->add(toolbar => 'guest_book_button', |
15
|
|
|
|
|
|
|
template => 'guest_book_button.html', |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub guest_book { |
20
|
|
|
|
|
|
|
my $user_db = $self->user_db->rdonly; |
21
|
|
|
|
|
|
|
my @pages = map { |
22
|
|
|
|
|
|
|
$self->pages->new_page($_); |
23
|
|
|
|
|
|
|
} sort {lc($a) cmp lc($b)} keys %{$user_db}; |
24
|
|
|
|
|
|
|
$user_db->close; |
25
|
|
|
|
|
|
|
$self->render_screen(pages => \@pages); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub update { |
29
|
|
|
|
|
|
|
my $hook = pop; |
30
|
|
|
|
|
|
|
my ($returned) = $hook->returned; |
31
|
|
|
|
|
|
|
return $returned unless $returned eq '1'; |
32
|
|
|
|
|
|
|
$self = $self->hub->guest_book; |
33
|
|
|
|
|
|
|
my $preference = shift; |
34
|
|
|
|
|
|
|
$self->remove_guest($preference->value); |
35
|
|
|
|
|
|
|
$self->add_guest($preference->new_value); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub add_guest { |
39
|
|
|
|
|
|
|
$self->user_db->rdwr->{(shift || return)} = 1; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub remove_guest { |
43
|
|
|
|
|
|
|
delete $self->user_db->rdwr->{(shift)}; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub user_db { |
47
|
|
|
|
|
|
|
my $db = io($self->plugin_directory . '/user_name.db'); |
48
|
|
|
|
|
|
|
$db->utf8->dbm('DB_File::Lock'); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
__DATA__ |