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

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

編集

ページ毎のアクセス数をカウントし、記録します。

[page access counter]

編集

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

関連するカスタマイズ

編集

汎用サブルーチン の 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()追加

編集
# 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(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;
    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()追加

編集
# 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 = 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 = 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 .= qq(,"@{[&escape($ref->{referer})]}");
        }
        push(@counts, $text);
    }
    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>

03697