root/platform/tdiary/plugin/recent_estraier.rb

Revision 3279, 1.4 kB (checked in by hsbt, 12 months ago)

platform/tdiary/plugin: changed directory rule.

Line 
1# recent_estraier.rb $Revision 1.1 $
2#
3# recent_estraier: Estraier検索語新しい順
4#                estsearch.cgiが作成する検索キーワードログから
5#                最新xx件分の検索語を表示します。
6# パラメタ:
7#   file:       検索キーワードログファイル名(絶対パス表記)
8#   estraier:     estseach.cgiのパス
9#   limit:      表示件数(未指定時:5)
10#   make_link:  <a>を生成するか?(未指定時:生成する)   
11#
12#
13# Copyright (c) 2005 SHIBATA Hiroshi <h-sbt@nifty.com>
14# Distributed under the GPL2.
15#
16
17require 'nkf'
18
19def recent_estraier(file, estraier, limit = 5, make_link = true)
20   begin
21      lines = []
22      log = open(file)
23      if log.stat.size > 300 * limit then
24         log.seek(-300 * limit,IO::SEEK_END)
25      end
26      log.each_line do |line|
27         lines << line
28      end
29     
30      result = "<ol>"
31      lines.reverse.each_with_index do |line,idx|
32         break if idx >= limit
33         word = NKF::nkf('-We -m0', line.split(/\t/)[2])
34         if word.empty? then
35            limit += 1
36         else
37            if make_link
38               result << %Q|<li><a href="#{estraier}?phrase=#{u(h(word))}&enc=EUC-JP">#{h word}</a></li>|
39            else
40               result << %Q|#{h word}|
41            end
42         end
43      end
44               
45      result << %Q[</ol>]
46     
47   rescue
48                %Q[<p class="message">#$! (#{$!.class})<br>cannot read #{file}.</p>]
49        end
50end
Note: See TracBrowser for help on using the browser.