OSDN Git Service

minimum error check on template file can not find
[keitairc/keitairc.git] / t / 02_Plugins / 01index
1 # -*- mode: perl; coding: utf-8 -*-
2 # $Id: 01index,v 1.1 2008-08-02 18:35:54 morimoto Exp $
3 # $Source: /home/ishikawa/work/keitairc/tmp/keitairc/t/02_Plugins/01index,v $
4
5 # WARNING: This file is a part of Keitairc::Plugins test suite, not
6 # actual working code.
7
8 $plugin = {
9         name => 'index',
10         action_imprementation => sub {
11                 my ($request, $name, $session_id, $param_string) = @_;
12
13                 ::send_message($request);
14
15                 my $unread_channels = 0;
16                 my $accesskey = 1;
17
18                 my $format_mtime = sub{
19                         use encoding 'utf8';
20                         my $mtime = shift;
21                         return if($mtime <= 0);
22                         my $timediff = time - $mtime;
23                         if($timediff < 60){
24                                 return $timediff . '秒';
25                         }
26                         if($timediff < 3600){
27                                 return int($timediff/60) . '分';
28                         }
29                         if($timediff < 86400){
30                                 return int($timediff/3600) . '時間';
31                         }
32                         if($timediff < 86400 * 30){
33                                 return int($timediff/86400) . '日';
34                         }
35                         if($timediff < 86400 * 365){
36                                 return int($timediff/86400/30) . 'ヶ月';
37                         }
38                         return int($timediff/86400/365) . '年';
39                         no encoding 'utf8';
40                 };
41
42                 my @loop;
43                 for my $cid ($::ib->channels()){
44                         my $p = {};
45                         my $channel = $::ib->cid2name($cid);
46                         my $cname = $::ib->simple_escape(encode($::cf->web_charset(), $::ib->compact_channel_name($cid)));
47                         if($accesskey < 10){
48                                 $p->{link} =
49                                         sprintf('<a accesskey="%1d" href="all/%d">[%1d] %s</a>',
50                                                 $accesskey,
51                                                 $cid,
52                                                 $accesskey,
53                                                 $cname);
54                         }else{
55                                 $p->{link} =
56                                         sprintf('<a href="all/%d">&nbsp;&nbsp;&nbsp; %s</a>',
57                                                 $cid, $cname);
58                         }
59                         $accesskey++;
60
61                         # 未読行数
62                         if($::ib->unread_lines($cid)){
63                                 $p->{unread} =
64                                         sprintf(' <a href="unread/%d">%s</a>',
65                                                 $cid,
66                                                 $::ib->unread_lines($cid));
67                                 $unread_channels++;
68                         }
69
70                         $p->{mtime} = Encode::encode($::cf->web_charset(), $format_mtime->($::ib->mtime($cid)));
71                         push @loop, $p;
72                 }
73
74                 my $ci = new Keitairc::ClientInfo($request);
75                 my $view = new Keitairc::View($::cf, $ci);
76                 return $view->render('index.html',
77                                      {
78                                              loop => \@loop,
79                                              unread => $unread_channels,
80                                      });
81         }
82 };
83
84 1;