Class: TDiary::Filter::DefaultFilter

Inherits:
Filter
  • Object
show all
Defined in:
lib/tdiary/filter/default.rb

Constant Summary

Constants inherited from Filter

Filter::DEBUG_FULL, Filter::DEBUG_NONE, Filter::DEBUG_SPAM

Instance Method Summary collapse

Methods inherited from Filter

#debug, #initialize

Methods included from ViewHelper

#base_url, #bot?

Constructor Details

This class inherits a constructor from TDiary::Filter::Filter

Instance Method Details

#comment_filter(diary, comment) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/tdiary/filter/default.rb', line 11

def comment_filter( diary, comment )
	if 'POST' != @cgi.request_method then
		return false
	end
	if comment.name.strip.empty? or comment.body.strip.empty? then
		return false
	end
	idx = 1
	diary.each_comment( -1 ) do |com|
		return false if idx >= @conf.comment_limit_per_day
		return false if comment == com
		idx += 1
	end
	true
end

#referer_filter(referer) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/tdiary/filter/default.rb', line 27

def referer_filter( referer )
	if not referer then
		false
	#elsif /[\x00-\x20\x7f-\xff]/ =~ referer then
	#	false
	elsif @conf.bot =~ @cgi.user_agent
		false
	elsif %r|^https?://|i =~ referer
		ref = CGI::unescape( referer.sub( /#.*$/, '' ).sub( /\?\d{8}$/, '' ) ).force_encoding('ASCII-8BIT')
		@conf.no_referer.each do |noref|
			return false if /#{noref.dup.force_encoding('ASCII-8BIT')}/i =~ ref
		end
		true
	else
		false
	end
end