-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComment.pm
More file actions
102 lines (79 loc) · 1.83 KB
/
Comment.pm
File metadata and controls
102 lines (79 loc) · 1.83 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
# -*- Mode: perl; indent-tabs-mode: nil -*-
# Copyright(c) 2003-2007 Robert L. Brown. This is licensed software
# only to be used with an explicit right-to-use license from the
# copyright holder.
package Comment;
use strict;
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $VERSION);
require Exporter;
$VERSION = 1.00;
@ISA = qw(Exporter);
@EXPORT = qw(
);
@EXPORT_OK = qw(); # Symbols to export on request
use CGI qw(:standard *table *ol *ul *Tr *td escape *p);
use Login;
use Database;
use Argcvt;
use Layout;
use Utility;
use CommentTable;
my $metaData = \%::CommentTable;
sub getTable
{
return $metaData;
}
sub getTableName
{
return $metaData->{'table'};
}
##
sub addConverter {
my $cvtlist = shift;
$cvtlist->{'comment.comment'} = \&Comment::convert_comment;
$cvtlist->{'candidate.comment'} = \&Comment::convert_candidate;
}
sub convert_candidate
{
my $value = shift;
my $rec = Comment::getRecord($value);
if ( !defined $rec ) {
return "#$value (deleted)";
} else {
return Comment::link($value) . ": " . convert_comment($rec->{'comment'});
}
}
sub convert_comment
{
my $value = shift;
my $comment_length = shift || 25;
if ( length($value) > $comment_length ) {
return substr($value, 0, $comment_length) . " . . .";
}
return $value;
}
sub link
{
my $value = shift;
my $url = Layout::fullURL("candidates.cgi") . "?op=viewcomment;id=$value";
return a({-href=>$url}, $value);
}
##
## Caching routines
##
my %cache;
sub getRecord
{
my $id = shift;
if ( !exists $cache{$id} ) {
my $comment = getRecordById({
-table=>\%::CommentTable,
-id=>$id,
});
$cache{$id} = $comment;
} else {
Database::addQueryComment("cache hit Comment $id");
}
return $cache{$id};
}
1;