Commit | Line | Data |
---|---|---|
128543b0 MW |
1 | %# -*-html-*- |
2 | %# | |
3 | %# Pastebin display webservice for Odin | |
4 | %# | |
5 | %# (c) 2015 Mark Wooding | |
6 | %# | |
7 | %#----- Licensing notice ---------------------------------------------------- | |
8 | %# | |
9 | %# This file is part of the `odin.gg' service, `odin-cgi'. | |
10 | %# | |
11 | %# `odin-cgi' is free software; you can redistribute it and/or modify | |
12 | %# it under the terms of the GNU Affero General Public License as | |
13 | %# published by the Free Software Foundation; either version 3 of the | |
14 | %# License, or (at your option) any later version. | |
15 | %# | |
16 | %# `odin-cgi' is distributed in the hope that it will be useful, | |
17 | %# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | %# GNU Affero General Public License for more details. | |
20 | %# | |
21 | %# You should have received a copy of the GNU Affero General Public | |
22 | %# License along with `odin-cgi'; if not, see | |
23 | %# <http://www.gnu.org/licenses/>. | |
24 | %# | |
be24e9af MW |
25 | <&| SELF:wrapper, |
26 | title => Odin::escapify($m, $title) . " (odin.gg Paste Bin)" &> | |
27 | <h1><tt>odin.gg</tt> Paste Bin: <% $title %></h1> | |
28 | <div class="menu"> | |
7e455e62 | 29 | <span class="item"><a href="<% "$Odin::PASTEBIN/$tag?op=raw" |h %>">Raw</a></span> |
be24e9af | 30 | % if (defined $edit) { |
7e455e62 | 31 | <span class="item"><a href="<% "$Odin::PASTEBIN/$tag?edit=$edit" |h %>">Edit</a></span> |
be24e9af | 32 | % } |
7f77ead8 | 33 | <span class="item"><a href="<% "$Odin::PASTEBIN/" |h %>">New</a></span> |
be24e9af | 34 | </div> |
7e455e62 MW |
35 | % if (defined $honc) { |
36 | <div class="note"> | |
37 | <p>Your browser doesn't appear to be accepting my cookies. | |
38 | <p>Don't share the link to this page with other people. <b>If you do, | |
39 | they'll be able to edit this paste just as you can</b>, using the | |
40 | <b>Edit</b> link at the top of the page. | |
41 | <p>Instead, share this link: | |
42 | <a href="<% "$Odin::PASTEBIN/$tag" |h %>"><% | |
43 | "$Odin::PASTEBIN/$tag" |h %></a> | |
44 | </div> | |
45 | % } | |
be24e9af | 46 | % if ($lang eq 'txt') { |
969db1ef | 47 | <pre class="paste"> |
be24e9af | 48 | <% $content |h %>\ |
969db1ef MW |
49 | </pre> |
50 | % } elsif ($lang =~ /^hl:(.*)$/) { | |
51 | <pre class="paste"> | |
b16468fb MW |
52 | % filter "highlight", $m, $content, |
53 | % "highlight", "-Ohtml", "-f", "-t8", "-S$1"; | |
be24e9af | 54 | </pre> |
bc6d34b0 MW |
55 | % } elsif ($lang eq "md") { |
56 | % filter "markdown", $m, $content, | |
57 | % "markdown", "-fnohtml,autolink,safelink,footnote"; | |
969db1ef MW |
58 | % } else { |
59 | <div class="note"> | |
60 | <p>I don't know how to display content with language | |
61 | ‘<% $lang |h %>’. This is a bug in the Pastebin program. | |
62 | Here's the raw text, in case that's useful. | |
63 | </div> | |
64 | <pre class="paste"> | |
65 | <% $content |h %>\ | |
66 | </pre> | |
67 | % } | |
be24e9af MW |
68 | </&> |
69 | %# | |
70 | <%args> | |
71 | $content | |
72 | $title | |
73 | $lang | |
74 | $tag | |
7e455e62 | 75 | $honc |
73961354 | 76 | $edit |
be24e9af MW |
77 | </%args> |
78 | %# | |
79 | <%init> | |
80 | my $db = Odin::open_db; | |
81 | </%init> | |
82 | %# | |
83 | <%once> | |
84 | use utf8; | |
b16468fb MW |
85 | |
86 | sub filter ($$$@) { | |
87 | my ($what, $m, $content, @cmd) = @_; | |
88 | my $kid = open my $fh, "-|" // die "fork: $!"; | |
89 | if ($kid == 0) { | |
90 | open my $hl, "|-", @cmd or die "open $what: $!"; | |
91 | syswrite $hl, $content // die "$what write: $!"; | |
92 | close $hl or die "$what kid: $!, $?"; | |
93 | exit 0; | |
94 | } else { | |
95 | while (sysread $fh, my $buf, 8192) { $m->print($buf); } | |
96 | close $fh and waitpid $kid, 0 | |
97 | or die "$what parent: $!, $?"; | |
98 | } | |
99 | } | |
be24e9af | 100 | </%once> |