[SimBot-commits] CVS: simbot/plugins httpd.pl,1.18,1.19 sqlite-logger.pl,1.53,1.54
Status: Abandoned
Brought to you by:
kstange
|
From: Pete P. <fou...@us...> - 2005-08-11 15:25:49
|
Update of /cvsroot/simbot/simbot/plugins In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19971/plugins Modified Files: httpd.pl sqlite-logger.pl Log Message: - bold and underline now work in the irc log - colors simply need to be added to the css and they'll work too - httpd will now happily serve CSS files in the templates/css directory. They should be named similarly to templates, so a request for main.css will use main.local.css if it exists, otherwise it'll use main.default.css. - Moved the CSS from the base template to an external file. Index: httpd.pl =================================================================== RCS file: /cvsroot/simbot/simbot/plugins/httpd.pl,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -p -r1.18 -r1.19 --- httpd.pl 11 Aug 2005 13:39:31 -0000 1.18 +++ httpd.pl 11 Aug 2005 15:25:29 -0000 1.19 @@ -53,7 +53,7 @@ sub index_handler { my $response = HTTP::Response->new(200); - my ($req_root) = $request->uri =~ m|^/([^\?]*)|; + my ($req_root) = $request->uri =~ m|^/([^/\?]*)|; &SimBot::debug(3, 'httpd: handling request for ' . $request->uri . ", req root $req_root\n"); my $code = 500; # An error by default. @@ -72,7 +72,9 @@ sub index_handler { foreach my $url (keys %SimBot::hash_plugin_httpd_pages) { my $title = $SimBot::hash_plugin_httpd_pages{$url}->{'title'}; - $msg .= qq(<li><a href="$url">$title</a></li>\n); + if(defined $title) { + $msg .= qq(<li><a href="$url">$title</a></li>\n); + } } $msg .= "</ul>\n"; @@ -205,6 +207,37 @@ sub admin_page { return RC_OK; } +sub serve_css { + my ($request, $response) = @_; + + my ($filename) = $request->uri =~ m{/css/([^/]+)$}; + # should be something like main.css + + $filename =~ s/\.css$//; + # now is something like main + + if(!defined $filename) { return RC_FORBIDDEN; } + # (user didn't ask for anything and we're unwilling to give a list) + + if(-r "templates/css/${filename}.local.css") { + $filename = "templates/css/${filename}.local.css"; + } elsif( -r "templates/css/${filename}.default.css") { + $filename = "templates/css/${filename}.default.css"; + } else { + return RC_NOT_FOUND; + } + + { + local $/; + open(IN, $filename) or return RC_INTERNAL_SERVER_ERROR; + my $content = <IN>; + $response->push_header("Content-Type", "text/css"); + $response->content($content); + close IN; + } + return RC_OK; +} + sub messup_httpd { if(defined &SimBot::option('plugin.httpd', 'admin_user') && length &SimBot::option('plugin.httpd', 'admin_user') > 4 @@ -216,6 +249,7 @@ sub messup_httpd { 'handler' => \&admin_page, }; } + $SimBot::hash_plugin_httpd_pages{'css'} = { 'handler' => \&serve_css, }; } sub cleanup_httpd { Index: sqlite-logger.pl =================================================================== RCS file: /cvsroot/simbot/simbot/plugins/sqlite-logger.pl,v retrieving revision 1.53 retrieving revision 1.54 diff -u -d -p -r1.53 -r1.54 --- sqlite-logger.pl 10 Aug 2005 19:26:52 -0000 1.53 +++ sqlite-logger.pl 11 Aug 2005 15:25:29 -0000 1.54 @@ -31,6 +31,7 @@ package SimBot::plugin::sqlite::logger; use warnings; use strict; +use Data::Dumper; use Time::Local; use HTML::Entities; @@ -943,9 +944,68 @@ sub create_query_hash { } sub linkify { - my @words = split(/\s+/, $_[0]); - my $curWord; + my $line = $_[0]; + + my $bold = 0; + my $reverse = 0; + my $underline = 0; + my $color = 16; + my $bgcolor = 16; + my $tag = ''; + + while(my @codes = $line =~ m/(?:&#(2|3|15|22|31);)+/) { + my $block = $&; + foreach my $code (@codes) { + if ($code == 2) { + $bold = 1 - $bold; + } elsif ($code == 31) { + $underline = 1 - $underline; + } elsif ($code == 22) { + $reverse = 1 - $reverse; + } elsif ($code == 3) { + $line =~ m/(\d{1,2})?(,(\d{1,2}))?/; + if ($2) { + $color = $1 if $1; + $bgcolor = $3; + $line =~ s/\003$1$2/\003/; + } elsif ($1) { + $color = $1; + $line =~ s/\003$1/\003/; + } else { + $color = 16; + $bgcolor = 16; + } + } else { + $bold = 0; + $underline = 0; + $reverse = 0; + $color = 16; + $bgcolor = 16; + } + } #end foreach code + + if ($tag =~ /<span/) { + $tag = "</span>"; + } else { + $tag = ''; + } + my $class = + ($bold ? 'bold ' : '') + . ($underline ? 'uline ' : '') + . ($reverse ? 'reverse ' + : ($color != 16 ? "color$color " : '') + . ($bgcolor != 16 ? "bgcolor$color " : '') + ); + + $tag .= "<span class=\"$class\">" if ($class ne ""); + $line =~ s/$block/$tag/; + } # end while blocks + $line .= "</span>" if ($tag =~ /<span/); + + my @words = split(/\s+/, $line); + my $curWord; + foreach $curWord (@words) { # remove things that commonly surround URLs my ($word_prefix, $word, $word_suffix) = $curWord |