-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupload
More file actions
executable file
·173 lines (136 loc) · 4.89 KB
/
upload
File metadata and controls
executable file
·173 lines (136 loc) · 4.89 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/usr/bin/perl
use strict;
use warnings 'FATAL' => 'all';
require './modules/docmaker.ph';
require './modules/decode.subs';
require './modules/rfork.subs';
require './modules/image.subs';
our ($HOME_URL, $UPLOAD_URL, $FILE_URL, $HELP_URL, $CONTENTROOT);
our $FOLDER;
my $cg = CGObject();
my $uploadfh = $cg->upload('filebox');
UploadPage() unless $uploadfh;
# parse and unpack
my $uploadpath = $cg->tmpFileName($cg->param('filebox'));
my $info = ReadMacFile($uploadpath);
# sanity checks on unpacked data
UploadError("Sorry, your document could not be read. This site only understands files in MacBinary, BinHex, or AppleSingle format.") unless $info->{'parsed'};
my $type = $info->{'type'};
$type = 'APPL' unless defined $type;
my $creator = $info->{'creator'};
$type = 'Dk@P' unless defined $creator;
UploadError("Sorry, this doesn't look like a DOCMaker document. DOCMaker documents should have a type of 'APPL' and a creator of 'Dk\@P', but yours had '$type'/'$creator'. Make sure the document isn't compressed; we can't handle things like .sit.hqx files.") unless ($type eq 'APPL' && $creator eq 'Dk@P');
# unpack resource fork
my $rsrc = RForkToHash($info->{'resource_fork'});
UploadError("Sorry, there was a problem reading the resource data. Maybe your document is corrupted.") unless $rsrc;
# resource fork sanity checks
UploadError("Sorry, no pages could be found. Are you sure this is a DOCMaker document?") unless (exists $rsrc->{'TEXT'} && exists $rsrc->{'TEXT'}{'128'} && exists $rsrc->{'styl'} && exists $rsrc->{'styl'}{'128'});
# add to database
my ($internal_id, $permalink, $display_name) = MakeDocumentEntry($info, $rsrc, $cg->param('filebox'));
UploadError("Sorry, the document could not be saved.") unless $permalink;
# save binary
my $folder = "$CONTENTROOT/$permalink";
mkdir $folder;
$FOLDER = $folder;
my $out_fh;
open($out_fh, '>', "$folder/$permalink.bin");
WriteMacBinary($info, $out_fh);
close $out_fh;
# save icon - try custom, fall back to standard
my $iconpath = "$folder/icon.png";
IconToImage(
$rsrc->{'ICN#'}{'-16455'}{'data'},
$rsrc->{'icl8'}{'-16455'}{'data'}, $iconpath)
|| IconToImage(
$rsrc->{'ICN#'}{'128'}{'data'},
$rsrc->{'icl8'}{'128'}{'data'}, $iconpath);
my $picthtml = '';
# save included images
if (exists $rsrc->{'PICT'})
{
for my $id (sort keys %{ $rsrc->{'PICT'} })
{
next unless $id > 2000;
PictToImage($rsrc->{'PICT'}{$id}{'data'}, "$folder/pict$id.png");
$picthtml .= qq(<p>PICT $id: <img src="$FILE_URL/$permalink/pict$id.png"></p>\n);
}
}
# generate CSS/JS
open $out_fh, '>', "$folder/page.css";
print $out_fh PageCSS($rsrc);
close $out_fh;
open $out_fh, '>', "$folder/page.js";
print $out_fh PageJS($rsrc, $display_name, $permalink);
close $out_fh;
my $ptitles = PageTitles($rsrc);
for my $i (1..scalar(@$ptitles))
{
my $page_html = GenPageStart($display_name . ': ' . $ptitles->[$i - 1], "page$i");
$page_html .= <<END;
<div class="page_main page${i}_margins"><div class="page${i}_content">
@{[ StyledPage($rsrc, $i) ]}
</div></div>
END
$page_html .= GenPageEnd();
open $out_fh, '>', "$folder/" . PageLink($i);
print $out_fh $page_html;
close $out_fh;
}
chdir $CONTENTROOT;
`zip -r $permalink/$permalink-html.zip $permalink -x $permalink/$permalink.bin`;
UnlockDocument($internal_id);
Redirect("$FILE_URL/$permalink/");
sub UploadError
{
my ($msg) = @_;
my $html = <<END;
<div class="textwall">
<h2>Sorry, a system error occurred.</h2>
<p>
$msg
See our <a href="$HELP_URL">help page</a> for advice on common problems.
</p>
<p>
<a href="$UPLOAD_URL">Try again,</a>
or return to the
<a href="$HOME_URL">home page</a>.
</p>
</div>
END
DoPage({ 'Title' => 'Upload Failed', 'CSS' => <<END }, $html);
DIV#content {
max-width: 980px;
margin-left: auto;
margin-right: auto;
}
END
exit;
}
sub UploadPage
{
my $html = <<END;
<div class="textwall">
<h2>Share your documents.</h2>
<p>Add a DOCMaker document below:</p>
<form enctype="multipart/form-data" method="POST" action="$UPLOAD_URL" class="uploadform">
<div class="ring">
<input type="file" id="filebox" name="filebox">
<input type="submit" name="submit" value="Upload">
</div></form>
<p><b>Is it in the right format?</b> To preserve the Mac-specific info that makes up a DOCMaker document, the file must be packed up in MacBinary, BinHex, or AppleSingle format. There are several classic Mac tools that can help you package up the document before you upload it. The file must NOT be compressed in StuffIt, Compact Pro, or other compression schemes.</p>
<p style="padding-left: 24px; margin-bottom: 0"><b>Good formats:</b> my-doc.bin, my-doc.hqx</p>
<p style="padding-left: 24px"><b>Bad formats:</b> my-doc.sit, my-doc.sit.bin, my-doc.bin.hqx</p>
<p>
See our <a href="$HELP_URL">help page</a> if you run into problems.
</p>
</div>
END
DoPage({ 'Title' => 'DOCMaker Library: Share', 'CSS' => <<END }, $html);
DIV#content {
max-width: 980px;
margin-left: auto;
margin-right: auto;
}
END
exit;
}