# disp_referrer.rb $Revision$ # -pv- # # 名称: # 本日のリンク元強化プラグイン # # 概要: # 本日のリンク元でサーチエンジンの検索文字の文字化けを直します。 # また、サーチエンジンの検索結果を他のリンク元の下にまとめて表示します # (デフォルト時)。 # なお、tDiary-1.5.x専用です。 # # 使い方: # 文字化けを直すのみ(表示はtDiaryの標準時と同様の並びにする)の場合は、 # tdiary.confに以下を追加してください。 # @options['disp_referrer.old'] = true # # 制限: # EUC-JPで表現できない文字は表示できません。 # # その他: # http://tdiary-users.sourceforge.jp/cgi-bin/wiki.cgi?disp_referrer%2Erb # を参照してください。 # # 著作権について: # Copyright (C) 2002 MUTOH Masao # You can redistribute it and/or modify it under GPL2. # =begin ChangeLog 2002-12-04 TADA Tadashi * document update. 2002-10-13 MUTOH Masao * Metcha SearchのURLが間違えていたのを修正。 2002-10-12 MUTOH Masao * 「その他」が付く場合に、検索エンジン名の後ろに「:」が付かない不具合の修正(pointed out by TADA Tadashi ) * goo検索改善 * version 2.3.1 2002-10-11 MUTOH Masao * @options['disp_referrer.cols']追加。1つの検索エンジンで表示するカラム数を指定できるようにした(デフォルト10件)。 カラムを超えた場合は、その他にまとめて表示される。 * 検索時の繰り返し処理で全てのリンク元を走査し終わったらループを抜けるようなロジックを追加。 これにより、頻度の低い検索エンジンを追加しても速度的にさほど差が出ないようになった。 * TOCC/Search、Metcha Search、metacrawler検索、DOGPILE検索、NAXEARCH、overture検索、 looksmart検索、i won_Search、EarthLink検索、About検索追加 * Yahoo!、AOL、Google、 Biglobe、Infoseek、Fresheye、Netscape検索改善 * version 2.3.0 2002-10-07 Junichiro Kita * add @options['disp_referrer.search_table'] 2002-10-07 TADA Tadashi * for tDiary 1.5.0.20021003. 2002-09-09 MUTOH Masao * ロボットよけが効いていない不具合の修正(pointed out by TADA Tadashi) * 検索キーワードが複数回ある場合の「x2」「x3」を、リンクの外に出した(proposed by TADA Tadashi) * Web.escapeHTML()の処理が1カ所抜けていたので追加 * version 2.2.2 2002-09-08 MUTOH Masao * escapeモジュールがweb/ディレクトリ配下にインストールされる場合に対応 Pointed out by Junichiro KITA . * tDiary-1.5.xで動作しなくなっていたバグの修正 Fixed by Junichiro KITA . * version 2.2.1 2002-09-04 MUTOH Masao * 高速化。アルゴリズム見直しおよび、fastesc導入。当社比(?)で実行時間を半分以下(45%程度)に削減できた。 * Netscape検索改善 * version 2.2.0 2002-08-30 MUTOH Masao * @options['disp_referrer.deny_user_agents']追加。ロボットよけに用いる。 ロボットよけはreferer_of_today_(short|long)のどちらでも行うようにした。 デフォルトでGoogle, Goo, Hatena Antennaに対応。 (Proposed by TADA Tadashi) * @options["disp_referrer.table"]追加。検索結果ではなく通常のリンク元も検索結果部分同様 サイト単位でまとめることができる。指定方法も検索テーブルと同様。 * 全ての検索結果にリンクを貼るようにした。 (Proposed by TADA Tadashi) * 検索結果の方もヒット数の多い順にソートするようにした。 * Netscape, Fresheye対応 * Google, MSN表示改善 2002-08-22 TADA Tadashi * support AlltheWeb search. * support tDiary 1.5 HTML. 2002-08-21 TADA Tadashi * support tDiary 1.5. 2002-08-08 MUTOH Masao * 検索結果の表示方法を変更。各検索エンジン毎に検索文字列を表示するようにした * 更新時は整形しないようにした(smbdさん要望) * 出力HTMLを改善 * AOL検索追加 * Lycos検索改善 * version 2.1.0 2002-08-07 MUTOH Masao * 表示対象のずれの修正 * version 2.0.1 2002-08-06 MUTOH Masao * google, Yahoo, Infoseek, Lycos, goo, OCN, excite, msn, BIGLOBE, ODN, DIONからの検索結果を、同アクセス数単位でリンク一覧の 下側にまとめて表示するようにした。従来の表示結果にしたい場合は @options['disp_referrer.old'] = trueを設定する。 * version 2.0.0 2002-07-24 MUTOH Masao * alltheweb対応 * jp.aol.com, aol.com対応 * 文字列変換の順序を変更 * version 1.1.0 2002-07-20 MUTOH Masao * version 1.0.0 =end require 'uconv' require 'nkf' begin require 'escape' rescue LoadError begin require 'web/escape' end end eval(< 0 if all_num < 0 or all_num > a_row_ref.size a_row_max = a_row_ref.size else a_row_max = all_num end refs -= a_row_ref a_row += a_row_ref[0...a_row_max].collect{|item| sum += item[0] query = "" str = diary.disp_referer([regval], item[1]) str = "/" if str.size == 0 query << Web.escapeHTML(str) << "" query << " x" << item[0].to_s if item[0] > 1 [item[0], query] } if a_row_ref.size >= a_row_max a_row_ref[a_row_max...a_row_ref.size].each {|item| sum += item[0] etc_sum += item[0] } end end end a_row.sort!{|a, b| -(a[0] <=> b[0])} a_row = a_row[0...all_num] if a_row and a_row.size > all_num and all_num > 0 div = ":" if etc_sum > 0 if all_num > 0 a_row << [0, "その他 x#{etc_sum}"] else a_row << [0, " "] div = "" end end if a_row and a_row.size > 0 result << [sum, %Q[
  • #{sum} #{Web.escapeHTML(title[0])} #{div} #{a_row.collect{|item| item[1]}.join(", ")}
  • \n]] end end [result, refs] end def referer_of_today_long(diary, limit) return '' if not diary or diary.count_referers == 0 or disp_referrer_antibot? search_table = [ [["Google検索","http://www.google.com/"], ["^http://.*(216.239|google).*q=([^&]*).*", "\\2"]], [["Yahoo検索","http://www.yahoo.co.jp/"], ["^http://.*.yahoo.*?p=([^&]*).*", "\\1"]], [["Infoseek検索","http://www.infoseek.co.jp/"], ["^http://.*infoseek.*?qt=([^&]*).*", "\\1"]], [["Lycos検索","http://www.lycos.co.jp/"], ["^http://.*lycos.*/.*?(query|q)=([^&]*).*", "\\2"]], [["goo検索","http://www.goo.ne.jp/"], ["^http://.*goo.ne.jp/.*?MT=([^&]*).*", "\\1"]], [["@nifty検索", "http://www.nifty.com/"], ["^http://(search|asearch|www).nifty.com/.*?(q|Text)=([^&]*).*", "\\3"]], [["OCN検索", "http://www.ocn.ne.jp/"], ["^http://ocn.excite.co.jp/search.gw.*search=([^&]*).*", "\\1"]], [["excite検索", "http://www.excite.co.jp/"], ["^http://.*excite.*?(search|s)=([^&]*).*", "\\2"]], [["msn検索", "http://www.msn.co.jp/home.htm"], ["^http://.*search.msn.*?(q|MT)=([^&]*).*", "\\2"]], [["BIGLOBE検索", "http://www.biglobe.ne.jp/"], ["^http://cgi.search.biglobe.ne.jp/cgi-bin/search.*?(q|key)=([^&]*).*", "\\2"]], [["テレコムサーチ", "http://www.odn.ne.jp/"], ["^http://search.odn.ne.jp/LookSmartSearch.jsp.*(key|QueryString)=([^&]*).*", "\\2"]], [["Netscape検索", "http://google.netscape.com/"], ["^http://.*.netscape.com/.*(query|q|search)=([^&]*).*", "\\2"]], [["DIONサーチ", "http://www.dion.ne.jp/"], ["^http://dir.dion.ne.jp/LookSmartSearch.jsp.*(key|QueryString)=([^&]*).*", "\\2"]], [["Metcha Search","http://bach.scitec.kobe-u.ac.jp/"], ["^http://bach.scitec.kobe-u.ac.jp/cgi-bin/metcha.cgi?q=([^&]*).*", "\\1"]], [["AOL検索", "http://www.aol.com/"], ["^http://.*aol.com/.*query=([^&]*).*", "\\1"]], [["Fresheye検索", "http://www.fresheye.com/"], ["^http://.*fresheye.*kw=([^&]*).*", "\\1"]], [["AlltheWeb検索","http://www.alltheweb.com/"], ["^http://www.alltheweb.com/.*?q=([^&]*).*", "\\1"]], [["TOCC/Search","http://www.tocc.co.jp/"], ["^http://www.tocc.co.jp.*QRY=([^&]*).*", "\\1"]], [["EarthLink検索","http://www.earthlink.net/"], ["^http://.*earthlink.*q=([^&]*).*", "\\1"]], [["i won_Search","http://home.iwon.com/"], ["^http://.*iwon.*searchfor=([^&]*).*", "\\1"]], [["metacrawler検索","http://www.metacrawler.com/"], ["^http://.*metacrawler.com/texis/search?q=([^&]*).*", "\\1"]], [["DOGPILE検索","http://www.dogpile.com/"], ["^http://search.dogpile.com/texis/search.q=([^&]*).*", "\\1"]], [["NEXEARCH","http://www.naver.co.jp/"], ["^http://search.naver.*query=([^&]*).*", "\\1"]], [["overture検索","http://www.overture.com/"], ["^http://overture.*Keywords=([^&]*).*", "\\1"]], [["About検索","http://www.about.com/"], ["^http://.*about.*terms=([^&]*).*", "\\1"]], [["looksmart検索","http://www.looksmart.com/"], ["^http://www.looksmart.com.*key=([^&]*).*", "\\1"]] ] if @options["disp_referrer.search_table"] search_table += @options["disp_referrer.search_table"] end result = %Q[
    #{referer_today}
    \n] result << %Q[
      \n] #search part. refs = diary.referers.collect{|item| item[1..2].flatten} refs.sort!{|a,b| -(a[0] <=> b[0])} if refs search_result, refs = disp_referrer_main(diary, refs, search_table) #optional part. if @options["disp_referrer.table"] opt_result, refs = disp_referrer_main(diary, refs, @options["disp_referrer.table"]) end #normal and optional part. normal_result = Array.new refs.each do |cnt, ref| normal_result << [cnt, %Q[
    • #{cnt} #{Web.escapeHTML(diary.disp_referer(@referer_table, ref))}
    • \n]] end #show normal part. normal_result += opt_result if opt_result normal_result.sort!{|a,b| - (a[0] <=> b[0])} normal_result.collect!{|item| item[1]} if normal_result result << normal_result.join if normal_result result << "
    \n
      " #show search part. search_result.sort!{|a,b| - (a[0] <=> b[0])} search_result.collect!{|item| item[1]} if search_result result << search_result.join if search_result result << "
    " end end