From efdeec171349d5793f5af78c31f4b2d0c80a7ec8 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 5 May 2014 00:47:41 +0000 Subject: www: add footers to HTML index and message views Some advertising is necessary. --- lib/PublicInbox/Feed.pm | 2 ++ lib/PublicInbox/View.pm | 6 ++-- lib/PublicInbox/WWW.pm | 74 +++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 77 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/PublicInbox/Feed.pm b/lib/PublicInbox/Feed.pm index 6996f374..fcb86023 100644 --- a/lib/PublicInbox/Feed.pm +++ b/lib/PublicInbox/Feed.pm @@ -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 = "
$footer
" if $footer; $html . "$footer"; } diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm index 674d7b7c..5870c9d1 100644 --- a/lib/PublicInbox/View.pm +++ b/lib/PublicInbox/View.pm @@ -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) . '
' .
-		html_footer($mime) .
+		html_footer($mime) . $footer .
 		'
'; } diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm index 898f42a8..1d1a0c9d 100644 --- a/lib/PublicInbox/WWW.pm +++ b/lib/PublicInbox/WWW.pm @@ -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 ssoma: ' . $urls[0]; + } else { + $urls = 'git archive URLs for ssoma:\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 = "$addr"; + $desc = $desc; + join("\n", + '- ' . $desc, + 'This is a public-inbox, '. + "anybody may post:", + "\t$addr (text-only, no HTML please)", + $urls + ); +} + 1; -- cgit v1.2.3-24-ge0c7