line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Kwiki::Favorites; |
2
|
1
|
|
|
1
|
|
34107
|
use Kwiki::Plugin -Base; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
use mixin 'Kwiki::Installer'; |
4
|
|
|
|
|
|
|
our $VERSION = '0.13'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
const class_id => 'favorites'; |
7
|
|
|
|
|
|
|
const css_file => 'favorites.css'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub register { |
10
|
|
|
|
|
|
|
my $registry = shift; |
11
|
|
|
|
|
|
|
$registry->add(action => 'favorites'); |
12
|
|
|
|
|
|
|
$registry->add(action => 'favorites_add'); |
13
|
|
|
|
|
|
|
$registry->add(action => 'favorites_remove'); |
14
|
|
|
|
|
|
|
$registry->add(toolbar => 'favorites_button', |
15
|
|
|
|
|
|
|
template => 'favorites_button.html', |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
$registry->add(widget => 'favorites_query', |
18
|
|
|
|
|
|
|
template => 'favorites_query.html', |
19
|
|
|
|
|
|
|
show_for => 'display', |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub favorites { |
24
|
|
|
|
|
|
|
my $favorites = |
25
|
|
|
|
|
|
|
$self->hub->cookie->jar->{favorites} || {}; |
26
|
|
|
|
|
|
|
my @pages = sort { |
27
|
|
|
|
|
|
|
$b->metadata->edit_unixtime <=> $a->metadata->edit_unixtime; |
28
|
|
|
|
|
|
|
} map { |
29
|
|
|
|
|
|
|
$self->pages->new_page($_); |
30
|
|
|
|
|
|
|
} keys %$favorites; |
31
|
|
|
|
|
|
|
$self->render_screen(pages => \@pages); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub favorites_add { |
35
|
|
|
|
|
|
|
my $page_name = $self->pages->name_to_id($self->cgi->page_name); |
36
|
|
|
|
|
|
|
my $favorites = $self->hub->cookie->jar->{favorites} || {}; |
37
|
|
|
|
|
|
|
$favorites->{$page_name} = 1; |
38
|
|
|
|
|
|
|
$self->hub->cookie->jar->{favorites} = $favorites; |
39
|
|
|
|
|
|
|
return "$page_name added"; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub favorites_remove { |
43
|
|
|
|
|
|
|
my $page_name = $self->pages->name_to_id($self->cgi->page_name); |
44
|
|
|
|
|
|
|
my $favorites = $self->hub->cookie->jar->{favorites} || {}; |
45
|
|
|
|
|
|
|
delete $favorites->{$page_name}; |
46
|
|
|
|
|
|
|
$self->hub->cookie->jar->{favorites} = $favorites; |
47
|
|
|
|
|
|
|
return "$page_name added"; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
__DATA__ |