[ 新規 ] [ 検索 | 一覧 | FrontPage ] [ 履歴 (RSS) | 差分履歴 (RSS) ] [ ログイン ]
【PR】Amazon | SL-C3000 | SL-C1000(3/18発売!) | SL-C860 | SL-6000W | SL-6000L | SL-6000N

WalWiki/カスタマイズ/ページ毎アクセスカウンタ

差分表示


編集前の状態に戻します。
ページ毎のアクセス数をカウントし、記録します。

- 2003-08-28 (Thu) 09:27:44 当日のアクセス数を表示できるように改良
- 2004-04-14 (Wed) 00:23:35 昨日のアクセス数を表示できるように改良
* [page access counter]

アクセス数は[[このように AccessCounts]]表示されます。

** 関連するカスタマイズ

[[WalWiki/カスタマイズ/汎用サブルーチン]] の format_time()
** resource.txtへの追加

,total,合計
** グローバル変数定義

 my $AccessCounts = 'AccessCounts';                          # yakty add [page access counter]

 my $ignore_access_interval = 1*60*60*24;                    # yakty add [page acesss counter]

 # yakty add [page access counter] start
 my $info_AccessCount = 'AccessCount';
 my $info_AccessToday = 'AccessToday';
 my $info_AccessYesterday = 'AccessYesterday';
 my $info_AccessTimeStamp = 'AccessTimeStamp';
 my $info_AccessRemoteAddr = 'AccessRemoteAddr';
 my $info_AccessReferer = 'AccessReferer';
 # yakty add [page access counter] end

** %fixedpage への追加

 my %fixedpage = (
     $IndexPage => 1,
     $CreatePage => 1,
     $ErrorPage => 1,
     $RssPage => 1,
     $RecentChanges => 1,
     $SearchPage => 1,
     $AdminChangePassword => 1,
     $CompletedSuccessfully => 1,
     $FrontPage => 1,
     $AccessCounts => 1,                 # yakty add [page access counter]
 );

** %page_command への追加

 my %page_command = (
     $IndexPage => 'index',
     $SearchPage => 'searchform',
     $CreatePage => 'create',
     $RssPage => 'rss',
     $AdminChangePassword => 'adminchangepasswordform',
     $FrontPage => 'FrontPage',
     $AccessCounts => 'counter',                             # yakty add [page access counter]
 );

** %command_do への追加

 my %command_do = (
     read => \&do_read,
     edit => \&do_edit,
     adminedit => \&do_adminedit,
     adminchangepasswordform => \&do_adminchangepasswordform,
     adminchangepassword => \&do_adminchangepassword,
     write => \&do_write,
     index => \&do_index,
     searchform => \&do_searchform,
     search => \&do_search,
     create => \&do_create,
     createresult => \&do_createresult,
     FrontPage => \&do_FrontPage,
     comment => \&do_comment,
     rss => \&do_rss,
     diff => \&do_diff,
     interwikibox => \&do_interwiki_box, # Walrus add [InterWikiBox]
     counter => \&do_counterpage,                            # yakty add [page access counter]
 );

** update_accesscounts()追加

-2003-08-28 (Thu) 13:21:27 WikiNameが有効な場合に存在しないページがカウントされてしまうのを抑制

 # yakty add [page access counter] start
 sub update_accesscounts
 {
     return if(&valid_password($form{mypassword}));
     return unless(&is_exist_page($form{mypage}) or $fixedpage{$form{mypage}});
 
     my $timestamp = &get_info($form{mypage}, $info_AccessTimeStamp);
     return if(time - $timestamp <= $ignore_access_interval
                 and length($ENV{REMOTE_ADDR}) > 0
                 and $ENV{REMOTE_ADDR} eq &get_info($form{mypage}, $info_AccessRemoteAddr));
 
     # total count
     my $count = 0 + &get_info($form{mypage}, $info_AccessCount);
     $count++;
 
     # today's count
     my $datetime = &get_now;
     $datetime =~ /^(\d\d\d\d\-\d\d\-\d\d)/;
     my $today = $1;
     $datetime = &format_time(gmtime($timestamp + $modifier_time_offset));
     $datetime = &format_time(gmtime(time - 24*60*60 + $modifier_time_offset));
     $datetime =~ /^(\d\d\d\d\-\d\d\-\d\d)/;
     my $yesterday = $1;
 
     my $lastaccess = &format_time(gmtime($timestamp + $modifier_time_offset));
     my $todayscount = 0;
     if($datetime =~ /^\Q$today\E/){
     my $yesterdayscount = -1;
     if($lastaccess =~ /^\Q$today\E/){
         $todayscount = &get_info($form{mypage}, $info_AccessToday);
     } elsif($lastaccess =~ /^\Q$yesterday\E/){
     	$yesterdayscount = &get_info($form{mypage}, $info_AccessToday);
     } else {
     	$yesterdayscount = 0;
     }
     $todayscount++;
 
     &set_info($form{mypage}, $info_AccessYesterday, $yesterdayscount) if($yesterdayscount >= 0);
     &set_info($form{mypage}, $info_AccessCount, $count);
     &set_info($form{mypage}, $info_AccessToday, $todayscount);
     &set_info($form{mypage}, $info_AccessRemoteAddr, $ENV{REMOTE_ADDR});
     &set_info($form{mypage}, $info_AccessTimeStamp, time);
     &set_info($form{mypage}, $info_AccessReferer, $ENV{HTTP_REFERER});
 }
 # yakty add [page access counter] end

** do_counterpage()追加

- 2003-08-28 (Thu) 13:15:40 RecentChangesは表示しないように変更

 # yakty add [page access counter] start
 sub do_counterpage
 {
     my @data;
     my $total = 0;
     my $todaystotal = 0;
     my $yesterdaystotal = 0;
     my $datetime = &get_now;
     $datetime =~ /^(\d\d\d\d\-\d\d\-\d\d)/;
     my $today = $1;
     $datetime = &format_time(gmtime(time - 24*60*60 + $modifier_time_offset));
     $datetime =~ /^(\d\d\d\d\-\d\d\-\d\d)/;
     my $yesterday = $1;
     foreach my $name (keys %infobase){
         next if($name eq $RecentChanges);
         my $count = 0 + &get_info($name, $info_AccessCount);
         next if($count == 0);
         my $referer = &get_info($name, $info_AccessReferer);
         my $timestamp = &get_info($name, $info_AccessTimeStamp);
         my $lastaccess = &format_time(gmtime($timestamp + $modifier_time_offset));
         my $todayscount = ($lastaccess =~ /^\Q$today\E/) ? 0 + &get_info($name, $info_AccessToday) : 0;
         #my $todayscount = ($lastaccess =~ /^\Q$today\E/) ? 0 + &get_info($name, $info_AccessToday) : 0;
         my $todayscount = 0;
         my $yesterdayscount = 0;
         if($lastaccess =~ /^\Q$today\E/){
         	$todayscount = 0 + &get_info($name, $info_AccessToday);
         	$yesterdayscount = 0 + &get_info($name, $info_AccessYesterday);
         } elsif($lastaccess =~ /^\Q$yesterday\E/){
         	$yesterdayscount = 0 + &get_info($name, $info_AccessToday);
         }
         push(@data,
             {
                 page => $name,
                 count => $count,
                 referer => $referer,
                 timestamp => $timestamp,
                 lastaccess => $lastaccess,
                 todayscount => $todayscount,
                 yesterdayscount => $yesterdayscount,
             });
         $total += $count;
         $todaystotal += $todayscount;
         $yesterdaystotal += $yesterdayscount;
     }
     my @counts;
     foreach my $ref (sort {$b->{count} <=> $a->{count} or $a->{page} cmp $b->{page}} @data){
         #my $text = ",@{[&armor_name($ref->{page})]}, $ref->{count}";
         my $text = ",@{[&armor_name($ref->{page})]}, $ref->{todayscount}, $ref->{count}, $ref->{lastaccess}";
         my $text = qq(,"@{[&armor_name($ref->{page})]}", $ref->{todayscount}, $ref->{yesterdayscount}, $ref->{count}, $ref->{lastaccess});
         #$text .= ",@{[&format_time(gmtime($ref->{timestamp} + $modifier_time_offset))]}";
         if(&valid_password($form{mypassword})){
             $text .= ",@{[&escape($ref->{referer})]}";
             $text .= qq(,"@{[&escape($ref->{referer})]}");
         }
         push(@counts, $text);
     }
     push(@counts, ",$resource{total}, $todaystotal, $total");
     push(@counts, ",$resource{total}, $todaystotal, $yesterdaystotal, $total");
     &print_header($AccessCounts);
     &print_content(join("\n", @counts));
     &print_footer($AccessCounts);
 }
 # yakty add [page access counter] end

** do_read()内の変更

     &update_accesscounts if($form{mycmd} eq 'read');        # yakty add [page access counter]
     &print_header($form{mypage});
     &print_content($database{$form{mypage}});
     &print_footer($form{mypage});

** print_footer()内の変更

 sub print_footer {
     my ($page) = @_;
     # Walrus add [modify footer] start
     $walrus_log = &make_log;            # Walrus add [for debug]
     my $mod_info = $modifier_name ? qq(Modified by <a href="$modifier_url">$modifier_name</a>.) : '';
     # yakty add [page access counter] start
     my $count = 0 + &get_info($form{mypage}, $info_AccessCount);
     my $counter;
     if($count > 0){
         $counter = qq(<div class="counter">@{[sprintf("%05d", $count)]}</div>);
     }
     # yakty add [page access counter] end
     print <<"EOD";
 <hr />
 <address class="footer">
     <a href="http://digit.que.ne.jp/work/">WalWiki</a> $walversion &copy; 2000-2002 by <a href="http://digit.que.ne.jp/">Makio Tsukamoto</a>.<br />
     based on <a href="http://www.hyuki.com/yukiwiki/">YukiWiki</a> $version &copy; 2000-2002 by <a href="http://www.hyuki.com/">Hiroshi Yuki</a>.<br />
     $mod_info
 </address>
 <p class="footer">
     <a href="http://digit.que.ne.jp/work/">$icontag</a>
     $counter<!-- yakty add [page access counter] -->
 </p>


04160