Repository navigation
Expand file tree
/
Copy pathDynamicText.pm
More file actions
108 lines (73 loc) · 1.94 KB
/
Copy pathDynamicText.pm
File metadata and controls
108 lines (73 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package WebComponent::DynamicText;
use strict;
use warnings;
use base qw( WebComponent );
1;
=pod
=head1 NAME
DynamicText - component to import a blob of externally edited text into a web page
=head1 DESCRIPTION
WebComponent to import a blob of externally edited text into a web page
=head1 METHODS
=over 4
=item * B<new> ()
Called when the object is initialized. Expands SUPER::new.
=cut
sub new {
my $self = shift->SUPER::new(@_);
$self->{default_text} = "";
$self->{blob_name} = undef;
return $self;
}
=item * B<output> ()
Returns the html output of the DynamicText component.
=cut
sub output {
my ($self) = @_;
# check if we have a blob name
unless (defined($self->blob_name)) {
return "Error: using DynamicText without a blob name";
}
# get some objects we nee
my $application = $self->application;
my $master = $application->dbmaster;
my $user = $application->session->user;
my $text = "";
# look for the file containing the text
if (open(FH, "./Html/blob_".$self->blob_name)) {
my $link = undef;
while (<FH>) {
if ($link) {
$text .= $_;
} else {
$link = $_;
}
}
close FH;
# check if the current user has the preference set to see
# the edit link
if (defined($user) && $user->has_right($application, 'edit', 'user', '*')) {
my $show_edit_link_prefs = $master->Preferences->get_objects( { user => $user, name => 'show_dynamic_text_edit_link' } );
if (scalar(@$show_edit_link_prefs) && $show_edit_link_prefs->[0]->value) {
$text = "<a href='".$link."' target=_blank>Edit this text</a><br>".$text;
}
}
} else {
$text = $self->default_text;
}
return $text;
}
sub blob_name {
my ($self, $name) = @_;
if (defined($name)) {
$self->{blob_name} = $name;
}
return $self->{blob_name};
}
sub default_text {
my ($self, $text) = @_;
if (defined($text)) {
$self->{default_text} = $text;
}
return $self->{default_text};
}