| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# |
|
2
|
|
|
|
|
|
|
# content items used to store "normal", non-metadata content. |
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package HTML::WebMake::NormalContent; |
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use HTML::WebMake::Content; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
22
|
|
|
7
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
58
|
|
|
8
|
1
|
|
|
1
|
|
4
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
26
|
|
|
9
|
1
|
|
|
1
|
|
4
|
use locale; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
7
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
1
|
|
|
|
|
5015
|
use vars qw{ |
|
12
|
|
|
|
|
|
|
@ISA |
|
13
|
|
|
|
|
|
|
$WM_META_PAT $MIN_FMT_CACHE_LEN |
|
14
|
1
|
|
|
1
|
|
25
|
}; |
|
|
1
|
|
|
|
|
1
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
@ISA = qw(HTML::WebMake::Content); |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
$WM_META_PAT = qr{
|
|
20
|
|
|
|
|
|
|
$MIN_FMT_CACHE_LEN = 1024; |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
########################################################################### |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub new { |
|
25
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
|
26
|
0
|
|
0
|
|
|
|
$class = ref($class) || $class; |
|
27
|
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
my ($name, $file, $attrs, $text, $datasource) = @_; |
|
29
|
0
|
|
|
|
|
|
my $self = $class->SUPER::new (@_); |
|
30
|
|
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
bless ($self, $class); |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# do some references now to avoid doing them later, minor speedup |
|
34
|
0
|
|
|
|
|
|
my $main = $self->{main}; |
|
35
|
0
|
|
|
|
|
|
my $util = $main->{util}; |
|
36
|
0
|
|
|
|
|
|
my $metadata = $main->{metadata}; |
|
37
|
0
|
|
|
|
|
|
my $attrval; |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# used for Content items defined from Contents sections |
|
40
|
0
|
0
|
|
|
|
|
if (defined $datasource) { |
|
41
|
0
|
|
|
|
|
|
$self->{datasource} = $datasource; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# see if we have 'map=false' as an attribute |
|
45
|
0
|
|
|
|
|
|
$attrval = $attrs->{'map'}; |
|
46
|
0
|
|
0
|
|
|
|
$attrval ||= $metadata->get_attrdefault ('map'); |
|
47
|
0
|
0
|
|
|
|
|
if (defined $attrval) { |
|
48
|
0
|
0
|
|
|
|
|
if (!$util->parse_boolean ($attrval)) { |
|
49
|
0
|
|
|
|
|
|
$self->{no_map} = 1; |
|
50
|
|
|
|
|
|
|
} |
|
51
|
0
|
|
|
|
|
|
delete $self->{'map'}; # in case it was set as an attr |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# is this content item formatted as-is, no content refs to be expanded |
|
55
|
|
|
|
|
|
|
# etc.? |
|
56
|
0
|
|
|
|
|
|
$attrval = $attrs->{'asis'}; |
|
57
|
0
|
|
0
|
|
|
|
$attrval ||= $metadata->get_attrdefault ('asis'); |
|
58
|
0
|
0
|
|
|
|
|
if (defined $attrval) { |
|
59
|
0
|
|
|
|
|
|
$self->{keep_as_is} = $util->parse_boolean ($attrval); |
|
60
|
0
|
|
|
|
|
|
delete $self->{'asis'}; # in case it was set as an attr |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
$attrval = $attrs->{'isroot'}; |
|
64
|
0
|
|
0
|
|
|
|
$attrval ||= $metadata->get_attrdefault ('isroot'); |
|
65
|
0
|
0
|
|
|
|
|
if (defined $attrval) { |
|
66
|
0
|
|
|
|
|
|
$self->{is_root} = $util->parse_boolean ($attrval); |
|
67
|
0
|
|
|
|
|
|
delete $self->{'isroot'}; # in case it was set as an attr |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
0
|
0
|
|
|
|
|
if (defined $attrs->{is_sitemap}) { |
|
71
|
0
|
|
|
|
|
|
$self->{is_sitemap} = |
|
72
|
|
|
|
|
|
|
$util->parse_boolean ($attrs->{is_sitemap}); |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
$attrval = $attrs->{'preproc'}; |
|
76
|
0
|
|
0
|
|
|
|
$attrval ||= $metadata->get_attrdefault ('preproc'); |
|
77
|
0
|
0
|
|
|
|
|
if (defined $attrval) { |
|
78
|
0
|
|
|
|
|
|
$self->{preproc} = $attrval; |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
0
|
0
|
|
|
|
|
if ($self->{is_sitemap}) { |
|
82
|
0
|
|
|
|
|
|
$self->{sitemap_node_name} = $attrs->{node}; |
|
83
|
0
|
|
|
|
|
|
$self->{sitemap_leaf_name} = $attrs->{leaf}; |
|
84
|
0
|
|
|
|
|
|
$self->{sitemap_dynamic_name} = $attrs->{dynamic}; |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
0
|
0
|
|
|
|
|
if ($self->{is_root}) { |
|
88
|
0
|
|
|
|
|
|
$main->getmapper()->set_root ($self); |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# is_navlinks is an attribute set by Main::add_navlinks(). |
|
92
|
0
|
0
|
|
|
|
|
if ($self->{is_navlinks}) { |
|
93
|
0
|
|
|
|
|
|
$self->{cannot_have_metadata} = 1; |
|
94
|
0
|
|
|
|
|
|
$self->{only_usable_from_def_refs} = 1; |
|
95
|
0
|
|
|
|
|
|
$self->{no_map} = 1; |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
# is_breadcrumbs: set by Main::add_breadcrumbs(). |
|
99
|
0
|
0
|
|
|
|
|
if ($self->{is_breadcrumbs}) { |
|
100
|
0
|
|
|
|
|
|
$self->{cannot_have_metadata} = 1; |
|
101
|
0
|
|
|
|
|
|
$self->{only_usable_from_def_refs} = 1; |
|
102
|
0
|
|
|
|
|
|
$self->{no_map} = 1; |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
|
|
105
|
0
|
0
|
|
|
|
|
if (!$self->{no_map}) { |
|
106
|
0
|
|
|
|
|
|
$metadata->add_metadefaults ($self); |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
|
|
109
|
0
|
0
|
0
|
|
|
|
if ($self->{is_root} && $self->{no_map}) { |
|
110
|
0
|
|
|
|
|
|
warn ($self->as_string().": root content cannot have \"map=false\"!\n"); |
|
111
|
0
|
|
|
|
|
|
undef $self->{no_map}; |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
$main->add_new_content_to_map ($name, $self); |
|
115
|
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
$self; |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
|
|
119
|
0
|
|
|
0
|
0
|
|
sub dbg { HTML::WebMake::Main::dbg (@_); } |
|
120
|
0
|
|
|
0
|
0
|
|
sub dbg2 { HTML::WebMake::Main::dbg2 (@_); } |
|
121
|
0
|
|
|
0
|
0
|
|
sub vrb { HTML::WebMake::Main::vrb (@_); } |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub as_string { |
|
126
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
|
127
|
0
|
|
|
|
|
|
"\$\{".$self->{name}."\}"; |
|
128
|
|
|
|
|
|
|
} |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub is_generated_content { |
|
133
|
0
|
|
|
0
|
1
|
|
0; |
|
134
|
|
|
|
|
|
|
} |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub expand { |
|
139
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
|
140
|
0
|
|
|
|
|
|
return $self->{main}->curly_subst ($self->{name}, $self->{name}); |
|
141
|
|
|
|
|
|
|
} |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub expand_no_ref { |
|
144
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
|
145
|
0
|
|
|
|
|
|
return $self->{main}->fileless_subst ($self->{name}, '${'.$self->{name}.'}'); |
|
146
|
|
|
|
|
|
|
} |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub get_metadata { |
|
151
|
0
|
|
|
0
|
1
|
|
my ($self, $key) = @_; |
|
152
|
|
|
|
|
|
|
|
|
153
|
0
|
0
|
|
|
|
|
if (!defined $self->{cached_metas}) { |
|
154
|
0
|
|
|
|
|
|
$self->{cached_metas} = { }; |
|
155
|
|
|
|
|
|
|
} |
|
156
|
|
|
|
|
|
|
|
|
157
|
0
|
|
|
|
|
|
my $val = $self->{cached_metas}->{$key}; |
|
158
|
0
|
|
|
|
|
|
my $main = $self->{main}; |
|
159
|
|
|
|
|
|
|
|
|
160
|
0
|
0
|
|
|
|
|
if (!defined $val) { |
|
161
|
0
|
|
|
|
|
|
$val = $main->quiet_curly_meta_subst |
|
162
|
|
|
|
|
|
|
($HTML::WebMake::Main::SUBST_META, $self->{name}.".".$key); |
|
163
|
0
|
0
|
|
|
|
|
if (!defined $val) { |
|
164
|
0
|
|
0
|
|
|
|
$val ||= $main->{metadata}->get_default_value ($key); |
|
165
|
|
|
|
|
|
|
} |
|
166
|
|
|
|
|
|
|
|
|
167
|
0
|
|
|
|
|
|
$val = $main->{metadata}->convert_to_type ($key, $val); |
|
168
|
0
|
|
|
|
|
|
$self->{cached_metas}->{$key} = $val; |
|
169
|
|
|
|
|
|
|
} |
|
170
|
|
|
|
|
|
|
|
|
171
|
0
|
|
|
|
|
|
return $val; |
|
172
|
|
|
|
|
|
|
} |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
sub create_extra_metas_if_needed { |
|
177
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
|
178
|
0
|
0
|
|
|
|
|
if (!defined $self->{extra_metas}) { |
|
179
|
0
|
|
|
|
|
|
$self->{extra_metas} = { }; |
|
180
|
|
|
|
|
|
|
} |
|
181
|
|
|
|
|
|
|
} |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
sub load_metadata { |
|
186
|
0
|
|
|
0
|
0
|
|
my ($self, $name, $key) = @_; |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
# a different method is used to load metadata from the current content |
|
189
|
|
|
|
|
|
|
# item, so this should not happen: |
|
190
|
0
|
0
|
|
|
|
|
if ($key =~ /^this\./i) { |
|
191
|
0
|
|
|
|
|
|
warn "oops! wasn't expecting a this. metaref in load_metadata: $key"; |
|
192
|
|
|
|
|
|
|
} |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
# unmapped content can't have metadata |
|
195
|
0
|
0
|
|
|
|
|
if ($self->{no_map}) { return; } |
|
|
0
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
|
|
197
|
0
|
0
|
|
|
|
|
if (defined $self->{extra_metas}->{$key}) { |
|
198
|
0
|
|
|
|
|
|
$self->add_extra_metas ($name); |
|
199
|
0
|
|
|
|
|
|
return; # we don't need to parse the text for this metadatum |
|
200
|
|
|
|
|
|
|
} |
|
201
|
|
|
|
|
|
|
|
|
202
|
0
|
0
|
|
|
|
|
if (!defined ($self->{parsed_metadata_tags})) { |
|
203
|
0
|
|
|
|
|
|
dbg ("loading content \"$name\" for meta ref \$\[$key\]"); |
|
204
|
0
|
|
|
|
|
|
$self->load_text_if_needed(); |
|
205
|
|
|
|
|
|
|
|
|
206
|
0
|
|
|
|
|
|
$self->{set_thisdot_metadata_items} = 0; |
|
207
|
0
|
|
|
|
|
|
$self->parse_metadata_tags ($name, $self->{text}); |
|
208
|
|
|
|
|
|
|
|
|
209
|
0
|
|
|
|
|
|
$self->add_extra_metas ($name); |
|
210
|
0
|
|
|
|
|
|
$self->infer_implicit_metas(); |
|
211
|
|
|
|
|
|
|
|
|
212
|
0
|
|
|
|
|
|
$self->{parsed_metadata_tags} = 1; |
|
213
|
|
|
|
|
|
|
} |
|
214
|
|
|
|
|
|
|
} |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
sub parse_metadata_tags { |
|
219
|
0
|
|
|
0
|
0
|
|
my ($self, $from, $str) = @_; |
|
220
|
|
|
|
|
|
|
|
|
221
|
0
|
0
|
|
|
|
|
if ($str !~ /${WM_META_PAT}/i) { return; } |
|
|
0
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
|
|
223
|
0
|
|
|
|
|
|
my $util = $self->{main}->{util}; |
|
224
|
|
|
|
|
|
|
|
|
225
|
0
|
|
|
|
|
|
$self->{meta_from} = $from; |
|
226
|
0
|
|
|
|
|
|
$str = $util->strip_tags ($str, "wmmeta", |
|
227
|
|
|
|
|
|
|
$self, \&tag_wmmeta, qw(name)); |
|
228
|
0
|
|
|
|
|
|
$self->{meta_from} = undef; |
|
229
|
|
|
|
|
|
|
|
|
230
|
0
|
0
|
|
|
|
|
if ($str =~ /${WM_META_PAT}.*?>/i) { |
|
231
|
0
|
|
|
|
|
|
warn " tag could not be parsed: \${$from} in ". |
|
232
|
|
|
|
|
|
|
$self->{main}->{current_subst}->{filename}.": $&\n"; |
|
233
|
|
|
|
|
|
|
} |
|
234
|
|
|
|
|
|
|
} |
|
235
|
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
sub tag_wmmeta { |
|
237
|
0
|
|
|
0
|
0
|
|
my ($self, $tag, $attrs, $text) = @_; |
|
238
|
|
|
|
|
|
|
|
|
239
|
0
|
|
|
|
|
|
my $name = lc $attrs->{name}; |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
# use a "value" attr if available; otherwise use the text |
|
242
|
|
|
|
|
|
|
# inside the tag. |
|
243
|
0
|
|
|
|
|
|
my $val = $attrs->{value}; |
|
244
|
0
|
0
|
|
|
|
|
if (!defined $val) { $val = $text; } |
|
|
0
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
|
|
246
|
0
|
|
|
|
|
|
$self->{main}->add_metadata ($self->{meta_from}, $name, $val, $attrs, |
|
247
|
|
|
|
|
|
|
$self->{set_thisdot_metadata_items}); |
|
248
|
|
|
|
|
|
|
|
|
249
|
0
|
|
|
|
|
|
""; |
|
250
|
|
|
|
|
|
|
} |
|
251
|
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
|
253
|
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
sub infer_implicit_metas { |
|
255
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
|
256
|
|
|
|
|
|
|
|
|
257
|
0
|
0
|
0
|
|
|
|
if (defined $self->{main}->{metadatas}->{"this.title"} |
|
258
|
|
|
|
|
|
|
&& defined $self->{main}->{metadatas}->{$self->{name}.".title"}) |
|
259
|
|
|
|
|
|
|
{ |
|
260
|
0
|
|
|
|
|
|
return; # no need to infer it, it's already defined |
|
261
|
|
|
|
|
|
|
} |
|
262
|
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
# Snarf a default title from the text, if one has not been set. |
|
264
|
0
|
|
|
|
|
|
$self->find_implicit_title_in_text (\$self->{text}); |
|
265
|
|
|
|
|
|
|
} |
|
266
|
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
|
268
|
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
sub find_implicit_title_in_text { |
|
270
|
0
|
|
|
0
|
0
|
|
my ($self, $txt) = @_; |
|
271
|
|
|
|
|
|
|
|
|
272
|
0
|
|
|
|
|
|
my $fmt = $self->get_format(); |
|
273
|
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
# POD documentation: the NAME section |
|
275
|
0
|
0
|
|
|
|
|
if ($fmt eq 'text/pod') { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
276
|
0
|
0
|
|
|
|
|
if ($$txt =~ /^\s*=head1\s+[-A-Z0-9_ ]+\n\s+(\S[^\n]*?)\n/s) |
|
277
|
0
|
|
|
|
|
|
{ $self->add_inferred_metadata ("title", $1, 'text/html'); } |
|
278
|
|
|
|
|
|
|
} |
|
279
|
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
# HTML/XML: the first title tag or heading |
|
281
|
|
|
|
|
|
|
elsif ($fmt eq 'text/html') { |
|
282
|
0
|
0
|
|
|
|
|
if ($$txt =~ /(.*?)<\/title>/si) |
|
|
|
0
|
|
|
|
|
|
|
283
|
0
|
|
|
|
|
|
{ $self->add_inferred_metadata ("title", $1, 'text/html'); } |
|
284
|
|
|
|
|
|
|
# or title tag |
|
285
|
|
|
|
|
|
|
elsif ($$txt =~ /(.*?)<\/h\d>/si) |
|
286
|
0
|
|
|
|
|
|
{ $self->add_inferred_metadata ("title", $1, 'text/html'); } |
|
287
|
|
|
|
|
|
|
} |
|
288
|
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
# EtText: EtText headings |
|
290
|
|
|
|
|
|
|
elsif ($fmt eq 'text/et') { |
|
291
|
0
|
0
|
|
|
|
|
if ($$txt =~ /(?:^\n+|\n\n)([^\n]+)[ \t]*\n[-=\~]{3,}\n/s) |
|
|
|
0
|
|
|
|
|
|
|
292
|
0
|
|
|
|
|
|
{ $self->add_inferred_metadata ("title", $1, 'text/html'); } |
|
293
|
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
elsif ($$txt =~ /(?:^\n+|\n\n)([0-9A-Z][^a-z]+)[ \t]*\n\n/s) |
|
295
|
0
|
|
|
|
|
|
{ $self->add_inferred_metadata ("title", $1, 'text/html'); } |
|
296
|
|
|
|
|
|
|
} |
|
297
|
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
# otherwise the first line of non-white chars |
|
299
|
|
|
|
|
|
|
elsif ($$txt =~ /^\s*(\S[^\n]*?)\s*\n/s) |
|
300
|
0
|
|
|
|
|
|
{ $self->add_inferred_metadata ("title", $1, $fmt); } |
|
301
|
|
|
|
|
|
|
|
|
302
|
0
|
|
|
|
|
|
undef; |
|
303
|
|
|
|
|
|
|
} |
|
304
|
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
|
306
|
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
sub add_inferred_metadata { |
|
308
|
0
|
|
|
0
|
0
|
|
my ($self, $name, $val, $fmt) = @_; |
|
309
|
|
|
|
|
|
|
|
|
310
|
0
|
|
|
|
|
|
my $existingmeta = $self->{main}->{metadatas}->{$self->{name}.".".$name}; |
|
311
|
0
|
0
|
|
|
|
|
return if (defined $existingmeta); |
|
312
|
|
|
|
|
|
|
|
|
313
|
0
|
|
|
|
|
|
my $attrs = { }; |
|
314
|
|
|
|
|
|
|
|
|
315
|
0
|
0
|
|
|
|
|
if ($fmt ne 'text/html') { |
|
316
|
0
|
|
|
|
|
|
$attrs->{format} = $fmt; |
|
317
|
|
|
|
|
|
|
} |
|
318
|
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
# If the "title" has a reference to $[this.title], it's not a |
|
320
|
|
|
|
|
|
|
# suitable inference; it uses the genuine title from another |
|
321
|
|
|
|
|
|
|
# content object. |
|
322
|
0
|
0
|
|
|
|
|
return if ($val =~ /\$\[this.title\]/i); |
|
323
|
|
|
|
|
|
|
|
|
324
|
0
|
|
|
|
|
|
$val =~ s/<[^>]+>//g; # trim wayward HTML tags |
|
325
|
0
|
|
|
|
|
|
$val =~ s/^\s+//; |
|
326
|
0
|
|
|
|
|
|
$val =~ s/\s+$//; |
|
327
|
|
|
|
|
|
|
|
|
328
|
0
|
|
|
|
|
|
dbg ("inferring $name metadata from text: \"$val\""); |
|
329
|
0
|
|
|
|
|
|
$self->{main}->add_metadata ($self->{name}, $name, $val, $attrs, |
|
330
|
|
|
|
|
|
|
$self->{set_thisdot_metadata_items}); |
|
331
|
|
|
|
|
|
|
|
|
332
|
0
|
|
|
|
|
|
$self->create_extra_metas_if_needed(); |
|
333
|
0
|
|
|
|
|
|
$self->{extra_metas}->{$name} = $val; |
|
334
|
|
|
|
|
|
|
} |
|
335
|
|
|
|
|
|
|
|
|
336
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
|
337
|
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
sub add_extra_metas { |
|
339
|
0
|
|
|
0
|
0
|
|
my ($self, $from) = @_; |
|
340
|
|
|
|
|
|
|
# also add our own extra metadata from nav links, tags |
|
341
|
|
|
|
|
|
|
# etc. |
|
342
|
0
|
|
|
|
|
|
my ($metaname, $val); |
|
343
|
0
|
|
|
|
|
|
while (($metaname, $val) = each %{$self->{extra_metas}}) { |
|
|
0
|
|
|
|
|
|
|
|
344
|
0
|
|
|
|
|
|
$self->{main}->add_metadata ($from, $metaname, $val, { }, |
|
345
|
|
|
|
|
|
|
$self->{set_thisdot_metadata_items}); |
|
346
|
|
|
|
|
|
|
} |
|
347
|
|
|
|
|
|
|
} |
|
348
|
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
|
350
|
|
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
sub get_score { |
|
352
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
|
353
|
0
|
|
|
|
|
|
return $self->get_metadata ("score"); |
|
354
|
|
|
|
|
|
|
} |
|
355
|
|
|
|
|
|
|
|
|
356
|
|
|
|
|
|
|
sub get_title { |
|
357
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
|
358
|
0
|
|
|
|
|
|
return $self->get_metadata ("title"); |
|
359
|
|
|
|
|
|
|
} |
|
360
|
|
|
|
|
|
|
|
|
361
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
|
362
|
|
|
|
|
|
|
|
|
363
|
|
|
|
|
|
|
sub get_modtime { |
|
364
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
|
365
|
0
|
0
|
|
|
|
|
if (defined $self->{datasource}) { |
|
366
|
0
|
|
|
|
|
|
return $self->{datasource}->get_location_mod_time ($self->get_filename()); |
|
367
|
|
|
|
|
|
|
} else { |
|
368
|
0
|
|
|
|
|
|
return $self->{main}->cached_get_modtime ($self->get_filename()); |
|
369
|
|
|
|
|
|
|
} |
|
370
|
|
|
|
|
|
|
} |
|
371
|
|
|
|
|
|
|
|
|
372
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
|
373
|
|
|
|
|
|
|
|
|
374
|
|
|
|
|
|
|
sub get_text_as { |
|
375
|
0
|
|
|
0
|
0
|
|
my ($self, $format) = @_; |
|
376
|
0
|
|
|
|
|
|
my $main = $self->{main}; |
|
377
|
|
|
|
|
|
|
|
|
378
|
0
|
0
|
|
|
|
|
if (!defined $format) { |
|
379
|
0
|
|
|
|
|
|
carp ($self->as_string().": get_text_as with undef arg"); |
|
380
|
0
|
|
|
|
|
|
return ""; |
|
381
|
|
|
|
|
|
|
} |
|
382
|
|
|
|
|
|
|
|
|
383
|
0
|
|
|
|
|
|
my $fmt = $self->get_format(); |
|
384
|
0
|
0
|
|
|
|
|
if (!defined $fmt) { |
|
385
|
0
|
|
|
|
|
|
carp ($self->as_string().": no format defined"); |
|
386
|
0
|
|
|
|
|
|
return ""; |
|
387
|
|
|
|
|
|
|
} |
|
388
|
|
|
|
|
|
|
|
|
389
|
|
|
|
|
|
|
# ensure if we parse any metadata, it's loaded as "this.foo" |
|
390
|
|
|
|
|
|
|
# as well as "name.foo" |
|
391
|
0
|
|
|
|
|
|
$self->{set_thisdot_metadata_items} = 1; |
|
392
|
|
|
|
|
|
|
|
|
393
|
0
|
|
|
|
|
|
$self->load_text_if_needed(); |
|
394
|
|
|
|
|
|
|
|
|
395
|
|
|
|
|
|
|
# we cache format changes, unless (a) the content object is |
|
396
|
|
|
|
|
|
|
# strictly dynamic, such as navlinks or breadcrumbs or a sitemap; |
|
397
|
|
|
|
|
|
|
# (b) the formats are the same (obviously!), or (c) the length |
|
398
|
|
|
|
|
|
|
# of the text to reformat is smaller than a predefined minimum |
|
399
|
|
|
|
|
|
|
# cacheable length (currently $MIN_FMT_CACHE_LEN). |
|
400
|
|
|
|
|
|
|
# |
|
401
|
0
|
|
|
|
|
|
my $ignore_reformat_cache = 0; |
|
402
|
0
|
|
|
|
|
|
my $txt; |
|
403
|
|
|
|
|
|
|
|
|
404
|
0
|
0
|
|
|
|
|
if ($self->{is_navlinks}) { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
405
|
0
|
|
|
|
|
|
$txt = $self->get_navlinks_text(); |
|
406
|
0
|
|
|
|
|
|
$ignore_reformat_cache = 1; |
|
407
|
|
|
|
|
|
|
|
|
408
|
|
|
|
|
|
|
} elsif ($self->{is_breadcrumbs}) { |
|
409
|
0
|
|
|
|
|
|
$txt = $self->get_breadcrumbs_text(); |
|
410
|
0
|
|
|
|
|
|
$ignore_reformat_cache = 1; |
|
411
|
|
|
|
|
|
|
|
|
412
|
|
|
|
|
|
|
} elsif ($self->{keep_as_is}) { |
|
413
|
0
|
|
|
|
|
|
$txt = $self->get_as_is_text(); |
|
414
|
|
|
|
|
|
|
|
|
415
|
|
|
|
|
|
|
} else { |
|
416
|
0
|
|
|
|
|
|
$txt = $self->get_normal_content_text(); |
|
417
|
|
|
|
|
|
|
} |
|
418
|
|
|
|
|
|
|
|
|
419
|
0
|
0
|
|
|
|
|
if (!defined $txt) { die "oops! undefined text for $self->{name}"; } |
|
|
0
|
|
|
|
|
|
|
|
420
|
|
|
|
|
|
|
|
|
421
|
0
|
0
|
|
|
|
|
if (defined $self->{preproc}) { |
|
422
|
0
|
|
|
|
|
|
$txt = $main->_p_interpret ('perl', $self->{preproc}, $txt); |
|
423
|
0
|
0
|
|
|
|
|
if (!defined $txt) { |
|
424
|
0
|
|
|
|
|
|
warn "preproc for \${$self->{name}} failed\n"; |
|
425
|
0
|
|
|
|
|
|
$txt = ''; |
|
426
|
|
|
|
|
|
|
} |
|
427
|
|
|
|
|
|
|
} |
|
428
|
|
|
|
|
|
|
|
|
429
|
0
|
0
|
|
|
|
|
if (!$ignore_reformat_cache) { |
|
430
|
0
|
0
|
|
|
|
|
if ($self->{is_sitemap}) { $ignore_reformat_cache = 1; } |
|
|
0
|
|
|
|
|
|
|
|
431
|
0
|
0
|
|
|
|
|
if ($main->{force_output}) { $ignore_reformat_cache = 1; } |
|
|
0
|
0
|
|
|
|
|
|
|
432
|
0
|
|
|
|
|
|
elsif (length ($txt) < $MIN_FMT_CACHE_LEN) { $ignore_reformat_cache = 1; } |
|
433
|
|
|
|
|
|
|
} |
|
434
|
|
|
|
|
|
|
|
|
435
|
|
|
|
|
|
|
# preformat user tags |
|
436
|
0
|
|
|
|
|
|
$main->getusertags()->subst_preformat_tags ($self->{name}, \$txt); |
|
437
|
|
|
|
|
|
|
|
|
438
|
|
|
|
|
|
|
# reformat before substs; this way we can cache the reformat |
|
439
|
|
|
|
|
|
|
# results for next time. |
|
440
|
0
|
0
|
|
|
|
|
if ($fmt ne $format) { |
|
441
|
|
|
|
|
|
|
# strip metadata before conversion |
|
442
|
0
|
|
|
|
|
|
$main->strip_metadata ($self->{name}, \$txt); |
|
443
|
|
|
|
|
|
|
|
|
444
|
0
|
|
|
|
|
|
$txt = $main->{format_conv}->convert |
|
445
|
|
|
|
|
|
|
($self, $fmt, $format, $txt, $ignore_reformat_cache); |
|
446
|
|
|
|
|
|
|
} |
|
447
|
|
|
|
|
|
|
|
|
448
|
|
|
|
|
|
|
# subst refs and perl code |
|
449
|
0
|
|
|
|
|
|
$main->subst ($self->{name}, \$txt, 1); |
|
450
|
|
|
|
|
|
|
|
|
451
|
|
|
|
|
|
|
# always remove leading & trailing whitespace from HTML or XML |
|
452
|
|
|
|
|
|
|
# content. |
|
453
|
0
|
0
|
0
|
|
|
|
if ($format eq 'text/html' || $format eq 'text/xml') { |
|
454
|
0
|
|
|
|
|
|
$txt =~ s/^\s+//s;$txt =~ s/\s+$//s; |
|
|
0
|
|
|
|
|
|
|
|
455
|
|
|
|
|
|
|
} |
|
456
|
|
|
|
|
|
|
|
|
457
|
0
|
|
|
|
|
|
$txt; |
|
458
|
|
|
|
|
|
|
} |
|
459
|
|
|
|
|
|
|
|
|
460
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
|
461
|
|
|
|
|
|
|
|
|
462
|
|
|
|
|
|
|
sub get_navlinks_text { |
|
463
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
|
464
|
|
|
|
|
|
|
|
|
465
|
0
|
|
|
|
|
|
$self->set_navlinks_vars (); |
|
466
|
0
|
|
|
|
|
|
return $self->{text}; |
|
467
|
|
|
|
|
|
|
} |
|
468
|
|
|
|
|
|
|
|
|
469
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
|
470
|
|
|
|
|
|
|
|
|
471
|
|
|
|
|
|
|
sub get_as_is_text { |
|
472
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
|
473
|
|
|
|
|
|
|
|
|
474
|
0
|
0
|
|
|
|
|
if (!$self->{no_map}) { |
|
475
|
0
|
|
|
|
|
|
$self->add_navigation_metadata(); |
|
476
|
0
|
|
|
|
|
|
$self->add_extra_metas ($self->{name}); |
|
477
|
0
|
|
|
|
|
|
$self->infer_implicit_metas(); |
|
478
|
|
|
|
|
|
|
|
|
479
|
|
|
|
|
|
|
# if this content item is mapped, set a var called "__MainContentName" |
|
480
|
|
|
|
|
|
|
# so it'll be used as the "main" content item for the current page |
|
481
|
|
|
|
|
|
|
# while drawing the breadcrumb trail. |
|
482
|
0
|
|
|
|
|
|
$self->{main}->set_transient_content ("__MainContentName", $self->{name}); |
|
483
|
|
|
|
|
|
|
} |
|
484
|
|
|
|
|
|
|
|
|
485
|
0
|
|
|
|
|
|
$self->touch_last_used(); |
|
486
|
0
|
|
|
|
|
|
return $self->{text}; |
|
487
|
|
|
|
|
|
|
} |
|
488
|
|
|
|
|
|
|
|
|
489
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
|
490
|
|
|
|
|
|
|
|
|
491
|
|
|
|
|
|
|
sub get_normal_content_text { |
|
492
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
|
493
|
|
|
|
|
|
|
|
|
494
|
0
|
0
|
|
|
|
|
if (!$self->{no_map}) { |
|
495
|
0
|
|
|
|
|
|
$self->add_navigation_metadata(); |
|
496
|
|
|
|
|
|
|
|
|
497
|
0
|
|
|
|
|
|
my $name = $self->{name}; |
|
498
|
0
|
|
|
|
|
|
dbg ("parsing metadata in \"$name\""); |
|
499
|
0
|
|
|
|
|
|
$self->parse_metadata_tags ($name, $self->{text}); |
|
500
|
|
|
|
|
|
|
|
|
501
|
0
|
|
|
|
|
|
$self->add_extra_metas ($name); |
|
502
|
0
|
|
|
|
|
|
$self->infer_implicit_metas(); |
|
503
|
|
|
|
|
|
|
|
|
504
|
|
|
|
|
|
|
# if this content item is mapped, set a var called "__MainContentName" |
|
505
|
|
|
|
|
|
|
# so it'll be used as the "main" content item for the current page |
|
506
|
|
|
|
|
|
|
# while drawing the breadcrumb trail. |
|
507
|
0
|
|
|
|
|
|
$self->{main}->set_transient_content ("__MainContentName", $name); |
|
508
|
|
|
|
|
|
|
} |
|
509
|
|
|
|
|
|
|
|
|
510
|
0
|
|
|
|
|
|
$self->touch_last_used(); |
|
511
|
0
|
|
|
|
|
|
return $self->{text}; |
|
512
|
|
|
|
|
|
|
} |
|
513
|
|
|
|
|
|
|
|
|
514
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
|
515
|
|
|
|
|
|
|
|
|
516
|
|
|
|
|
|
|
sub load_text_if_needed { |
|
517
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
|
518
|
|
|
|
|
|
|
|
|
519
|
0
|
0
|
|
|
|
|
if (defined $self->{text}) { return; } |
|
|
0
|
|
|
|
|
|
|
|
520
|
0
|
0
|
|
|
|
|
if (!defined $self->{location}) { return; } |
|
|
0
|
|
|
|
|
|
|
|
521
|
0
|
0
|
|
|
|
|
if (!defined $self->{datasource}) { return; } |
|
|
0
|
|
|
|
|
|
|
|
522
|
|
|
|
|
|
|
|
|
523
|
|
|
|
|
|
|
# deferred loading of content text. |
|
524
|
0
|
|
|
|
|
|
$self->touch_last_used(); |
|
525
|
0
|
|
|
|
|
|
$self->{text} = $self->{datasource}->get_location ($self->get_filename()); |
|
526
|
|
|
|
|
|
|
} |
|
527
|
|
|
|
|
|
|
|
|
528
|
|
|
|
|
|
|
sub unload_text { |
|
529
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
|
530
|
|
|
|
|
|
|
|
|
531
|
0
|
0
|
|
|
|
|
if (defined $self->{datasource}) { |
|
532
|
0
|
|
|
|
|
|
dbg ($self->as_string().": unloading cached text, ". |
|
533
|
|
|
|
|
|
|
"last used: ".$self->{last_used}); |
|
534
|
0
|
|
|
|
|
|
delete $self->{text}; |
|
535
|
|
|
|
|
|
|
} |
|
536
|
|
|
|
|
|
|
} |
|
537
|
|
|
|
|
|
|
|
|
538
|
|
|
|
|
|
|
sub is_from_datasource { |
|
539
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
|
540
|
0
|
0
|
|
|
|
|
if (!defined $self->{datasource}) { return 0; } |
|
|
0
|
|
|
|
|
|
|
|
541
|
0
|
|
|
|
|
|
1; |
|
542
|
|
|
|
|
|
|
} |
|
543
|
|
|
|
|
|
|
|
|
544
|
|
|
|
|
|
|
sub touch_last_used { |
|
545
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
|
546
|
|
|
|
|
|
|
|
|
547
|
0
|
0
|
|
|
|
|
if (defined $self->{datasource}) { |
|
548
|
0
|
|
|
|
|
|
$self->{last_used} = $self->{main}->{current_tick}; |
|
549
|
0
|
|
|
|
|
|
dbg2 ("updating last used on ".$self->as_string().": ".$self->{last_used}); |
|
550
|
|
|
|
|
|
|
} |
|
551
|
|
|
|
|
|
|
} |
|
552
|
|
|
|
|
|
|
|
|
553
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
|
554
|
|
|
|
|
|
|
|
|
555
|
|
|
|
|
|
|
sub add_ref_from_url { |
|
556
|
0
|
|
|
0
|
0
|
|
my ($self, $filename) = @_; |
|
557
|
|
|
|
|
|
|
|
|
558
|
0
|
0
|
|
|
|
|
return if ($filename =~ /^\(/); # (eval), (dep_ignore) etc. |
|
559
|
|
|
|
|
|
|
|
|
560
|
0
|
0
|
0
|
|
|
|
if (!$self->{no_map} && !defined $self->{reffed_in_url}) { |
|
561
|
0
|
|
|
|
|
|
dbg2 ($self->as_string().": add ref from url $filename"); |
|
562
|
0
|
|
|
|
|
|
$self->{reffed_in_url} = $filename; |
|
563
|
0
|
|
|
|
|
|
$self->{main}->getcache()->put_metadata ($self->{name}.".url", $filename); |
|
564
|
|
|
|
|
|
|
} |
|
565
|
|
|
|
|
|
|
} |
|
566
|
|
|
|
|
|
|
|
|
567
|
|
|
|
|
|
|
sub get_url { |
|
568
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
|
569
|
|
|
|
|
|
|
|
|
570
|
0
|
0
|
|
|
|
|
if ($self->{no_map}) { |
|
571
|
0
|
|
|
|
|
|
warn "cannot get URLs for unmapped content \${$self->{name}}\n"; |
|
572
|
0
|
|
|
|
|
|
return ''; |
|
573
|
|
|
|
|
|
|
} |
|
574
|
|
|
|
|
|
|
|
|
575
|
0
|
|
|
|
|
|
my $url = $self->{reffed_in_url}; |
|
576
|
0
|
0
|
|
|
|
|
if (defined $url) { return $url; } |
|
|
0
|
|
|
|
|
|
|
|
577
|
|
|
|
|
|
|
|
|
578
|
0
|
|
|
|
|
|
$url = $self->{main}->getcache()->get_metadata ($self->{name}.".url"); |
|
579
|
|
|
|
|
|
|
|
|
580
|
0
|
0
|
|
|
|
|
if (defined $url) { |
|
581
|
0
|
|
|
|
|
|
$self->{reffed_in_url} = $url; |
|
582
|
0
|
|
|
|
|
|
return $url; |
|
583
|
|
|
|
|
|
|
} |
|
584
|
|
|
|
|
|
|
|
|
585
|
|
|
|
|
|
|
defer: |
|
586
|
0
|
|
|
|
|
|
$url = $self->{main}->make_deferred_url ($self->{name}); |
|
587
|
0
|
|
|
|
|
|
return $url; |
|
588
|
|
|
|
|
|
|
} |
|
589
|
|
|
|
|
|
|
|
|
590
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
|
591
|
|
|
|
|
|
|
|
|
592
|
|
|
|
|
|
|
sub add_navigation_metadata { |
|
593
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
|
594
|
|
|
|
|
|
|
|
|
595
|
0
|
0
|
0
|
|
|
|
return if ($self->{no_map} || $self->is_generated_content()); |
|
596
|
0
|
0
|
|
|
|
|
return if ($self->{added_nav_metas_flag}); |
|
597
|
0
|
|
|
|
|
|
$self->{added_nav_metas_flag} = 1; |
|
598
|
|
|
|
|
|
|
|
|
599
|
0
|
|
|
|
|
|
$self->create_extra_metas_if_needed(); |
|
600
|
0
|
0
|
|
|
|
|
if (defined ($self->{up_content})) { |
|
601
|
0
|
|
|
|
|
|
$self->{extra_metas}->{'nav_up'} = $self->{up_content}->get_name(); |
|
602
|
|
|
|
|
|
|
} |
|
603
|
0
|
0
|
|
|
|
|
if (defined ($self->{next_content})) { |
|
604
|
0
|
|
|
|
|
|
$self->{extra_metas}->{'nav_next'} = $self->{next_content}->get_name(); |
|
605
|
|
|
|
|
|
|
} |
|
606
|
0
|
0
|
|
|
|
|
if (defined ($self->{prev_content})) { |
|
607
|
0
|
|
|
|
|
|
$self->{extra_metas}->{'nav_prev'} = $self->{prev_content}->get_name(); |
|
608
|
|
|
|
|
|
|
} |
|
609
|
|
|
|
|
|
|
} |
|
610
|
|
|
|
|
|
|
|
|
611
|
|
|
|
|
|
|
sub invalidate_cached_nav_metadata { |
|
612
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
|
613
|
0
|
|
|
|
|
|
$self->{added_nav_metas_flag} = 0; |
|
614
|
|
|
|
|
|
|
} |
|
615
|
|
|
|
|
|
|
|
|
616
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
|
617
|
|
|
|
|
|
|
|
|
618
|
|
|
|
|
|
|
sub set_navlinks_vars { |
|
619
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
|
620
|
|
|
|
|
|
|
|
|
621
|
0
|
|
|
|
|
|
foreach my $dir (qw{up prev next}) { |
|
622
|
0
|
|
|
|
|
|
my $contname = $self->{main}->curly_meta_subst |
|
623
|
|
|
|
|
|
|
($HTML::WebMake::Main::SUBST_EVAL, "this.nav_".$dir."?"); |
|
624
|
0
|
|
|
|
|
|
my ($obj, $url); |
|
625
|
|
|
|
|
|
|
|
|
626
|
0
|
0
|
|
|
|
|
if ($contname ne '') { |
|
|
|
0
|
|
|
|
|
|
|
627
|
0
|
|
|
|
|
|
$obj = $self->{main}->get_content_obj ($contname); |
|
628
|
|
|
|
|
|
|
|
|
629
|
|
|
|
|
|
|
# if we haven't got the URL for that content object in our |
|
630
|
|
|
|
|
|
|
# cache, and it hasn't been evaluated, use a symbolic one |
|
631
|
|
|
|
|
|
|
# which the make() mechanism will fix later. |
|
632
|
0
|
0
|
0
|
|
|
|
if (!defined $obj || !defined ($url = $obj->get_url()) || $url eq '') |
|
|
|
|
0
|
|
|
|
|
|
633
|
|
|
|
|
|
|
{ |
|
634
|
0
|
|
|
|
|
|
$url = $self->{main}->make_deferred_url ($contname); |
|
635
|
|
|
|
|
|
|
} |
|
636
|
|
|
|
|
|
|
|
|
637
|
|
|
|
|
|
|
# relativise it. |
|
638
|
0
|
|
|
|
|
|
$url = '$(TOP/)'.$url; |
|
639
|
|
|
|
|
|
|
|
|
640
|
0
|
0
|
|
|
|
|
if (!defined $self->{'nav_'.$dir}) { |
|
641
|
0
|
|
|
|
|
|
warn $self->as_string().": no name defined for '".$dir."'\n"; |
|
642
|
0
|
|
|
|
|
|
next; |
|
643
|
|
|
|
|
|
|
} |
|
644
|
|
|
|
|
|
|
|
|
645
|
0
|
|
|
|
|
|
$self->{main}->set_transient_content ("url", $url); |
|
646
|
0
|
|
|
|
|
|
$self->{main}->set_transient_content ("name", $contname); |
|
647
|
0
|
|
|
|
|
|
$self->{main}->set_transient_content ($dir."text", |
|
648
|
|
|
|
|
|
|
$self->navlinks_subst ($self->{'nav_'.$dir})); |
|
649
|
|
|
|
|
|
|
|
|
650
|
|
|
|
|
|
|
} elsif (defined $self->{'no_nav_'.$dir}) { # optional attribute |
|
651
|
0
|
|
|
|
|
|
$self->{main}->set_transient_content ($dir."text", |
|
652
|
|
|
|
|
|
|
$self->navlinks_subst ($self->{'no_nav_'.$dir})); |
|
653
|
|
|
|
|
|
|
|
|
654
|
|
|
|
|
|
|
} else { |
|
655
|
0
|
|
|
|
|
|
$self->{main}->set_transient_content ($dir."text", ''); |
|
656
|
|
|
|
|
|
|
} |
|
657
|
|
|
|
|
|
|
} |
|
658
|
|
|
|
|
|
|
|
|
659
|
0
|
|
|
|
|
|
$self->{main}->del_content ("name"); |
|
660
|
0
|
|
|
|
|
|
$self->{main}->del_content ("url"); |
|
661
|
|
|
|
|
|
|
} |
|
662
|
|
|
|
|
|
|
|
|
663
|
|
|
|
|
|
|
sub navlinks_subst { |
|
664
|
0
|
|
|
0
|
0
|
|
my ($self, $var) = @_; |
|
665
|
0
|
|
|
|
|
|
$self->{main}->curly_subst ($HTML::WebMake::Main::SUBST_EVAL, $var); |
|
666
|
|
|
|
|
|
|
} |
|
667
|
|
|
|
|
|
|
|
|
668
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
|
669
|
|
|
|
|
|
|
|
|
670
|
|
|
|
|
|
|
sub get_breadcrumbs_text { |
|
671
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
|
672
|
|
|
|
|
|
|
|
|
673
|
0
|
|
|
|
|
|
my $root = $self->{main}->getmapper()->get_root(); |
|
674
|
0
|
0
|
|
|
|
|
if (!defined $root) { |
|
675
|
0
|
|
|
|
|
|
warn ($self->as_string().": need a root content for !\n"); |
|
676
|
0
|
|
|
|
|
|
return ""; |
|
677
|
|
|
|
|
|
|
} |
|
678
|
|
|
|
|
|
|
|
|
679
|
|
|
|
|
|
|
# to illustrate this, let's consider this chain of contents: |
|
680
|
|
|
|
|
|
|
# TOPPAGE -> CONTENTS -> STORY -> TAILPAGE. |
|
681
|
|
|
|
|
|
|
# $self is TAILPAGE at this point. |
|
682
|
|
|
|
|
|
|
|
|
683
|
0
|
|
|
|
|
|
my @uplist = (); |
|
684
|
0
|
|
|
|
|
|
my $contname = $self->{main}->curly_subst ($HTML::WebMake::Main::SUBST_EVAL, "__MainContentName"); |
|
685
|
0
|
0
|
|
|
|
|
if (!defined $contname) { |
|
686
|
0
|
|
|
|
|
|
dbg ($self->as_string().": no mapped content on page"); |
|
687
|
0
|
|
|
|
|
|
return ""; |
|
688
|
|
|
|
|
|
|
} |
|
689
|
0
|
|
|
|
|
|
my $obj = $self->{main}->{contents}->{$contname}; |
|
690
|
0
|
0
|
|
|
|
|
if (!defined $obj) { |
|
691
|
0
|
|
|
|
|
|
dbg ($self->as_string().": cannot find mapped content \${$contname}"); |
|
692
|
0
|
|
|
|
|
|
return ""; |
|
693
|
|
|
|
|
|
|
} |
|
694
|
|
|
|
|
|
|
|
|
695
|
0
|
|
|
|
|
|
while (1) { |
|
696
|
0
|
0
|
|
|
|
|
push (@uplist, $obj); last if ($obj == $root); |
|
|
0
|
|
|
|
|
|
|
|
697
|
0
|
|
|
|
|
|
my $upobj = $obj->get_up_content(); |
|
698
|
0
|
0
|
|
|
|
|
last unless defined $upobj; |
|
699
|
0
|
0
|
|
|
|
|
last if ($upobj == $obj); |
|
700
|
0
|
|
|
|
|
|
$obj = $upobj; |
|
701
|
|
|
|
|
|
|
} |
|
702
|
|
|
|
|
|
|
# @uplist = (TAILPAGE, STORY, CONTENTS, TOPPAGE) |
|
703
|
|
|
|
|
|
|
|
|
704
|
0
|
|
|
|
|
|
@uplist = reverse @uplist; |
|
705
|
|
|
|
|
|
|
# @uplist = (TOPPAGE, STORY, CONTENTS, TAILPAGE) |
|
706
|
|
|
|
|
|
|
|
|
707
|
0
|
|
|
|
|
|
my $top = shift @uplist; |
|
708
|
|
|
|
|
|
|
# @uplist = (STORY, CONTENTS, TAILPAGE) |
|
709
|
|
|
|
|
|
|
|
|
710
|
0
|
|
|
|
|
|
my $tail = pop @uplist; |
|
711
|
|
|
|
|
|
|
# @uplist = (STORY, CONTENTS) |
|
712
|
|
|
|
|
|
|
|
|
713
|
0
|
|
|
|
|
|
my $text = ''; |
|
714
|
0
|
0
|
0
|
|
|
|
if (defined $top && defined $self->{breadcrumb_top_name}) { |
|
715
|
0
|
|
|
|
|
|
$text .= $self->cook_a_breadcrumb ($top, $self->{breadcrumb_top_name}); |
|
716
|
|
|
|
|
|
|
} |
|
717
|
0
|
|
|
|
|
|
foreach $obj (@uplist) { |
|
718
|
0
|
|
|
|
|
|
$text .= $self->cook_a_breadcrumb ($obj, $self->{breadcrumb_level_name}); |
|
719
|
|
|
|
|
|
|
} |
|
720
|
0
|
0
|
0
|
|
|
|
if (defined $tail && defined $self->{breadcrumb_tail_name}) { |
|
721
|
0
|
|
|
|
|
|
$text .= $self->cook_a_breadcrumb ($tail, $self->{breadcrumb_tail_name}); |
|
722
|
|
|
|
|
|
|
} |
|
723
|
|
|
|
|
|
|
|
|
724
|
0
|
|
|
|
|
|
$self->{main}->del_content ("name"); |
|
725
|
0
|
|
|
|
|
|
$self->{main}->del_content ("url"); |
|
726
|
0
|
|
|
|
|
|
$text; |
|
727
|
|
|
|
|
|
|
} |
|
728
|
|
|
|
|
|
|
|
|
729
|
|
|
|
|
|
|
sub cook_a_breadcrumb { |
|
730
|
0
|
|
|
0
|
0
|
|
my ($self, $obj, $linktmpl) = @_; |
|
731
|
|
|
|
|
|
|
|
|
732
|
|
|
|
|
|
|
# if we haven't got the URL for that content object in our |
|
733
|
|
|
|
|
|
|
# cache, and it hasn't been evaluated, use a symbolic one |
|
734
|
|
|
|
|
|
|
# which the make() mechanism will fix later. |
|
735
|
0
|
|
|
|
|
|
my $url; |
|
736
|
0
|
|
|
|
|
|
my $dotdots = $self->{main}->{current_subst}->{dotdots}; |
|
737
|
0
|
0
|
0
|
|
|
|
if (!defined $dotdots |
|
|
|
|
0
|
|
|
|
|
|
738
|
|
|
|
|
|
|
|| !defined ($url = $obj->get_url()) |
|
739
|
|
|
|
|
|
|
|| $url eq '') |
|
740
|
|
|
|
|
|
|
{ |
|
741
|
0
|
|
|
|
|
|
$url = $self->{main}->make_deferred_url ($obj->{name}); |
|
742
|
|
|
|
|
|
|
} else { |
|
743
|
0
|
|
|
|
|
|
$url = $dotdots.$url; |
|
744
|
|
|
|
|
|
|
} |
|
745
|
|
|
|
|
|
|
|
|
746
|
0
|
|
|
|
|
|
$self->{main}->set_transient_content ("url", $url); |
|
747
|
0
|
|
|
|
|
|
$self->{main}->set_transient_content ("name", $obj->{name}); |
|
748
|
0
|
|
|
|
|
|
return $self->{main}->curly_subst ($HTML::WebMake::Main::SUBST_EVAL, $linktmpl); |
|
749
|
|
|
|
|
|
|
} |
|
750
|
|
|
|
|
|
|
|
|
751
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
|
752
|
|
|
|
|
|
|
|
|
753
|
|
|
|
|
|
|
sub is_only_usable_from_deferred_refs { |
|
754
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
|
755
|
|
|
|
|
|
|
|
|
756
|
0
|
0
|
0
|
|
|
|
if ($self->{is_breadcrumbs} || $self->{is_navlinks}) { |
|
757
|
0
|
|
|
|
|
|
1; |
|
758
|
|
|
|
|
|
|
} else { |
|
759
|
0
|
|
|
|
|
|
0; |
|
760
|
|
|
|
|
|
|
} |
|
761
|
|
|
|
|
|
|
} |
|
762
|
|
|
|
|
|
|
|
|
763
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
|
764
|
|
|
|
|
|
|
|
|
765
|
|
|
|
|
|
|
1; |