From 2f77bc52b1cb845b229ed19073c3c4f86d3ae4c6 Mon Sep 17 00:00:00 2001 From: kitaj Date: Sat, 3 May 2003 14:47:03 +0000 Subject: [PATCH] * tdiary.rb: import classes for TrackBack(TDiary::TDiaryTrackBack*) from tb.rb. git-svn-id: https://tdiary.svn.sourceforge.net/svnroot/tdiary/trunk/core@1361 7f22e88f-374d-0410-998f-c91420d97ba2 --- ChangeLog | 3 ++ tdiary.rb | 159 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 160 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index c87e95061..26a4cd087 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2003.05.03 Junichiro Kita + * tdiary.rb: import classes for TrackBack(TDiary::TDiaryTrackBack*) from tb.rb. + 2003.05.02 TADA Tadashi * index.rb, updatre.rb: untaint org_path. thanks mput. diff --git a/tdiary.rb b/tdiary.rb index 690e8286d..49e26fa71 100644 --- a/tdiary.rb +++ b/tdiary.rb @@ -1,12 +1,12 @@ =begin == NAME tDiary: the "tsukkomi-able" web diary system. -tdiary.rb $Revision: 1.108 $ +tdiary.rb $Revision: 1.109 $ Copyright (C) 2001-2003, TADA Tadashi =end -TDIARY_VERSION = '1.5.3.20030502' +TDIARY_VERSION = '1.5.3.20030503' require 'cgi' require 'nkf' @@ -1595,4 +1595,159 @@ def initialize(cgi, rhtml, conf) categorize end end + + # + # exception class for TrackBack + # + class TDiaryTrackBackError < StandardError + end + + # + # class TDiaryTrackBackBase + # + class TDiaryTrackBackBase < TDiaryBase + public :mode + def initialize( cgi, rhtml, conf ) + super + date = ENV['REQUEST_URI'].scan(%r!/(\d{4})(\d\d)(\d\d)!)[0] + @date = Time::local(*date) + end + + def referer? + nil + end + + def trackback_url + 'http://' + ENV['HTTP_HOST'] + + (ENV['SERVER_PORT'] == '80' ? '' : ":#{ENV['SERVER_PORT']}") + + ENV['REQUEST_URI'] + end + + def diary_url + trackback_url.sub(/#{File::basename(ENV['SCRIPT_NAME'])}.*$/, '') + + @conf.index.sub(%r|^\./|, '') + + @plugin.instance_eval(%Q|anchor "#{@date.strftime('%Y%m%d')}"|) + end + + def self.success_response + < + +0 + +HERE + end + + def self.fail_response(reason) + < + +1 +#{reason} + +HERE + end + end + + # + # class TDiaryTrackBackRSS + # generate RSS + # + class TDiaryTrackBackRSS < TDiaryTrackBackBase + def initialize( cgi, rhtml, conf ) + super + @io.transaction( @date ) do |diaries| + @diaries = diaries + @diary = @diaries[@date.strftime('%Y%m%d')] + DIRTY_NONE + end + end + + def eval_rhtml( prefix = '' ) + raise TDiaryTrackBackError.new("invalid date: #{@date.strftime('%Y%m%d')}") unless @diary + @plugin = load_plugins + r = < + +0 + + +#{@diary.title} +#{diary_url} + +ja-jp +RSSHEAD + @diary.each_comment(100) do |com, idx| + begin + next unless com.visible_true? + rescue NameError, NoMethodError + next unless com.visible? + end + next unless /^(Track|Ping)Back$/ =~ com.name + url, blog_name, title, excerpt = com.body.split(/\n/, 4) + r << < +#{CGI::escapeHTML( title )} +#{CGI::escapeHTML( url )} +#{CGI::escapeHTML( excerpt )} + +RSSITEM + end + r << < + + +RSSFOOT + end + end + + # + # class TDiaryTrackBackReceive + # receive TrackBack ping and store as comment + # + class TDiaryTrackBackReceive < TDiaryTrackBackBase + def initialize( cgi, rhtml, conf ) + super + @error = nil + + url = @cgi.params['url'][0] + blog_name = (@cgi.params['blog_name'][0] || '').to_euc + title = (@cgi.params['title'][0] || '').to_euc + excerpt = (@cgi.params['excerpt'][0] || '').to_euc + + body = [url, blog_name, title, excerpt].join("\n") + @comment = Comment::new('TrackBack', '', body) + begin + @io.transaction( @date ) do |diaries| + @diaries = diaries + if @diaries[@date.strftime('%Y%m%d')].add_comment(@comment) + DIRTY_COMMENT + else + @error = "repeated TrackBack Ping" + DIRTY_NONE + end + end + rescue + @error = $!.message + end + end + + def eval_rhtml( prefix = '' ) + raise TDiaryTrackBackError.new(@error) if @error + @plugin = load_plugins + TDiaryTrackBackBase::success_response + end + end + + # + # class TDiaryTrackBackShow + # show TrackBacks + # + class TDiaryTrackBackShow < TDiaryTrackBackBase + def eval_rhtml( prefix = '' ) + @plugin = load_plugins + anchor = @plugin.instance_eval(%Q|anchor "#{@date.strftime('%Y%m%d')}"|) + raise ForceRedirect::new("../#{@conf.index}#{anchor}#t") + end + end end