Last active
October 15, 2017 05:38
-
-
Save afresh1/bc9318482a9fdba74b99823b4c120be3 to your computer and use it in GitHub Desktop.
blogsum as a Plack app - https://github.com/obfuscurity/blogsum - https://metacpan.org/pod/Plack - Patches needed due to CGI::Compile: https://metacpan.org/pod/CGI::Compile#CAVEATS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env plackup | |
use strict; | |
use warnings; | |
use Plack::Builder; | |
use Plack::App::File; | |
use Plack::App::WrapCGI; | |
BEGIN { | |
chdir "/var/www/blogsum" or die "Unable to chdir: $!"; | |
require "./startup.pl"; | |
} | |
use lib '.'; | |
my $themes = Plack::App::File->new( root => "themes" )->to_app; | |
my $index = Plack::App::WrapCGI->new(script => "index.cgi")->to_app; | |
my $admin = Plack::App::WrapCGI->new(script => "admin.cgi")->to_app; | |
sub rewrite_rule ($$$) { | |
my ($env, $match, $action) = @_; | |
$action->($env) if $env->{PATH_INFO} =~ s{$match}{}; | |
} | |
sub rewrite { my $app = shift; sub { | |
my $env = shift; | |
# http doesn't supply this | |
$env->{PATH_INFO} ||= $env->{SCRIPT_NAME}; | |
# Plack debug doesn't like this | |
$env->{SCRIPT_NAME} = ''; | |
rewrite_rule $env, qr{^/rss(2)?.xml$}, sub { | |
$env->{QUERY_STRING} .= "&rss=" . ( $1 || 1 ); | |
}; | |
rewrite_rule $env, qr{^/(Page|Tags)/([^/]+)/?$}, sub { | |
my ($type, $args) = ( lc($1), $2 ); | |
$type = 'search' if $type eq 'tags'; | |
$env->{QUERY_STRING} .= "&$type=$args"; | |
}; | |
rewrite_rule $env, qr{^ | |
/(?<year>[0-9]{4}) # four digit year | |
(?: /(?<month>[0-9]{2}) # two digit month | |
(?:/(?<uri>[^/]+))? # uri (maybe) | |
)? # maybe a month or uri | |
/? # maybe a trailing / | |
$}x, sub { | |
my $qs = "&view=article&year=$+{year}"; | |
$qs .= "&month=$+{month}" if exists $+{month}; | |
$qs .= "&uri=$+{uri}" if defined $+{uri}; | |
$env->{QUERY_STRING} .= $qs | |
}; | |
$env->{PATH_INFO} = '/index.cgi' if $env->{PATH_INFO} eq '/'; | |
$env->{PATH_INFO} ||= '/index.cgi' ; | |
return $app->($env); | |
} } | |
builder { | |
enable \&rewrite; | |
mount "/themes" => $themes; | |
mount "/admin.cgi" => $admin; | |
mount "/index.cgi" => $index; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- admin.cgi.orig Wed Oct 11 18:32:23 2017 | |
+++ admin.cgi Wed Oct 11 18:32:52 2017 | |
@@ -8,19 +8,19 @@ | |
########################### | |
use strict; | |
use Blogsum::Config; | |
-my $database = $Blogsum::Config::database; | |
-my $blog_theme = $Blogsum::Config::blog_theme; | |
-my $blog_title = $Blogsum::Config::blog_title; | |
+our $database = $Blogsum::Config::database; | |
+our $blog_theme = $Blogsum::Config::blog_theme; | |
+our $blog_title = $Blogsum::Config::blog_title; | |
########################### | |
# main execution # | |
########################### | |
-my $cgi = CGI->new; | |
-my $dbh = DBI->connect("DBI:SQLite:dbname=$database", '', '', { RaiseError => 1 }) || die $DBI::errstr; | |
-my $template = HTML::Template->new(filename => "themes/${blog_theme}/admin.tmpl", die_on_bad_params => 0); | |
+our $cgi = CGI->new; | |
+our $dbh = DBI->connect("DBI:SQLite:dbname=$database", '', '', { RaiseError => 1 }) || die $DBI::errstr; | |
+our $template = HTML::Template->new(filename => "themes/${blog_theme}/admin.tmpl", die_on_bad_params => 0); | |
$template->param( theme => $blog_theme ); | |
-my $view; | |
+our $view; | |
if ($cgi->param('view')) { | |
if ($cgi->param('view') eq 'moderate') { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- index.cgi.orig Wed Oct 11 17:10:44 2017 | |
+++ index.cgi Wed Oct 11 19:22:20 2017 | |
@@ -9,33 +9,33 @@ | |
########################### | |
use strict; | |
use Blogsum::Config; | |
-my $database = $Blogsum::Config::database; | |
-my $blog_theme = $Blogsum::Config::blog_theme; | |
-my $blog_title = $Blogsum::Config::blog_title; | |
-my $blog_subtitle = $Blogsum::Config::blog_subtitle; | |
-my $blog_url = $Blogsum::Config::blog_url; | |
+our $database = $Blogsum::Config::database; | |
+our $blog_theme = $Blogsum::Config::blog_theme; | |
+our $blog_title = $Blogsum::Config::blog_title; | |
+our $blog_subtitle = $Blogsum::Config::blog_subtitle; | |
+our $blog_url = $Blogsum::Config::blog_url; | |
$blog_url .= '/' unless ($blog_url =~ /^.*\/$/); | |
-my $blog_owner = $Blogsum::Config::blog_owner; | |
-my $blog_rights = $Blogsum::Config::blog_rights; | |
-my $feed_updates = $Blogsum::Config::feed_updates; | |
-my $captcha_pubkey = $Blogsum::Config::captcha_pubkey; | |
-my $captcha_seckey = $Blogsum::Config::captcha_seckey; | |
-my $comment_max_length = $Blogsum::Config::comment_max_length; | |
-my $comments_allowed = $Blogsum::Config::comments_allowed; | |
-my $smtp_server = $Blogsum::Config::smtp_server; | |
-my $smtp_sender = $Blogsum::Config::smtp_sender; | |
-my $articles_per_page = $Blogsum::Config::articles_per_page; | |
-my $google_analytics_id = $Blogsum::Config::google_analytics_id; | |
-my $google_webmaster_id = $Blogsum::Config::google_webmaster_id; | |
-my $max_tags_in_cloud = $Blogsum::Config::max_tags_in_cloud; | |
+our $blog_owner = $Blogsum::Config::blog_owner; | |
+our $blog_rights = $Blogsum::Config::blog_rights; | |
+our $feed_updates = $Blogsum::Config::feed_updates; | |
+our $captcha_pubkey = $Blogsum::Config::captcha_pubkey; | |
+our $captcha_seckey = $Blogsum::Config::captcha_seckey; | |
+our $comment_max_length = $Blogsum::Config::comment_max_length; | |
+our $comments_allowed = $Blogsum::Config::comments_allowed; | |
+our $smtp_server = $Blogsum::Config::smtp_server; | |
+our $smtp_sender = $Blogsum::Config::smtp_sender; | |
+our $articles_per_page = $Blogsum::Config::articles_per_page; | |
+our $google_analytics_id = $Blogsum::Config::google_analytics_id; | |
+our $google_webmaster_id = $Blogsum::Config::google_webmaster_id; | |
+our $max_tags_in_cloud = $Blogsum::Config::max_tags_in_cloud; | |
########################### | |
# main execution # | |
########################### | |
-my $cgi = CGI->new; | |
-my $dbh = DBI->connect("DBI:SQLite:dbname=$database", '', '', { RaiseError => 1 }) || die $DBI::errstr; | |
-my $template = HTML::Template->new(filename => "themes/${blog_theme}/index.tmpl", die_on_bad_params => 0); | |
+our $cgi = CGI->new; | |
+our $dbh = DBI->connect("DBI:SQLite:dbname=$database", '', '', { RaiseError => 1 }) || die $DBI::errstr; | |
+our $template = HTML::Template->new(filename => "themes/${blog_theme}/index.tmpl", die_on_bad_params => 0); | |
if ($cgi->param('rss')) { | |
output_rss(); | |
} else { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment