Created
October 12, 2017 02:29
-
-
Save afresh1/d3e92c49de013edecfe9a00c92eb7a8c to your computer and use it in GitHub Desktop.
blogsum as a Plack app
This file contains 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 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; | |
rewrite_rule $env, qr{^/rss.xml$}, sub { | |
$env->{QUERY_STRING} .= "&rss=1"; | |
}; | |
rewrite_rule $env, qr{^/rss2.xml$}, sub { | |
$env->{QUERY_STRING} .= "&rss=2"; | |
}; | |
rewrite_rule $env, qr{^/Page/([^/]+)/?$}, sub { | |
$env->{QUERY_STRING} .= "&page=$1"; | |
}; | |
rewrite_rule $env, qr{^/Tags/([^/]+)/?$}, sub { | |
$env->{QUERY_STRING} .= "&search=$1"; | |
}; | |
rewrite_rule $env, qr{^/([0-9]{4})/([0-9]{2})/([^/]+)$}, sub { | |
$env->{QUERY_STRING} .= "view=article&year=$1&month=$2&uri=$3"; | |
}; | |
rewrite_rule $env, qr{^/([0-9]{4})/([0-9]{2})/?$}, sub { | |
$env->{QUERY_STRING} .= "view=article&year=$1&month=$2"; | |
}; | |
rewrite_rule $env, qr{^/([0-9]{4})/?$}, sub { | |
$env->{QUERY_STRING} .= "view=article&year=$1"; | |
}; | |
$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 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