]> Sergey Matveev's repositories - public-inbox.git/commitdiff
www: add footers to HTML index and message views
authorEric Wong <e@80x24.org>
Mon, 5 May 2014 00:47:41 +0000 (00:47 +0000)
committerEric Wong <e@80x24.org>
Mon, 5 May 2014 00:47:41 +0000 (00:47 +0000)
Some advertising is necessary.

lib/PublicInbox/Feed.pm
lib/PublicInbox/View.pm
lib/PublicInbox/WWW.pm

index 6996f374e555a4f55d565fda80fe3b119369e3b0..fcb860236686276c9c9f639dbaa3307fc4c50560 100644 (file)
@@ -89,6 +89,8 @@ sub generate_html_index {
        Email::Address->purge_cache;
 
        my $footer = nav_footer($args->{cgi}, $last);
+       my $list_footer = $args->{footer};
+       $footer .= "\n" . $list_footer if ($footer && $list_footer);
        $footer = "<hr /><pre>$footer</pre>" if $footer;
        $html . "</pre>$footer</html>";
 }
index 674d7b7cdfb73c77172c59485dea33c60908d3f7..5870c9d1ad3099ca857f0ab2d6966a2f16cf95d9 100644 (file)
@@ -20,12 +20,12 @@ my $enc_mime = find_encoding('MIME-Header');
 
 # public functions:
 sub msg_html {
-       my ($class, $mime, $full_pfx) = @_;
-
+       my ($class, $mime, $full_pfx, $footer) = @_;
+       $footer = '' unless defined $footer;
        headers_to_html_header($mime, $full_pfx) .
                multipart_text_as_html($mime, $full_pfx) .
                '</pre><hr /><pre>' .
-               html_footer($mime) .
+               html_footer($mime) . $footer .
                '</pre></body></html>';
 }
 
index 898f42a8c56379ab48bfde3ad34ca11f97a32bd8..1d1a0c9d468fae37e509e6a0a4c9ddcb1cc232c4 100644 (file)
@@ -13,6 +13,8 @@ use strict;
 use warnings;
 use PublicInbox::Config;
 use URI::Escape qw(uri_escape_utf8 uri_unescape);
+use constant SSOMA_URL => 'http://ssoma.public-inbox.org/';
+use constant PI_URL => 'http://public-inbox.org/';
 our $LISTNAME_RE = qr!\A/([\w\.\-]+)!;
 our $pi_config;
 BEGIN {
@@ -119,6 +121,7 @@ sub get_index {
                        listname => $ctx->{listname},
                        pi_config => $pi_config,
                        cgi => $cgi,
+                       footer => footer($ctx),
                        top => $top,
                }) ]
        ];
@@ -164,9 +167,10 @@ sub get_mid_html {
        my $mid_href = PublicInbox::Hval::ascii_html(
                                                uri_escape_utf8($ctx->{mid}));
        my $pfx = "../f/$mid_href.html";
+       my $foot = footer($ctx);
        require Email::MIME;
        [ 200, [ 'Content-Type' => 'text/html; charset=UTF-8' ],
-               [ PublicInbox::View->msg_html(Email::MIME->new($x), $pfx) ] ];
+         [ PublicInbox::View->msg_html(Email::MIME->new($x), $pfx, $foot) ] ];
 }
 
 # /$LISTNAME/f/$MESSAGE_ID.html                   -> HTML content (fullquotes)
@@ -176,8 +180,9 @@ sub get_full_html {
        return r404() unless $x;
        require PublicInbox::View;
        require Email::MIME;
+       my $foot = footer($ctx);
        [ 200, [ 'Content-Type' => 'text/html' ],
-               [ PublicInbox::View->msg_html(Email::MIME->new($x))] ];
+         [ PublicInbox::View->msg_html(Email::MIME->new($x), undef, $foot)] ];
 }
 
 sub self_url {
@@ -205,4 +210,69 @@ sub do_redirect {
        ]
 }
 
+sub ctx_get {
+       my ($ctx, $key) = @_;
+       my $val = $ctx->{$key};
+       (defined $val && length $val) or die "BUG: bad ctx, $key unusable\n";
+       $val;
+}
+
+sub try_cat {
+       my ($path) = @_;
+       my $rv;
+       if (open(my $fh, '<', $path)) {
+               local $/;
+               $rv = <$fh>;
+               close $fh;
+       }
+       $rv;
+}
+
+sub footer {
+       my ($ctx) = @_;
+       return '' unless $ctx;
+       my $git_dir = ctx_get($ctx, 'git_dir');
+
+       # favor user-supplied footer
+       my $footer = try_cat("$git_dir/public-inbox/footer.html");
+       if (defined $footer) {
+               chomp $footer;
+               return $footer;
+       }
+
+       # auto-generate a footer
+       my $listname = ctx_get($ctx, 'listname');
+       my $desc = try_cat("$git_dir/description");
+       $desc = '$GIT_DIR/description missing' unless defined $desc;
+       chomp $desc;
+
+       my $urls = try_cat("$git_dir/cloneurl");
+       my @urls = split(/\r?\n/, $urls || '');
+       my $nurls = scalar @urls;
+       if ($nurls == 0) {
+               $urls = '($GIT_DIR/cloneurl missing)';
+       } elsif ($nurls == 1) {
+               $urls = 'git archive URL for <a href="' . SSOMA_URL .
+                       '">ssoma</a>: ' . $urls[0];
+       } else {
+               $urls = 'git archive URLs for <a href="' . SSOMA_URL .
+                       "\">ssoma</a>:\n" . join('', map { "\t" . $_ } @urls);
+       }
+
+       my $addr = $pi_config->get($listname, 'address');
+       if (ref($addr) eq 'ARRAY') {
+               $addr = $addr->[0]; # first address is primary
+       }
+
+       $addr = "<a href=\"mailto:$addr\">$addr</a>";
+       $desc =  $desc;
+       join("\n",
+               '- ' . $desc,
+               'This is a <a href="' . PI_URL . '">public-inbox</a>, '.
+               "anybody may post:",
+               "\t$addr (text-only, no HTML please)",
+               $urls
+       );
+}
+
 1;