about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2014-05-05 00:47:41 +0000
committerEric Wong <e@80x24.org>2014-05-05 00:47:41 +0000
commitefdeec171349d5793f5af78c31f4b2d0c80a7ec8 (patch)
tree72733315d25803fd800a9ff8ae50440b736496c4 /lib
parentec1d0105e6f758ced83902b92b25df0c4b75613d (diff)
downloadpublic-inbox-efdeec171349d5793f5af78c31f4b2d0c80a7ec8.tar.gz
Some advertising is necessary.
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/Feed.pm2
-rw-r--r--lib/PublicInbox/View.pm6
-rw-r--r--lib/PublicInbox/WWW.pm74
3 files changed, 77 insertions, 5 deletions
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 = "<hr /><pre>$footer</pre>" if $footer;
         $html . "</pre>$footer</html>";
 }
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) .
                 '</pre><hr /><pre>' .
-                html_footer($mime) .
+                html_footer($mime) . $footer .
                 '</pre></body></html>';
 }
 
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 <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;