line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Blikistan::MagicEngine::PerlSite; |
2
|
1
|
|
|
1
|
|
1841
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
3
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
4
|
1
|
|
|
1
|
|
6
|
use base 'Blikistan::MagicEngine::TT2'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
128
|
|
5
|
|
|
|
|
|
|
use base 'Blikistan::MagicEngine::YamlConfig'; |
6
|
|
|
|
|
|
|
use URI::Escape; |
7
|
|
|
|
|
|
|
use JSON; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Blikistan::MagicEngine::PerlSite |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 SYNOPSIS |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use Blikistan; |
16
|
|
|
|
|
|
|
my $b = Blikistan->new( |
17
|
|
|
|
|
|
|
magic_engine => 'perlSite', |
18
|
|
|
|
|
|
|
rester => $rester, |
19
|
|
|
|
|
|
|
magic_opts => \%magic_opts, |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 DESCRIPTION |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
MagicEngine for Blikistan designed for presenting Wiki content as a web 1.0 website. |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=cut |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub print_blog { |
29
|
|
|
|
|
|
|
my $self = shift; |
30
|
|
|
|
|
|
|
my $r = $self->{rester}; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my $params = $self->load_config($r); |
33
|
|
|
|
|
|
|
$params->{rester} = $r; |
34
|
|
|
|
|
|
|
$params->{blog_tag} ||= $self->{blog_tag}; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my $page = $self->{subpage} || $params->{start_page}; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# Need to get the metadata here |
39
|
|
|
|
|
|
|
$r->accept('application/json'); |
40
|
|
|
|
|
|
|
my $return = _get_page($r, $page); |
41
|
|
|
|
|
|
|
my $page_obj = jsonToObj($return); |
42
|
|
|
|
|
|
|
my $page_name = $page_obj->{name}; |
43
|
|
|
|
|
|
|
my $page_uri = $page_obj->{page_uri}; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# If we're searching, do the search thing |
46
|
|
|
|
|
|
|
$r->accept('text/html'); |
47
|
|
|
|
|
|
|
my $nav = _get_page($r, |
48
|
|
|
|
|
|
|
$params->{nav_page}, |
49
|
|
|
|
|
|
|
$params->{base_uri}, |
50
|
|
|
|
|
|
|
$page_uri); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
my ($page_content); |
53
|
|
|
|
|
|
|
if ( $self->{search} ) { |
54
|
|
|
|
|
|
|
$page_content = _search($r, |
55
|
|
|
|
|
|
|
$self->{search}, |
56
|
|
|
|
|
|
|
$params->{base_uri}, |
57
|
|
|
|
|
|
|
'search'); |
58
|
|
|
|
|
|
|
} else { |
59
|
|
|
|
|
|
|
$page_content = _get_page($r, |
60
|
|
|
|
|
|
|
$page, |
61
|
|
|
|
|
|
|
$params->{base_uri}, |
62
|
|
|
|
|
|
|
$page_uri); |
63
|
|
|
|
|
|
|
$page_content = "$page_name\n$page_content"; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
$params->{nav} = $nav; |
67
|
|
|
|
|
|
|
$params->{page} = $page_content; |
68
|
|
|
|
|
|
|
return $self->render_template( $params ); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub _fix_links { |
72
|
|
|
|
|
|
|
my $r = shift; |
73
|
|
|
|
|
|
|
my $base_uri = shift; |
74
|
|
|
|
|
|
|
my $page_uri = shift; |
75
|
|
|
|
|
|
|
my $page_content = shift; |
76
|
|
|
|
|
|
|
my $return; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
$base_uri =~ s#/hydra##g; |
79
|
|
|
|
|
|
|
# Interesting pieces of the page URI |
80
|
|
|
|
|
|
|
my ($server_uri, $workspace, $page_name) = |
81
|
|
|
|
|
|
|
($page_uri =~ m#(https?://[^/]+)/([^/]+)/.*\?(.*)$#); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# Now we can build the internal REST links |
84
|
|
|
|
|
|
|
my $rest_page_uri = "/data/workspaces/$workspace/pages/"; |
85
|
|
|
|
|
|
|
my @links = ($page_content =~ m/href=["']([^'"]+)["']/g); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
foreach my $link (@links) { |
88
|
|
|
|
|
|
|
if ( $link =~ m#^[^/]+$# ) { |
89
|
|
|
|
|
|
|
$page_content =~ s/href=(.)$link/href=$1$base_uri$link/g; |
90
|
|
|
|
|
|
|
} elsif ( $link =~ m/^$rest_page_uri/ ) { |
91
|
|
|
|
|
|
|
$page_content =~ s/$rest_page_uri/$base_uri/g; |
92
|
|
|
|
|
|
|
} elsif ( $link =~ m/^pages/ ) { |
93
|
|
|
|
|
|
|
$page_content =~ s/href='pages\//href='$base_uri/g; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
my %seen; |
98
|
|
|
|
|
|
|
my @image_links = ($page_content =~ m/src=["']([^'"]+)["']/g); |
99
|
|
|
|
|
|
|
foreach my $link (@image_links) { |
100
|
|
|
|
|
|
|
next if $seen{$link}++; |
101
|
|
|
|
|
|
|
if ( $link =~ m/attachments/ ) { |
102
|
|
|
|
|
|
|
$page_content =~ s/$link/$server_uri\/$link/g; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
else { |
105
|
|
|
|
|
|
|
warn "$link has no attachments\n"; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
return $page_content; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub _search { |
112
|
|
|
|
|
|
|
my $r = shift; |
113
|
|
|
|
|
|
|
my $query_string = shift; |
114
|
|
|
|
|
|
|
my $base_uri = shift; |
115
|
|
|
|
|
|
|
my $page_uri = shift; |
116
|
|
|
|
|
|
|
$r->accept('text/html'); |
117
|
|
|
|
|
|
|
$r->query($query_string); |
118
|
|
|
|
|
|
|
my $return = $r->get_pages(); |
119
|
|
|
|
|
|
|
$return = _fix_links ($r, |
120
|
|
|
|
|
|
|
$base_uri, |
121
|
|
|
|
|
|
|
$page_uri, |
122
|
|
|
|
|
|
|
$return); |
123
|
|
|
|
|
|
|
return $return; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub _get_page { |
127
|
|
|
|
|
|
|
my $r = shift; |
128
|
|
|
|
|
|
|
my $page_name = shift; |
129
|
|
|
|
|
|
|
my $base_uri = shift; |
130
|
|
|
|
|
|
|
my $page_uri = shift; |
131
|
|
|
|
|
|
|
my $html = $r->get_page($page_name) || ''; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
$html =~ s#^ (.+) \s*$#$1#s; |
134
|
|
|
|
|
|
|
$html = _fix_links ($r, |
135
|
|
|
|
|
|
|
$base_uri, |
136
|
|
|
|
|
|
|
$page_uri, |
137
|
|
|
|
|
|
|
$html); |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
return $html; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 AUTHOR |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Kirsten L. Jones<< >> |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Copyright 2006 Kirsten L. Jones, all rights reserved. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
151
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=cut |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
1; |
156
|
|
|
|
|
|
|
|