Skip to content

Commit

Permalink
* large change about referer: daily management, volatile link, etc.
Browse files Browse the repository at this point in the history
git-svn-id: https://tdiary.svn.sourceforge.net/svnroot/tdiary/trunk/core@2580 7f22e88f-374d-0410-998f-c91420d97ba2
  • Loading branch information
tadatadashi committed Feb 2, 2006
1 parent 14df8dc commit 82d8ac4
Show file tree
Hide file tree
Showing 15 changed files with 382 additions and 177 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
2006-02-03 TADA Tadashi <sho@spc.gr.jp>
* large change about referer: daily management, volatile link, etc.

2006-01-02 TADA Tadashi <sho@spc.gr.jp>
* tdiary/defaultio.rb: ignore Errno::NOENT when delete empty file.

Expand Down
10 changes: 9 additions & 1 deletion misc/i18n/tdiary.conf.sample-en
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# tDiary configuration file $Revision: 1.15 $
# tDiary configuration file $Revision: 1.16 $
#

#-------
Expand Down Expand Up @@ -258,6 +258,14 @@ FOOTER
'^http://10.',
]

# URLs which are only recorded into Today's Link (Regular Expression)
# @only_volatile is an array of URLs to record into only Today's Link.
# When a referer match to this list, it will be recoreded to volatile
# list. This list will be cleared when you make new text in new day.
# Specify @only_volatile same style of @no_referer.
@only_volatile = [
]

# The rules which convert the specified URL to the word (Regular Expression)
# @referer_table is configured so that readable URLs are shown in
# today's links when you read "daily" page. You add an array of
Expand Down
46 changes: 1 addition & 45 deletions plugin/00default.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# 00default.rb: default plugins
# $Revision: 1.93 $
# $Revision: 1.94 $
#
# Copyright (C) 2001-2005, TADA Tadashi <sho@spc.gr.jp>
# You can redistribute it and/or modify it under GPL2.
Expand Down Expand Up @@ -464,28 +464,6 @@ def my( a, str, title = nil )
end
end

#
# referer of today
#
def referer_of_today_short( diary, limit )
return '' if not diary or diary.count_referers == 0 or bot?
result = %Q[#{referer_today} | ]
diary.each_referer( limit ) do |count,ref|
result << %Q[<a href="#{CGI::escapeHTML( ref )}" title="#{CGI::escapeHTML( disp_referer( @referer_table, ref ) )}">#{count}</a> | ]
end
result
end

def referer_of_today_long( diary, limit )
return '' if not diary or diary.count_referers == 0 or bot?
result = %Q[<div class="caption">#{referer_today}</div>\n]
result << %Q[<ul>\n]
diary.each_referer( limit ) do |count,ref|
result << %Q[<li>#{count} <a href="#{CGI::escapeHTML( ref )}">#{CGI::escapeHTML( disp_referer( @referer_table, ref ) )}</a></li>\n]
end
result + '</ul>'
end

#
# other resources
#
Expand Down Expand Up @@ -672,28 +650,6 @@ def saveconf_comment
end
end

# referer
def saveconf_referer
if @mode == 'saveconf' then
@conf.show_referer = @cgi.params['show_referer'][0] == 'true' ? true : false
@conf.referer_limit = @cgi.params['referer_limit'][0].to_i
@conf.referer_limit = 10 if @conf.referer_limit < 1
@conf.referer_day_only = @cgi.params['referer_day_only'][0] == 'true' ? true : false
no_referer2 = []
@conf.to_native( @cgi.params['no_referer'][0] ).each do |ref|
ref.strip!
no_referer2 << ref if ref.length > 0
end
@conf.no_referer2 = no_referer2
referer_table2 = []
@conf.to_native( @cgi.params['referer_table'][0] ).each do |pair|
u, n = pair.sub( /[\r\n]+/, '' ).split( /[ \t]+/, 2 )
referer_table2 << [u,n] if u and n
end
@conf.referer_table2 = referer_table2
end
end

def saveconf_csrf_protection
if @mode == 'saveconf' then
err = nil
Expand Down
185 changes: 185 additions & 0 deletions plugin/05referer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
#
# 01referer.rb: load/save and show today's referer plugin
# $Revision: 1.1 $
#
# Copyright (C) 2005, TADA Tadashi <sho@spc.gr.jp>
# You can redistribute it and/or modify it under GPL2.
#

#
# saving referer
#
add_header_proc do
referer_save_trigger
''
end

def referer_save_trigger
return if @conf.io_class != TDiary::DefaultIO
return if @mode !~ /^day|form|edit|append|replace$/

if @date then
diary = @diaries[@date.strftime( '%Y%m%d' )]
referer_save( diary ) if diary
end
end

class RefererDiary
include TDiary::RefererManager
def initialize
init_referers
end
end

def latest_day?( diary )
y = @years.keys.sort[-1]
m = @years[y].sort[-1]
diary.date.year == y.to_i and diary.date.month == m.to_i and diary.date.day == @diaries.keys.sort[-1][6,2].to_i
end

def referer_save( diary )
# save to volatile only?
save = false
ref = CGI::unescape( @cgi.referer.sub( /#.*$/, '' ).sub( /\?\d{8}$/, '' ) )
@conf.only_volatile.each do |volatile|
if /#{volatile}/i =~ ref then
save = true
break
end
end

# load and save volatile
@referer_volatile = RefererDiary::new
if !save and @cgi.referer and !latest_day?( diary ) then
save = true
end
@referer_volatile.add_referer( @cgi.referer ) if save
referer_transaction( @referer_volatile, save ) do |ref, count|
@referer_volatile.add_referer( ref, count )
end

# load and save referers of current day
if !save and @cgi.referer and @mode == 'day' then
diary.add_referer( @cgi.referer )
save = true
end
referer_transaction( diary, save ) do |ref, count|
diary.add_referer( ref, count )
end
end

def referer_transaction( diary = nil, save = false )
if diary.respond_to?( :date ) then
file = diary.date.strftime( "#{@conf.data_path}%Y/%Y%m%d.tdr" )
else
file = "#{@conf.data_path}volatile.tdr"
end
ymd = nil

begin
File::open( file, 'r' ) do |fh|
fh.flock( File::LOCK_SH )
fh.gets # read magic
fh.read.split( /\r?\n\.\r?\n/ ).each do |l|
headers, body = TDiary::parse_tdiary( l )
ymd = headers['Date']
next unless body
body.each do |r|
count, ref = r.chomp.split( / /, 2 )
next unless ref
yield( ref.chomp, count.to_i )
end
end
end
rescue Errno::ENOENT
end

if @mode =~ /^(append|replace)$/ and !diary.respond_to?( :date ) then
if !ymd or (@date.strftime( '%Y%m%d' ) > ymd) then
ymd = nil
diary.clear_referers
save = true
end
end

if save then
unless ymd then
ymd = (@date ? @date : Time::now).strftime( '%Y%m%d' )
end
File::open( file, File::WRONLY | File::CREAT ) do |fh|
fh.flock( File::LOCK_EX )
fh.rewind
fh.truncate( 0 )
fh.puts( TDiary::TDIARY_MAGIC )
fh.puts( "Date: #{ymd}" )
fh.puts
diary.each_referer( diary.count_referers ) do |count,ref|
fh.puts( "#{count} #{ref}" )
end
fh.puts( '.' )
end
end
end

#
# referer of today
#
def referer_of_today_short( diary, limit )
# return '' if not diary or diary.count_referers == 0 or bot?
# result = %Q[#{referer_today} | ]
# diary.each_referer( limit ) do |count,ref|
# result << %Q[<a href="#{CGI::escapeHTML( ref )}" title="#{CGI::escapeHTML( disp_referer( @referer_table, ref ) )}">#{count}</a> | ]
# end
# result
''
end

def referer_of_today_long( diary, limit )
return '' if not diary or diary.count_referers == 0 or bot?
result = %Q[<div class="caption">#{referer_today}</div>\n]
result << %Q[<ul>\n]
diary.each_referer( limit ) do |count,ref|
result << %Q[<li>#{count} <a href="#{CGI::escapeHTML( ref )}">#{CGI::escapeHTML( disp_referer( @referer_table, ref ) )}</a></li>\n]
end
result << '</ul>'

return result unless latest_day?( diary ) and @referer_volatile.count_referers != 0

result << %Q[<div class="caption">#{volatile_referer}</div>\n]
result << %Q[<ul>\n]
@referer_volatile.each_referer( limit ) do |count,ref|
result << %Q[<li>#{count} <a href="#{CGI::escapeHTML( ref )}">#{CGI::escapeHTML( disp_referer( @referer_table, ref ) )}</a></li>\n]
end
result << '</ul>'
end

#
# referer preference
#
def saveconf_referer
if @mode == 'saveconf' then
@conf.show_referer = @cgi.params['show_referer'][0] == 'true' ? true : false

no_referer2 = []
@conf.to_native( @cgi.params['no_referer'][0] ).each do |ref|
ref.strip!
no_referer2 << ref if ref.length > 0
end
@conf.no_referer2 = no_referer2

only_volatile2 = []
@conf.to_native( @cgi.params['only_volatile'][0] ).each do |ref|
ref.strip!
only_volatile2 << ref if ref.length > 0
end
@conf.only_volatile2 = only_volatile2

referer_table2 = []
@conf.to_native( @cgi.params['referer_table'][0] ).each do |pair|
u, n = pair.sub( /[\r\n]+/, '' ).split( /[ \t]+/, 2 )
referer_table2 << [u,n] if u and n
end
@conf.referer_table2 = referer_table2
end
end

35 changes: 0 additions & 35 deletions plugin/en/00default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ def comment_body_label_short; 'Comment'; end
def comment_submit_label; 'Submit'; end
def comment_submit_label_short; 'Submit'; end
def comment_date( time ); time.strftime( "(#{@date_format} %H:%M)" ); end
def referer_today; "Today's Link"; end
def trackback_today; "Today's TrackBacks"; end
def trackback_total( total ); "(Total: #{total})"; end

Expand Down Expand Up @@ -81,9 +80,6 @@ def submit_label
end
def preview_label; 'Preview'; end

def label_no_referer; "Today's Link Excluding List"; end
def label_referer_table; "Today's Link Conversion Rule"; end

def nyear_diary_label(date, years); "my old days"; end
def nyear_diary_title(date, years); "same days in past"; end

Expand Down Expand Up @@ -236,37 +232,6 @@ def category_anchor(c); "[#{c}]"; end
HTML
end

# referer
add_conf_proc( 'referer', "Today's Link", 'referer' ) do
saveconf_referer

<<-HTML
<h3 class="subtitle">Show links</h3>
#{"<p>Select show or hide about Today's Link</p>" unless @conf.mobile_agent?}
<p><select name="show_referer">
<option value="true"#{if @conf.show_referer then " selected" end}>Show</option>
<option value="false"#{if not @conf.show_referer then " selected" end}>Hide</option>
</select></p>
<h3 class="subtitle">Number of Links</h3>
#{"<p>In Latest or Month mode, you can specify number of visible Link list. So in Dayly mode, all of Link are shown.</p>" unless @conf.mobile_agent?}
<p><input name="referer_limit" value="#{@conf.referer_limit}" size="3"> sites</p>
<h3 class="subtitle">Control Links saving</h3>
#{"<p>Specify which saving only day mode. It means reducing 'referer noise' by access from 'Link page'.</p>" unless @conf.mobile_agent?}
<p><select name="referer_day_only">
<option value="true"#{if @conf.referer_day_only then " selected" end}>Save links only in day mode</option>
<option value="false"#{if not @conf.referer_day_only then " selected" end}>Save links in all access</option>
</select></p>
<h3 class="subtitle">Excluding list</h3>
#{"<p>List of excluding URL that is not recorded to Today's Link. Specify it in regular expression, and a URL into a line.</p>" unless @conf.mobile_agent?}
<p>See <a href="#{@conf.update}?referer=no" target="referer">Default configuration is here</a>.</p>
<p><textarea name="no_referer" cols="60" rows="10">#{@conf.no_referer2.join( "\n" )}</textarea></p>
<h3 class="subtitle">Rule of conversion URL to words.</h3>
#{"<p>A table to convert URL to words in Today's Link. Specify it in regular expression, and a URL into a line.<p>" unless @conf.mobile_agent?}
<p>See <a href="#{@conf.update}?referer=table" target="referer">Default configurations</a>.</p>
<p><textarea name="referer_table" cols="60" rows="10">#{@conf.referer_table2.collect{|a|a.join( " " )}.join( "\n" )}</textarea></p>
HTML
end

# comment mail
def comment_mail_mime( str )
[str.dup]
Expand Down
41 changes: 41 additions & 0 deletions plugin/en/05referer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#
# 05referer.rb: English resource of referer plugin
#
# Copyright (C) 2006, TADA Tadashi <sho@spc.gr.jp>
# You can redistribute it and/or modify it under GPL2.
#

def referer_today; "Links to this day"; end
def volatile_referer; "Today's Link"; end

def label_no_referer; "Today's Link Excluding List"; end
def label_only_volatile; "Volatile Links List"; end
def label_referer_table; "Today's Link Conversion Rule"; end

def nyear_diary_label(date, years); "my old days"; end
def nyear_diary_title(date, years); "same days in past"; end

add_conf_proc( 'referer', "Today's Link", 'referer' ) do
saveconf_referer

<<-HTML
<h3 class="subtitle">Show links</h3>
#{"<p>Select show or hide about Today's Link</p>" unless @conf.mobile_agent?}
<p><select name="show_referer">
<option value="true"#{if @conf.show_referer then " selected" end}>Show</option>
<option value="false"#{if not @conf.show_referer then " selected" end}>Hide</option>
</select></p>
<h3 class="subtitle">Excluding list</h3>
#{"<p>List of excluding URL that is not recorded to Today's Link. Specify it in regular expression, and a URL into a line.</p>" unless @conf.mobile_agent?}
<p>See <a href="#{@conf.update}?referer=no" target="referer">Default configuration is here</a>.</p>
<p><textarea name="no_referer" cols="60" rows="10">#{@conf.no_referer2.join( "\n" )}</textarea></p>
<h3 class="subtitle">Volatile list</h3>
#{"<p>List of volatile URL that is recorded to Today's Link only. Specify it in regular expression, and a URL into a line.</p>" unless @conf.mobile_agent?}
<p>See <a href="#{@conf.update}?referer=volatile" target="referer">Default configuration is here</a>.</p>
<p><textarea name="only_volatile" cols="60" rows="10">#{@conf.only_volatile2.join( "\n" )}</textarea></p>
<h3 class="subtitle">Rule of conversion URL to words.</h3>
#{"<p>A table to convert URL to words in Today's Link. Specify it in regular expression, and a URL into a line.<p>" unless @conf.mobile_agent?}
<p>See <a href="#{@conf.update}?referer=table" target="referer">Default configurations</a>.</p>
<p><textarea name="referer_table" cols="60" rows="10">#{@conf.referer_table2.collect{|a|a.join( " " )}.join( "\n" )}</textarea></p>
HTML
end
Loading

0 comments on commit 82d8ac4

Please sign in to comment.