| 1 | # tdiarytimes_textstyle.rb $Revision: 1.3 $ |
|---|
| 2 | # |
|---|
| 3 | # Copyright (c) 2004 phonondrive <tdiary@phonondrive.com> |
|---|
| 4 | # Distributed under the GPL |
|---|
| 5 | # |
|---|
| 6 | # プラグイン配布ページ: |
|---|
| 7 | # http://phonondrive.com/trd/ |
|---|
| 8 | # -------------------------------------------------------------------- |
|---|
| 9 | # |
|---|
| 10 | # |
|---|
| 11 | # |
|---|
| 12 | # Abstract: |
|---|
| 13 | # -------------------------------------------------------------------- |
|---|
| 14 | # 日記を登録した時間帯をタイムライン上に記録します。 |
|---|
| 15 | # 記録されたエントリは日時の経過と共にフェードアウトしていきます。 |
|---|
| 16 | # このような MTBlogTimes や tdiarytimes と同等の機能をテキストで実現します。 |
|---|
| 17 | # また、テキストベースであることを生かした柔軟なサイトデザインが可能です。 |
|---|
| 18 | # ruby-gd のインストール作業も必要ないため、すぐに使用出来ます。 |
|---|
| 19 | # |
|---|
| 20 | # |
|---|
| 21 | # Usage: |
|---|
| 22 | # -------------------------------------------------------------------- |
|---|
| 23 | # プラグインは、プラグインフォルダに入れてください。 |
|---|
| 24 | # ヘッダ、あるいはフッタ部に入力した <%= tdiarytimes_textstyle %> |
|---|
| 25 | # の位置にタイムライン文字列が展開されます。 |
|---|
| 26 | # 新しいエントリの記録や保持期間の過ぎた古いエントリの削除は、 |
|---|
| 27 | # 日記の追加および登録時に行われます。 |
|---|
| 28 | # ただし、エントリのフェードアウト効果はリアルタイムに計算されます。 |
|---|
| 29 | # エントリの表示分解能は10分ごとです。 |
|---|
| 30 | # |
|---|
| 31 | # |
|---|
| 32 | # Options: |
|---|
| 33 | # -------------------------------------------------------------------- |
|---|
| 34 | # |
|---|
| 35 | # 現在、次の9つのオプションが用意されています。 |
|---|
| 36 | # |
|---|
| 37 | # init_text 日記の登録されていない時間帯の文字列 (任意の文字列) |
|---|
| 38 | # entr_text 日記が登録された時間帯の文字列 (任意の文字列) |
|---|
| 39 | # init_color 日記の登録されていない時間帯の文字列の色 (RRBBGG形式で指定) |
|---|
| 40 | # entr_color 日記が登録された時間帯の文字列の色 (RRBBGG形式で指定) |
|---|
| 41 | # fade_color 日記が登録された時間帯の文字列のフェードアウト先の色 (RRBBGG形式で指定) |
|---|
| 42 | # init_css タイムライン文字列全体のCSS設定 (CSSの書式に準拠) |
|---|
| 43 | # entr_css 日記が登録された時間帯の文字列のCSS設定 (CSSの書式に準拠) |
|---|
| 44 | # title_text オブジェクト上にマウスをポイントした時のTIPS文字列 (任意の文字列) |
|---|
| 45 | # fade_time ログとして保存しておく(フェードアウトに要する)日数 (任意の数値) |
|---|
| 46 | # entr_interval 前回のエントリ登録から指定時間以内は新規登録しない (任意の数値) |
|---|
| 47 | # |
|---|
| 48 | # オプション値の設定方法には3つの方法があり、その優先順位は次の通りです。 |
|---|
| 49 | # <%= tdiarytimes_textstyle %> 引数指定 > tdiary.conf設定値 > デフォルト値 |
|---|
| 50 | # |
|---|
| 51 | # entr_intervalを除いた全てのオプション値は <%= %> への引数指定により設定出来るため、 |
|---|
| 52 | # ページにごとに意匠を変更するなど自由度の高いサイトデザインが可能です。 |
|---|
| 53 | # 一方で、全てのオプションにデフォルト値が用意されているため、 |
|---|
| 54 | # 全く設定を行わなくても動作します。 |
|---|
| 55 | # デフォルト値の具体的な値については、tdiary.confへの記述方法の項を参照して下さい。 |
|---|
| 56 | # |
|---|
| 57 | # |
|---|
| 58 | # <%= tdiarytimes_textstyle %>への引数指定によるオプション設定方法 |
|---|
| 59 | # -------------------------------------------------------------------- |
|---|
| 60 | #【書式】 |
|---|
| 61 | # <%= tdiarytimes_textstyle init_text, entr_text, init_color, entr_color, fade_color, init_css, entr_css, title_text, fade_time %> |
|---|
| 62 | # |
|---|
| 63 | #【記述例】 |
|---|
| 64 | # <%=tdiarytimes_textstyle "●","●","004400","66ff66","004400","background-color:#002200;font-size:9px",nil,"TEXTSTYLE!!",15 %> |
|---|
| 65 | # |
|---|
| 66 | # ※ tdiary.conf指定値、またはデフォルト値を使用したい場合は、引数に nil を指定してください。 |
|---|
| 67 | # |
|---|
| 68 | # |
|---|
| 69 | # tdiary.confへの記述によるオプション設定方法 |
|---|
| 70 | # -------------------------------------------------------------------- |
|---|
| 71 | #【記述例】 (例として指定されている値は、プラグイン本体の持つデフォルト値です) |
|---|
| 72 | # @options['tdiarytimes_textstyle.init_text'] = "|" |
|---|
| 73 | # @options['tdiarytimes_textstyle.entr_text'] = "|" |
|---|
| 74 | # @options['tdiarytimes_textstyle.init_color'] = "444444" |
|---|
| 75 | # @options['tdiarytimes_textstyle.entr_color'] = "eeeeee" |
|---|
| 76 | # @options['tdiarytimes_textstyle.fade_color'] = "444444" |
|---|
| 77 | # @options['tdiarytimes_textstyle.init_css'] = "background-color:#444444;" |
|---|
| 78 | # @options['tdiarytimes_textstyle.entr_css'] = "" |
|---|
| 79 | # @options['tdiarytimes_textstyle.title_text'] = "TDIARYTIMES-TEXTSTYLE" |
|---|
| 80 | # @options['tdiarytimes_textstyle.fade_time'] = 30 |
|---|
| 81 | # @options['tdiarytimes_textstyle.entr_interval'] = 1 |
|---|
| 82 | # |
|---|
| 83 | # ※ fade_time の単位は日、entr_interval の単位は時間です。 |
|---|
| 84 | # ※ ログとして保存しておく期間(フェードアウト期間)を過ぎたデータエントリは、 |
|---|
| 85 | # 指定期間経過後の次回日記追加時にログファイルから削除されます。 |
|---|
| 86 | # この期間を決定する fade_time 値は、<%= %> 引数からは指定出来ません。 |
|---|
| 87 | # デフォルト値(30日)以外の値を用いたい場合は、必ず tdiary.conf にて指定して下さい。 |
|---|
| 88 | # 同様に、entr_interval もデフォルト値(1時間)以外に設定したい場合は、 |
|---|
| 89 | # tdiary.conf にて指定して下さい。ちなみに0.5だと30分間隔になります。 |
|---|
| 90 | # |
|---|
| 91 | # |
|---|
| 92 | # In secure mode: |
|---|
| 93 | # -------------------------------------------------------------------- |
|---|
| 94 | # 現在のところ動作しません。(ログファイルを読み込めない為) |
|---|
| 95 | # |
|---|
| 96 | # |
|---|
| 97 | # Acknowledgements: |
|---|
| 98 | # -------------------------------------------------------------------- |
|---|
| 99 | # This plugin is based on tdiarytimes.rb $Revision: 1.3 $ |
|---|
| 100 | # Copyright (c) 2003 neuichi <neuichi@nmnl.jp> |
|---|
| 101 | # Distributed under the GPL |
|---|
| 102 | # http://nmnl.jp/hiki/software/?tDiary+%3A%3A+Plugin |
|---|
| 103 | # |
|---|
| 104 | # |
|---|
| 105 | =begin ChangeLog |
|---|
| 106 | 2004.03.04 phonondrive <tdiary@phonondrive.com> |
|---|
| 107 | * version 1.0.4 |
|---|
| 108 | 非応答USER-AGENTリストを更新しました。 |
|---|
| 109 | |
|---|
| 110 | 2004.02.05 phonondrive <tdiary@phonondrive.com> |
|---|
| 111 | * version 1.0.3 |
|---|
| 112 | フェードアウト効果の計算結果が正しく出力されない点を修正しました。 |
|---|
| 113 | |
|---|
| 114 | 2004.01.30 phonondrive <tdiary@phonondrive.com> |
|---|
| 115 | * version 1.0.2 |
|---|
| 116 | 最低登録間隔のオプション (entr_interval) を追加。 |
|---|
| 117 | 前回のエントリ登録から指定時間以内は新規登録しないようにしました。 |
|---|
| 118 | |
|---|
| 119 | 2004.01.29 phonondrive <tdiary@phonondrive.com> |
|---|
| 120 | * version 1.0.1 |
|---|
| 121 | replace(登録)時もエントリを記録するようにしました。 |
|---|
| 122 | 次のUSER-AGENTからの呼び出しには結果を出力しないようにしました。 |
|---|
| 123 | モバイル端末 (tDiary準拠) |
|---|
| 124 | テキストブラウザ (w3m, Lynx, links) |
|---|
| 125 | CSS非対応ブラウザ (Mosaic, Lite, iCab, JustView, WebExplorer) |
|---|
| 126 | 検索ボット (bot, crawler, Spider, Slurp, inktomi, Sidewinder, naver) |
|---|
| 127 | その他 (libwww, antenna) |
|---|
| 128 | |
|---|
| 129 | 2004.01.28 phonondrive <tdiary@phonondrive.com> |
|---|
| 130 | * version 1.0.0 |
|---|
| 131 | =end |
|---|
| 132 | |
|---|
| 133 | |
|---|
| 134 | |
|---|
| 135 | |
|---|
| 136 | # tDiarytimes_textstyle の結果を出力しない USER-AGENT リスト |
|---|
| 137 | # モバイル端末、テキストブラウザ、CSS非対応ブラウザ、検索ボット、アンテナなど |
|---|
| 138 | # 大文字・小文字は区別しません。 |
|---|
| 139 | |
|---|
| 140 | def tdiarytimes_textstyle_ignore_user_agent; "w3m|Lynx|links|Mosaic|Lite|iCab|JustView|WebExplorer|bot|crawler|Spider|Slurp|inktomi|Sidewinder|naver|libwww|archiver|http|check|WDB|WWWC|WWWD|samidare|tamatebako|NATSU-MICAN|hina|antenna"; end |
|---|
| 141 | |
|---|
| 142 | |
|---|
| 143 | |
|---|
| 144 | |
|---|
| 145 | # -------------------------------------------------------------------- |
|---|
| 146 | # 日記登録時の処理 |
|---|
| 147 | # -------------------------------------------------------------------- |
|---|
| 148 | |
|---|
| 149 | if /^(append|replace)$/ =~ @mode then |
|---|
| 150 | |
|---|
| 151 | # オプション値(エントリ保持期間)の読み込みと設定 |
|---|
| 152 | |
|---|
| 153 | fade_time = @options['tdiarytimes_textstyle.fade_time'] || 30 |
|---|
| 154 | fade_time = 24 * 60 * 60 * fade_time.to_f |
|---|
| 155 | |
|---|
| 156 | entr_interval = @options['tdiarytimes_textstyle.entr_interval'] || 1 |
|---|
| 157 | entr_interval = 60 * 60 * entr_interval.to_f |
|---|
| 158 | |
|---|
| 159 | |
|---|
| 160 | # ログデータの読み込み |
|---|
| 161 | |
|---|
| 162 | cache = "#{@cache_path}/tdiarytimes_textstyle" |
|---|
| 163 | Dir::mkdir( cache ) unless File::directory?( cache ) |
|---|
| 164 | |
|---|
| 165 | begin |
|---|
| 166 | io = open("#{cache}/tdiarytimes_textstyle.dat","r") |
|---|
| 167 | ary_data = Marshal.load(io) |
|---|
| 168 | io.close |
|---|
| 169 | |
|---|
| 170 | # 1.0.1 >> 1.0.2 ログデータ移行用 |
|---|
| 171 | if ary_data.size == 144 |
|---|
| 172 | ary_data.push(Time.now.to_i - entr_interval - 1) |
|---|
| 173 | end |
|---|
| 174 | |
|---|
| 175 | rescue |
|---|
| 176 | # ログがない場合は仮データを用意 |
|---|
| 177 | ary_data = Array.new(145) {|i| 0 } |
|---|
| 178 | end |
|---|
| 179 | |
|---|
| 180 | |
|---|
| 181 | # 不良データや寿命が来たエントリを削除する |
|---|
| 182 | |
|---|
| 183 | (0..143).each {|i| |
|---|
| 184 | delta = (Time.now.to_i - ary_data[i])/fade_time.to_f |
|---|
| 185 | if delta < 0 || delta > 1 |
|---|
| 186 | ary_data[i] = 0 |
|---|
| 187 | end |
|---|
| 188 | } |
|---|
| 189 | |
|---|
| 190 | |
|---|
| 191 | # 最低登録間隔を経過していたら、日記が登録された時間帯に新しいエントリをセットする |
|---|
| 192 | |
|---|
| 193 | if (Time.now.to_i - ary_data[144]) > entr_interval.to_f |
|---|
| 194 | ary_data[(Time.now.strftime('%H').to_i*6 + Time.now.strftime('%M').to_f/10).to_i] = Time.now.to_i |
|---|
| 195 | # 最終登録時間の記録 |
|---|
| 196 | ary_data[144] = Time.now.to_i |
|---|
| 197 | end |
|---|
| 198 | |
|---|
| 199 | |
|---|
| 200 | # ログデータの書き込み |
|---|
| 201 | |
|---|
| 202 | io = open("#{cache}/tdiarytimes_textstyle.dat","w") |
|---|
| 203 | Marshal.dump(ary_data,io) |
|---|
| 204 | io.close |
|---|
| 205 | end |
|---|
| 206 | |
|---|
| 207 | |
|---|
| 208 | |
|---|
| 209 | |
|---|
| 210 | # -------------------------------------------------------------------- |
|---|
| 211 | # プラグイン表示時の動作 |
|---|
| 212 | # -------------------------------------------------------------------- |
|---|
| 213 | |
|---|
| 214 | def tdiarytimes_textstyle(init_text = nil, entr_text = nil, init_color = nil, entr_color = nil, fade_color = nil, init_css = nil, entr_css = nil, title_text = nil, fade_time = nil) |
|---|
| 215 | |
|---|
| 216 | |
|---|
| 217 | # モバイル端末、テキストブラウザ、CSS非対応ブラウザ、検索ボットなどには結果を出力しない |
|---|
| 218 | |
|---|
| 219 | unless @cgi.mobile_agent? || @cgi.user_agent =~ %r[(#{tdiarytimes_textstyle_ignore_user_agent})]i |
|---|
| 220 | |
|---|
| 221 | |
|---|
| 222 | r = "" |
|---|
| 223 | |
|---|
| 224 | |
|---|
| 225 | # オプション値の読み込みと設定 |
|---|
| 226 | |
|---|
| 227 | init_text = @options['tdiarytimes_textstyle.init_text'] || "|" unless init_text |
|---|
| 228 | entr_text = @options['tdiarytimes_textstyle.entr_text'] || "|" unless entr_text |
|---|
| 229 | init_color = @options['tdiarytimes_textstyle.init_color'] || "444444" unless init_color |
|---|
| 230 | entr_color = @options['tdiarytimes_textstyle.entr_color'] || "eeeeee" unless entr_color |
|---|
| 231 | fade_color = @options['tdiarytimes_textstyle.fade_color'] || "444444" unless fade_color |
|---|
| 232 | init_css = @options['tdiarytimes_textstyle.init_css'] || "background-color:#444444;" unless init_css |
|---|
| 233 | entr_css = @options['tdiarytimes_textstyle.entr_css'] || "" unless entr_css |
|---|
| 234 | title_text = @options['tdiarytimes_textstyle.title_text'] || "TDIARYTIMES-TEXTSTYLE" unless title_text |
|---|
| 235 | fade_time = @options['tdiarytimes_textstyle.fade_time'] || 30 unless fade_time |
|---|
| 236 | |
|---|
| 237 | |
|---|
| 238 | entr_color_rgb = entr_color.unpack("a2a2a2") |
|---|
| 239 | fade_color_rgb = fade_color.unpack("a2a2a2") |
|---|
| 240 | |
|---|
| 241 | fade_time = 24 * 60 * 60 * fade_time.to_f |
|---|
| 242 | |
|---|
| 243 | |
|---|
| 244 | # ログデータの読み込み |
|---|
| 245 | |
|---|
| 246 | cache = "#{@cache_path}/tdiarytimes_textstyle" |
|---|
| 247 | |
|---|
| 248 | begin |
|---|
| 249 | io = open("#{cache}/tdiarytimes_textstyle.dat","r") |
|---|
| 250 | ary_data = Marshal.load(io) |
|---|
| 251 | io.close |
|---|
| 252 | rescue |
|---|
| 253 | # ログファイルが見つからない場合はエラーとダミーデータを表示 |
|---|
| 254 | r << %Q|Error! cannot open log file.| |
|---|
| 255 | ary_data = Array.new(145) {|i| 0 } |
|---|
| 256 | end |
|---|
| 257 | |
|---|
| 258 | |
|---|
| 259 | # htmlデータの出力 |
|---|
| 260 | |
|---|
| 261 | r << %Q|<span style="color:##{h init_color};#{h init_css}" title="#{h title_text}">| |
|---|
| 262 | |
|---|
| 263 | (0..143).each {|i| |
|---|
| 264 | data = ary_data[i] |
|---|
| 265 | if data != 0 |
|---|
| 266 | delta = (Time.now.to_i - data)/fade_time.to_f |
|---|
| 267 | if delta < 0 |
|---|
| 268 | # 不良エントリ対策 |
|---|
| 269 | now_color = init_color |
|---|
| 270 | elsif delta > 1 |
|---|
| 271 | # フェードアウト期間超過エントリ対策 |
|---|
| 272 | now_color = fade_color |
|---|
| 273 | else |
|---|
| 274 | # 正常なエントリの処理 |
|---|
| 275 | now_color = "" |
|---|
| 276 | (0..2).each{|i| |
|---|
| 277 | now_color << format("%02x", entr_color_rgb[i].hex + ((fade_color_rgb[i].hex - entr_color_rgb[i].hex)*delta).to_i) |
|---|
| 278 | } |
|---|
| 279 | end |
|---|
| 280 | r << %Q|<span style="color:##{h now_color};#{h entr_css}" title="#{Time.at(data).strftime('%b %d,%Y')}">#{entr_text}</span>| |
|---|
| 281 | else |
|---|
| 282 | r << %Q|#{init_text}| |
|---|
| 283 | end |
|---|
| 284 | } |
|---|
| 285 | |
|---|
| 286 | r << %Q|</span>| |
|---|
| 287 | |
|---|
| 288 | end |
|---|
| 289 | |
|---|
| 290 | end |
|---|