FrontPage 差分 一覧 ソース 検索 ヘルプ ログイン

FSWiki TodaysLink PlugInのソース

!!!FSWiki TodaysLink PlugIn
{{category others}}

----

3.4.xのTodaysLinkのバグ修正及び
TodayだけでなくYesterdayのrefererも監視するように変更。
さらに検索エンジンからのrefererに関しては検索キーワードのみを抽出。

*http://chinmai.net/~osakana/diary/?200311a#07-3

 --- TodaysLink.pm-orig	Wed Jul 23 21:25:26 2003
 +++ TodaysLink.pm	Fri Nov  7 16:07:27 2003
 @@ -53,13 +53,20 @@
  	$month += 1;
  	my $today =sprintf("%04d/%02d/%02d",$year,$month,$mday);
  
 +	$time = $time - 86400;
 +	($sec,$min,$hour,$mday,$month,$year,$wday) = localtime($time);
 +	$year += 1900;
 +	$month += 1;
 +	my $yesterday =sprintf("%04d/%02d/%02d",$year,$month,$mday);
 +	
 +
  	my $count={};
  	#logを走査
  	open(LOG,$wiki->config('log_dir')."/".$wiki->config('access_log_file')) or return "";
  	while(my $line=<LOG>){
  		chomp $line;
  		my ($page,$date,$time,$ip,$ref,$ua) = split(/ /,$line);
 -		if($date =~ /$today/){
 +		if(($date =~ /$today/) or ($date =~ /$yesterday/)){
  		    $count->{$ref}++;
  		}
  	}
 @@ -95,10 +102,17 @@
  		my $refcount=$count->{$ref};
  		
  		if($way ne "H" && $way ne "h"){
 -			my $decodeurl = Util::url_decode($ref);
 -			&Jcode::convert(\$ref,"euc");
 -			$buf .= "<li><a href=\"".Util::escapeHTML($ref)."\">".Util::escapeHTML($decodeurl)."</a>".
 -			        "($refcount)</li>\n";
 +
 +			my $found = &getsearchkey($ref);
 +			if ($found ne "") {
 +				$buf .= "<li><a href=\"".Util::escapeHTML($ref)."\">".
 +					&Jcode::convert(\$found,"euc")."</a>"."($refcount)</li>\n";
 +			} else {
 +				my $decodeurl = Util::url_decode($ref);
 +				&Jcode::convert(\$decodeurl,"euc");
 +				$buf .= "<li><a href=\"".Util::escapeHTML($ref)."\">".
 +					Util::escapeHTML($decodeurl)."</a>"."($refcount)</li>\n";
 +			}
  		}else{
  			$buf .= "|" unless ($i==0);
  			$buf .= "<a href=\"$ref\">$refcount</a>";
 @@ -115,4 +129,48 @@
  	}
  	return $buf;
  }
 +
 +sub getsearchkey {
 +  local( $referer ) = shift;
 +  local( $found );
 +
 +  $_ = $referer;
 +  $found = "";
 +  if ( /[?&]MT=([^&]+)/o )          { $found .= " $1"; }  # www.hotbot.com, www.goo.ne.jp, search.msn.com, search.msn.co.jp, 
 +  if ( /[?&]p=([^&]+)/o )           { $found .= " $1"; }  # ink.yahoo.com, search.yahoo.co.jp, google.yahoo.co.jp
 +  if ( /[?&]qt=([^&]+)/o )          { $found .= " $1"; }  # www.infoseek.co.jp, cnet.com/search/, 
 +  if ( /[?&]query=([^&]+)/o )       { $found .= " $1"; }  # www.lycos.co.jp, 
 +  if ( /[?&]key=([^&]+)/o )         { $found .= " $1"; }  # odin.ingrid.org, kensaku.org, 
 +  if ( /[?&]s=([^&]+)/o )           { $found .= " $1"; }  # www.excite.co.jp, 
 +  if ( /[?&]search=([^&]+)/o )      { $found .= " $1"; }  # www.excite.co.jp, netscape.com/search, 
 +  if ( /[?&]q=([^&]+)/o )           { $found .= " $1"; }  # www.altavista.com, www.technobahn.com, suche.fireball.de, www.e-sekai.com/, www.google.com, www.google.co.jp,
 +  if ( /[?&]as_q=([^&]+)/o )        { $found .= " $1"; }  # www.google.co.jp,
 +  if ( /[?&]kw=([^&]+)/o )          { $found .= " $1"; }  # search.fresheye.com,
 +  if ( /[?&]keyword=([^&]+)/o )     { $found .= " $1"; }  # snap.com/search/,
 +  if ( /[?&]Keywords=([^&]+)/o )    { $found .= " $1"; }  # www.goto.com/d/search/, 
 +  if ( /[?&]QueryString=([^&]+)/o ) { $found .= " $1"; }  # search.odn.ne.jp, 
 +  if ( /[?&]FI_1=([^&]+)/o ) {
 +    $found .= " $1";                                  # www.excite.co.jp, 
 +    if ( /[?&]FI_2=([^&]+)/o ) { $found .= " $1"; }
 +    if ( /[?&]FI_3=([^&]+)/o ) { $found .= " $1"; }
 +    if ( /[?&]FI_4=([^&]+)/o ) { $found .= " $1"; }
 +    if ( /[?&]FI_5=([^&]+)/o ) { $found .= " $1"; }
 +    if ( /[?&]FI_6=([^&]+)/o ) { $found .= " $1"; }
 +  }
 +  if ( /[?&]AW0=([^&]+)/o ) {
 +    $found .= " $1";                                  # www.hotbot.com, 
 +    if ( /[?&]AW1=([^&]+)/o )   { $found .= " $1"; }
 +    if ( /[?&]AW2=([^&]+)/o )   { $found .= " $1"; }
 +    if ( /[?&]AW3=([^&]+)/o )   { $found .= " $1"; }
 +    if ( /[?&]AW4=([^&]+)/o )   { $found .= " $1"; }
 +    if ( /[?&]AW5=([^&]+)/o )   { $found .= " $1"; }
 +  }
 +  $found =~ s/^ //o;
 +  $found =~ s/%([0-9a-fA-F][0-9a-fA-F])/pack("C", hex($1))/ego;
 +  if ($found =~ /^cache:[^\+]*\+(.*)$/) {
 +	$found = "$1 (Google cache)";
 +  }
 +  return ( $found );
 +}
 +
  1;


----
以下、obsolete


3.4.xのTodaysLinkのバグ修正及び
TodayだけでなくYesterdayのrefererも監視するように変更。

*http://chinmai.net/~osakana/diary/?200309c#23-2

 --- TodaysLink.pm-old	Wed Jul 23 21:25:26 2003
 +++ TodaysLink.pm	Tue Sep 23 00:36:56 2003
 @@ -53,13 +53,19 @@
  	$month += 1;
  	my $today =sprintf("%04d/%02d/%02d",$year,$month,$mday);
 
 +	$time = $time - 86400;
 +	($sec,$min,$hour,$mday,$month,$year,$wday) = localtime($time);
 +	$year += 1900;
 +	$month += 1;
 +	my $yesterday =sprintf("%04d/%02d/%02d",$year,$month,$mday);
 +
  	my $count={};
  	#logを走査
  	open(LOG,$wiki->config('log_dir')."/".$wiki->config('access_log_file')) or return "";
  	while(my $line=<LOG>){
  		chomp $line;
  		my ($page,$date,$time,$ip,$ref,$ua) = split(/ /,$line);
 -		if($date =~ /$today/){
 +		if(($date =~ /$today/) or ($date =~ /$yesterday/)){
  		    $count->{$ref}++;
  		}
  	}
 @@ -96,7 +102,7 @@
  		
  		if($way ne "H" && $way ne "h"){
  			my $decodeurl = Util::url_decode($ref);
 -			&Jcode::convert(\$ref,"euc");
 +			&Jcode::convert(\$decodeurl,"euc");
  			$buf .= "<li><a href=\"".Util::escapeHTML($ref)."\">".Util::escapeHTML($decodeurl)."</a>".
  			        "($refcount)</li>\n";
  		}else{