Changeset 18

Show
Ignore:
Timestamp:
06/11/08 02:07:20 (4 months ago)
Author:
simon
Message:

Various fixes to bring us up to date, several to deal with new Maypole version.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Glob.pm

    r12 r18  
    1111        LockDirectory => "/var/lib/glob/sessionlock", 
    1212    }; 
    13 use Calendar::Simple; 
    1413use Tagtools; 
    1514 
     
    2625sub additional_data {  
    2726    my $r = shift; 
    28     if ($r->params->{format} =~ /rss|xml/) { 
     27    if ($r->params->{format} =~ /rss|xml/ and $r->model_class) { 
    2928        $r->model_class->process($r); 
    3029        my  $ja = $r->{params}{lang} eq "ja"; 
     
    3534        ); 
    3635        my @posts = @{$r->objects || []}; 
    37         if (!@posts or !$posts[0]->isa("Glob::Post")) {@posts = @{$r->{template_args}{posts}||[]}}; 
     36        if (!@posts or !( 
     37                $posts[0]->isa("Glob::Post") or $posts[0]->isa("Glob::Comment") 
     38           )) { 
     39                @posts = @{$r->{template_args}{posts}||[]} 
     40        }; 
    3841        # This is a hack 
    3942        if ($ja) { @posts = grep { $_->content_jp} @posts } 
     
    4447        for my $item (@posts) { 
    4548            my $c; 
    46             $t->process(\do {$ja ? $item->content_jp : $item->content}, {}, \$c); 
     49            if ($item->isa("Glob::Comment")) { 
     50                $c = $item->content; 
     51            } else { 
     52                $t->process(\do {$ja ? $item->content_jp : $item->content}, {}, \$c); 
     53            } 
    4754            $c ||= $t->error; 
    48             $rss->add_item( title => ($ja ? $item->title_jp : $item->title),  
    49                 link => URI->new(Glob->config->{uri_base}."post/view/".$item->id.($ja?"?lang=ja":""))->canonical, 
     55            my $title = $item->isa("Glob::Comment") ? "New comment from '".$item->author."' on '".$item->post->title."'" :($ja ? $item->title_jp : $item->title) ; 
     56            my $author = $item->can("author") ? $item->author : Glob->config->{author}; 
     57            my $postid = ($item->isa("Glob::Comment") ? $item->post->id: $item->id); 
     58            $rss->add_item( title => $title, 
     59                link => URI->new(Glob->config->{uri_base}."post/view/".$postid.($ja?"?lang=ja":""))->canonical, 
    5060                description => $c, 
    51                 author => Glob->config->{author}
     61                author => $author
    5262                dc => {  
    53                     creator => Glob->config->{author}
    54                     subject => join " ", $item->tags  
     63                    creator => $author
     64                    subject => ($item->can("tags") && join " ", $item->tags), 
    5565                }, 
    5666                pubDate => $item->posted->strftime("%a, %d %b %Y %H:%M:%S %z") 
     
    7282 
    7383use Maypole::Constants; 
    74 sub parse_path { 
     84sub preprocess_path { 
    7585    my $r = shift; 
    7686    my $p = $r->path; 
    77     if (!$p) { 
     87    if (!$p or $p eq "/") { 
    7888        $r->path("/post/recent"); 
    7989    } elsif ($p =~ /blosxom|bryar/) { # Grandfather 
     
    8393        $r->path("/post/recent"); 
    8494    } 
    85     $r->SUPER::parse_path; 
     95    $r->SUPER::preprocess_path; 
    8696} 
    8797 
     
    94104sub authenticate { 
    95105    my ($self,$r)=@_; 
     106    return DECLINED if $r->{path} =~ /plagnet/; 
    96107    return DECLINED if $r->{path} =~ /static/; 
    97108    $r->get_user(); 
     
    215226    $sm->ready(); 
    216227    my $res = $sm->test($r->params->{content}); 
    217     if ($res->is_spam) { 
     228    if ($res->is_spam or !defined $r->params->{parent}) { 
    218229        $r->content_type("text/plain"); 
    219230        $r->output("I think you're a spammer, because your comment: ". 
     231            (!$r->params->{parent} ? "doesn't contain the magic cookie\n":""). 
    220232        join("\n", $res->describe_hits)); 
    221233    return; 
     
    241253    my $self = shift; 
    242254    my $tag = "date:".$self->posted->ymd; 
    243     $self->add_to_system_tags({tag => Glob::SystemTag->find_or_create({name 
     255    $self->add_to_system_tags({system_tag => Glob::SystemTag->find_or_create({name 
    244256    =>$tag}) }); 
    245257} 
     
    254266__PACKAGE__->set_up_table("comment"); 
    255267use Class::DBI::utf8; 
     268use Class::DBI::Plugin::RetrieveAll; 
     269__PACKAGE__->retrieve_all_sort_field("posted desc"); 
    256270Glob::Comment->has_a("post" => "Glob::Post"); 
    257271Glob::Post->has_many("comments" => "Glob::Comment", {order_by => "posted"}); 
     
    260274    deflate => 'datetime', 
    261275); 
     276 
     277sub recent :Exported {  
     278    my ($self, $r) = @_; 
     279    my $it = $self->retrieve_all; 
     280    my @objs; 
     281    push @objs, $it->next for 0..19; 
     282    $r->objects(\@objs); 
     283} 
    262284 
    263285package Glob::Tag; 
     
    282304        Glob->config->{posts_per_page}, $page); 
    283305    $r->{template_args}{pager} = $pager; 
    284     if (!$r->objects) { 
     306    if (!($tag = $r->objects->[0])) { 
    285307        $tag = $self->search(name => $r->{args}->[0])->first; 
    286     } else { 
    287         $tag = $r->objects->[0]; # Should hardly happen 
     308        if (!$tag) { warn "Couldn't find a tag, even after searching" } 
    288309    } 
    289310    $r->{template_args}{tag} = $tag; 
     
    341362FROM post, system_tagging 
    342363WHERE system_tagging.post = post.id 
    343     AND system_tagging.tag = ? 
     364    AND system_tagging.system_tag = ? 
    344365ORDER BY post.posted DESC 
    345366/ 
     
    353374    $r->{template_args}{pager} = $pager; 
    354375 
    355     if (!$r->objects) { 
     376    if (!$r->objects or !$r->objects->[0]) { 
     377        warn "Looking for tag ".$r->{args}[0]; 
    356378        $tag = $self->search(name => $r->{args}->[0])->first; 
    357379    } else { 
     380        warn "Getting a tag by ID?"; 
    358381        $tag = $r->objects->[0]; # Should hardly happen 
    359382    } 
     383    warn "No tag" unless $tag; 
    360384    $r->{template_args}{tag} = $tag; 
    361385    $r->{template_args}{tags} = [$tag]; # For selector 
  • trunk/Tagtools.pm

    r15 r18  
    11package Tagtools; 
     2use warnings; 
    23use Lingua::EN::Inflect::Number qw(to_PL); 
    34use URI::Escape; 
  • trunk/templates/footer

    r9 r18  
    33    <div id="rhs"> 
    44<div class="rhstitle">Language</div> 
    5 <a href="?lang=ja"><img src="/ja.gif" alt="Japanese" title="Japanese"></a> 
    6 <a href="?lang=en"><img src="/en.gif" alt="English" title="English"></a> 
     5<a href="?lang=ja"><img src="http://static.simon-cozens.org/blog/ja.gif" alt="Japanese" title="Japanese"></a> 
     6<a href="?lang=en"><img src="http://static.simon-cozens.org/blog/en.gif" alt="English" title="English"></a> 
    77 
    88<hr> 
  • trunk/templates/header

    r13 r18  
    55        <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> 
    66        <title> Simon Cozens [%IF post; " - "; post.title |html; END %]</title> 
    7         <link rel="stylesheet" type="text/css" href="http://simon-cozens.org/style/site.css"/> 
     7        <link rel="stylesheet" type="text/css" href="http://static.simon-cozens.org/www/style/site.css"/> 
     8        <link rel="stylesheet" type="text/css" href="http://static.simon-cozens.org/www/style/niftyCorners.css"/> 
    89        <link rel="stylesheet" type="text/css" href="http://blog.simon-cozens.org/static/blog.css"/> 
    9 <meta name="ICBM" content="51.585, -0.57861"> 
     10<meta name="ICBM" content="35.3816, 136.263"> 
    1011<meta name="DC.title" content="Where Everybody's Crazy - Simon Cozens' Blog"> 
    1112<link rel="alternate" type="application/rdf+xml" title="RSS" 
     
    2728urchinTracker(); 
    2829</script> 
    29         <script type="text/javascript" src="http://simon-cozens.org/style/niftycube.js"></script> 
     30        <script type="text/javascript" src="http://static.simon-cozens.org/www/style/niftycube.js"></script> 
    3031 
    3132<script type="text/javascript"> 
     
    6061    <div id="container"> 
    6162    <div id="main"> 
     63        <p> I'm a missionary in Japan. The name of my mission agency is 
     64        WEC International. That's supposedly <a href="http://www.wec-int.org/">Worldwide 
     65            Evangelisation for Christ</a>, but I think I have a better 
     66        idea about what it stands for... 
     67        </p> 
  • trunk/templates/post/print

    r2 r18  
    22<h1> [%post.title %] </h1> 
    33[% post.content %] 
     4<hr> 
     5<p> 
     6<a href="[%base%]/post/view/[%post.id%]">Full version</a> 
     7 - [%  SET comments = post.comments; 
     8     IF comments; comments.size; ELSE; 0; END; " Comment"; "s" IF NOT 
     9     comments OR comments.size != 1; 
     10      "</A>"; 
     11%] 
     12</p> 
    413</body></html>