1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
#
# navi_day.rb
#
# navi_day: 「前の日記」や「次の日記」を“月またぎ”に対応させる。
#
# 日単位での表示の時の「前の日記」や「次の日記」のリンクが、
# 異なる月の日記を正しく指せない場合があるという tDiary の制限を
# 解消するプラグインです。以前よりある navi_user.rb と機能的には
# 同じですが、navi_user.rb よりは処理がずっと軽くなっています。
# また、日記の表示状態(非表示の日記)に対する考慮もなされています。
#
# tDiary 2.0 以降で使えると思います。セキュアモードでも使えますが、
# セキュアモードの場合は、モバイル端末からのアクセスに対しては
# このプラグインは効力を持ちません(tDiary セキュア環境の制限:
# モバイル端末の場合は本文を出力するときに calc_links が呼ばれる
# ため)。
#
# navi_user.rb と併用すると navi_user.rb の方が優先されますので、
# このプラグインを使うときには必ず navi_user.rb を外してください。
#
# Copyright (C) 2007, MIYASAKA Masaru <alkaid@coral.ocn.ne.jp>
# You can redistribute it and/or modify it under GPL2.
#
# Last Modified : May 27, 2007
#
# for tDiary 2.0.X
if not TDiaryMonth.method_defined?(:diaries) then
eval( <<-MODIFY_CLASS, TOPLEVEL_BINDING )
module TDiary
class TDiaryMonth
attr_reader :diaries
end
end
MODIFY_CLASS
end
class NaviDayCGI
attr_reader :params
def referer; nil; end
def initialize
@params = Hash.new([])
end
end
alias :calc_links_navi_day_backup :calc_links
def calc_links
if not @conf.secure and \
(/day|edit/ =~ @mode or \
/latest|month|nyear/ =~ @mode) then
if /(latest|month|nyear)/ === @mode
today = @diaries.keys.sort[-1]
else
today = @date.strftime('%Y%m%d')
end
days = @diaries.keys
days |= [today]
days.sort!
days.unshift(nil).push(nil)
today_index = days.index(today)
days[0 .. today_index - 1].reverse_each do |prev_day|
@prev_day = prev_day
break unless @prev_day
break if (@mode == 'edit') or @diaries[@prev_day].visible?
end
days[today_index + 1 .. -1].each do |next_day|
@next_day = next_day
break unless @next_day
break if (@mode == 'edit') or @diaries[@next_day].visible?
end
if not @prev_day or not @next_day then
cgi = NaviDayCGI.new
years = []
@years.each do |k, v|
v.each do |m|
years << k + m
end
end
this_month = @date.strftime('%Y%m')
years |= [this_month]
years.sort!
years.unshift(nil).push(nil)
this_month_index = years.index(this_month)
years[0 .. this_month_index - 1].reverse_each do |prev_month|
break unless not @prev_day and prev_month
cgi.params['date'] = [prev_month]
diaries = TDiaryMonth.new(cgi, '', @conf).diaries
days = diaries.keys.sort
days.unshift(nil)
days.reverse_each do |prev_day|
@prev_day = prev_day
break unless @prev_day
break if (@mode == 'edit') or diaries[@prev_day].visible?
end
end
years[this_month_index + 1 .. -1].each do |next_month|
break unless not @next_day and next_month
cgi.params['date'] = [next_month]
diaries = TDiaryMonth.new(cgi, '', @conf).diaries
days = diaries.keys.sort
days.push(nil)
days.each do |next_day|
@next_day = next_day
break unless @next_day
break if (@mode == 'edit') or diaries[@next_day].visible?
end
end
end
else
calc_links_navi_day_backup
end
end
|