line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Quiki::Attachments; |
2
|
1
|
|
|
1
|
|
1158
|
use File::MMagic; |
|
1
|
|
|
|
|
20786
|
|
|
1
|
|
|
|
|
41
|
|
3
|
1
|
|
|
1
|
|
12
|
use CGI qw/:standard/; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
12
|
|
4
|
1
|
|
|
1
|
|
3726
|
use File::Slurp 'slurp'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
528
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = 0.01; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub save_attach { |
9
|
0
|
|
|
0
|
1
|
|
my ($self, $param, $out) = @_; |
10
|
0
|
0
|
|
|
|
|
open OUT, ">", $out or die "Can't create out file: $!"; |
11
|
0
|
|
|
|
|
|
my $filename = param($param); |
12
|
0
|
|
|
|
|
|
my ($buffer, $bytesread); |
13
|
0
|
|
|
|
|
|
while ($bytesread = read($filename, $buffer, 1024)) { |
14
|
0
|
|
|
|
|
|
print OUT $buffer |
15
|
|
|
|
|
|
|
} |
16
|
0
|
|
|
|
|
|
close OUT; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub list { |
21
|
0
|
|
|
0
|
1
|
|
my ($self, $node) = @_; |
22
|
0
|
|
|
|
|
|
my $folder = "data/attach/$node"; |
23
|
0
|
|
|
|
|
|
my %desc; |
24
|
|
|
|
|
|
|
my @attachs; |
25
|
0
|
|
|
|
|
|
my $mm = new File::MMagic; |
26
|
0
|
|
|
|
|
|
opendir DIR, $folder; |
27
|
0
|
|
|
|
|
|
for my $f (sort { lc($a) cmp lc($b) } readdir(DIR)) { |
|
0
|
|
|
|
|
|
|
28
|
0
|
0
|
|
|
|
|
next if $f =~ /^\.\.?$/; |
29
|
0
|
|
|
|
|
|
my $filename = "data/attach/$node/$f"; |
30
|
0
|
0
|
|
|
|
|
if ($f =~ m!_desc_(.*)!) |
31
|
|
|
|
|
|
|
{ |
32
|
0
|
|
|
|
|
|
$desc{$1} = slurp $filename |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
else |
35
|
|
|
|
|
|
|
{ |
36
|
0
|
|
|
|
|
|
my $mime = $mm->checktype_filename( $filename ); |
37
|
0
|
|
|
|
|
|
my $mimeimg = "mime_default.png"; |
38
|
0
|
0
|
|
|
|
|
$mimeimg = "mime_image.png" if $mime =~ /image/; |
39
|
0
|
0
|
|
|
|
|
$mimeimg = "mime_pdf.png" if $mime =~ /pdf/; |
40
|
0
|
0
|
|
|
|
|
$mimeimg = "mime_zip.png" if $mime =~ /zip/; |
41
|
0
|
|
|
|
|
|
push @attachs, { ID => $f, |
42
|
|
|
|
|
|
|
MIME => $mime, |
43
|
|
|
|
|
|
|
SIZE => sprintf("%.0f",((stat($filename))[7] / 1024)), |
44
|
|
|
|
|
|
|
MIMEIMG => $mimeimg }; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
0
|
|
|
|
|
|
for (@attachs) { |
48
|
0
|
|
|
|
|
|
$_->{DESC} = $desc{$_->{ID}} |
49
|
|
|
|
|
|
|
} |
50
|
0
|
|
|
|
|
|
return \@attachs; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
"42"; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=encoding UTF-8 |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 NAME |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Quiki::Attachments - Quiki attachments manager |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 SYNOPSIS |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Quiki::Attachments->list($node); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 DESCRIPTION |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
This module handles the needed operations to maintain the page |
70
|
|
|
|
|
|
|
attachments. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head2 list |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
lists specific node attachments |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head2 save_attach |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
temporary function to save attachments. Should be replaced/bettened soon. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 SEE ALSO |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Quiki, perl(1) |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 AUTHOR |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Alberto Simões, Eambs@cpan.orgE |
87
|
|
|
|
|
|
|
Nuno Carvalho, Esmash@cpan.orgE |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Copyright 2009-2010 Alberto Simoes and Nuno Carvalho. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
94
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
95
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=cut |
100
|
|
|
|
|
|
|
|