line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*- perl -*- |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# $Id: KeywordIndex.pm,v 1.3 2004/01/28 16:49:59 eserte Exp $ |
5
|
|
|
|
|
|
|
# Author: Slaven Rezic |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# Copyright (C) 2003 Slaven Rezic. |
8
|
|
|
|
|
|
|
# This is free software; you can redistribute it and/or modify it under the |
9
|
|
|
|
|
|
|
# terms of the GNU General Public License, see the file COPYING. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# |
12
|
|
|
|
|
|
|
# Mail: slaven@rezic.de |
13
|
|
|
|
|
|
|
# WWW: http://we-framework.sourceforge.net |
14
|
|
|
|
|
|
|
# |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
package WE_Frontend::Plugin::KeywordIndex; |
17
|
1
|
|
|
1
|
|
1119
|
use base qw(Template::Plugin); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
65
|
|
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
1
|
|
5
|
use HTML::Entities; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
51
|
|
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
1
|
|
4
|
use WE::Util::LangString qw(langstring); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
51
|
|
22
|
1
|
|
|
1
|
|
4
|
use WE_Frontend::Plugin::WE_Navigation; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
23
|
|
|
|
|
|
|
|
24
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
25
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
412
|
|
26
|
|
|
|
|
|
|
$VERSION = sprintf("%d.%02d", q$Revision: 1.3 $ =~ /(\d+)\.(\d+)/); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 NAME |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
WE_Frontend::Plugin::KeywordIndex - gather site keywords |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 SYNOPSIS |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my $t = Template->new({PLUGIN_BASE => "WE_Frontend::Plugin"}); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
[% USE KeywordIndex %] |
37
|
|
|
|
|
|
|
[% SET keywords = KeywordIndex.array() %] |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 DESCRIPTION |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Gather keywords and return them to the templating system. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head2 METHODS |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=over |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub new { |
50
|
0
|
|
|
0
|
1
|
|
my($class, $context, $params) = @_; |
51
|
0
|
|
|
|
|
|
my $n = WE_Frontend::Plugin::WE_Navigation->new($context, $params); |
52
|
0
|
|
|
|
|
|
my $self = { WE_Navigation => $n, |
53
|
|
|
|
|
|
|
Context => $context, |
54
|
|
|
|
|
|
|
}; |
55
|
0
|
|
|
|
|
|
bless $self, $class; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# XXX Possible args: |
59
|
|
|
|
|
|
|
# * $lang |
60
|
|
|
|
|
|
|
# * keyword-normalizer as a anonymous subroutine |
61
|
|
|
|
|
|
|
# * restrictions (use is_released_object or such?) |
62
|
|
|
|
|
|
|
sub gather_keywords { |
63
|
0
|
|
|
0
|
0
|
|
my($self, $rootid, %args) = @_; |
64
|
0
|
|
|
|
|
|
my $wen = $self->{WE_Navigation}; |
65
|
0
|
|
|
|
|
|
my $objdb = $wen->{ObjDB}; |
66
|
0
|
|
0
|
|
|
|
my $lang = $wen->{Context}->stash->get("lang") || "en"; |
67
|
0
|
|
|
|
|
|
$rootid = $objdb->root_object->Id; |
68
|
0
|
|
|
|
|
|
my %keywords; |
69
|
|
|
|
|
|
|
$objdb->walk($rootid, |
70
|
|
|
|
|
|
|
sub { |
71
|
0
|
|
|
0
|
|
|
my($id) = @_; |
72
|
0
|
|
|
|
|
|
my $o = $objdb->get_object($id); |
73
|
0
|
|
|
|
|
|
my $s = langstring($o->Keywords, $lang); |
74
|
0
|
0
|
|
|
|
|
return if !defined $s; |
75
|
0
|
|
|
|
|
|
my @keywords = split /\s*,\s*/, $s; |
76
|
0
|
|
|
|
|
|
for my $kw (@keywords) { |
77
|
0
|
|
|
|
|
|
push @{ $keywords{$kw} }, |
|
0
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
{ |
79
|
|
|
|
|
|
|
Id => $id, |
80
|
|
|
|
|
|
|
Title => langstring($o->Title, $lang), |
81
|
|
|
|
|
|
|
Relurl => "$id.html", # XXX do not hardcode extension, use NameDB if possible |
82
|
|
|
|
|
|
|
}; |
83
|
|
|
|
|
|
|
} |
84
|
0
|
|
|
|
|
|
}); |
85
|
0
|
|
|
|
|
|
\%keywords; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=item array() |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Format and output the given text definition. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# XXX Possible %args: |
95
|
|
|
|
|
|
|
# * interpolate initials into the result array |
96
|
|
|
|
|
|
|
# * sort function |
97
|
|
|
|
|
|
|
sub array { |
98
|
0
|
|
|
0
|
1
|
|
my($self) = @_; |
99
|
0
|
|
|
|
|
|
my $keywords = $self->gather_keywords(); # XXX supply objid and %args (from params?) |
100
|
0
|
|
|
|
|
|
my @out; |
101
|
0
|
|
|
|
|
|
for my $kw (sort { uc $a cmp uc $b } keys %$keywords) { |
|
0
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
push @out, {Keyword => $kw, |
103
|
|
|
|
|
|
|
References => $keywords->{$kw}, |
104
|
|
|
|
|
|
|
}; |
105
|
|
|
|
|
|
|
} |
106
|
0
|
|
|
|
|
|
return \@out; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
1; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
__END__ |