-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* large change about referer: daily management, volatile link, etc.
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
Showing
15 changed files
with
382 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.