chiark / gitweb /
cfa0f263b1bf952787f5355855e3c5fa7faed762
[odin-cgi] / mason / pastebin / %show
1 <&| SELF:wrapper,
2         title => Odin::escapify($m, $title) . " (odin.gg Paste Bin)" &>
3 <h1><tt>odin.gg</tt> Paste Bin: <% $title %></h1>
4 <div class="menu">
5   <span class="item"><a href="<% "$Odin::PASTEBIN/$tag?op=raw" |h %>">Raw</a></span>
6 % if (defined $edit) {
7   <span class="item"><a href="<% "$Odin::PASTEBIN/$tag?edit=$edit" |h %>">Edit</a></span>
8 % }
9   <span class="item"><a href="<% "$Odin::PASTEBIN/" |h %>">New</a></span>
10 </div>
11 % if (defined $honc) {
12 <div class="note">
13 <p>Your browser doesn't appear to be accepting my cookies.
14 <p>Don't share the link to this page with other people.  <b>If you do,
15   they'll be able to edit this paste just as you can</b>, using the
16   <b>Edit</b> link at the top of the page.
17 <p>Instead, share this link:
18   <a href="<% "$Odin::PASTEBIN/$tag" |h %>"><%
19     "$Odin::PASTEBIN/$tag" |h %></a>
20 </div>
21 % }
22 % if ($lang eq 'txt') {
23 <pre class="paste">
24 <% $content |h %>\
25 </pre>
26 % } elsif ($lang =~ /^hl:(.*)$/) {
27 <pre class="paste">
28 % filter "highlight", $m, $content,
29 %   "highlight", "-Ohtml", "-f", "-t8", "-S$1";
30 </pre>
31 % } else {
32 <div class="note">
33 <p>I don't know how to display content with language
34   &lsquo;<% $lang |h %>&rsquo;.  This is a bug in the Pastebin program.
35   Here's the raw text, in case that's useful.
36 </div>
37 <pre class="paste">
38 <% $content |h %>\
39 </pre>
40 % }
41 </&>
42 %#
43 <%args>
44         $content
45         $title
46         $lang
47         $tag
48         $honc
49         $edit
50 </%args>
51 %#
52 <%init>
53         my $db = Odin::open_db;
54 </%init>
55 %#
56 <%once>
57         use utf8;
58
59         sub filter ($$$@) {
60           my ($what, $m, $content, @cmd) = @_;
61           my $kid = open my $fh, "-|" // die "fork: $!";
62           if ($kid == 0) {
63             open my $hl, "|-", @cmd or die "open $what: $!";
64             syswrite $hl, $content // die "$what write: $!";
65             close $hl or die "$what kid: $!, $?";
66             exit 0;
67           } else {
68             while (sysread $fh, my $buf, 8192) { $m->print($buf); }
69             close $fh and waitpid $kid, 0
70               or die "$what parent: $!, $?";
71           }
72         }
73 </%once>