~ubuntu-branches/ubuntu/saucy/tdiary/saucy-proposed

« back to all changes in this revision

Viewing changes to plugin/05referer.rb

  • Committer: Bazaar Package Importer
  • Author(s): Daigo Moriwaki
  • Date: 2011-04-11 21:53:16 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20110411215316-ih4gt4q8p29d2wf8
Tags: 3.0.1-1
* New upstream release (Closes: #542801, #594947)
* debian/control:
 - Bumped up Standards-Version to 3.9.1.
 - Updated version dependency.
* debian/tdiary-setup.rb: Followed the upstream changes, incorporating js and
  index.fcgi

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#
2
 
# 01referer.rb: load/save and show today's referer plugin
3
 
# $Revision: 1.17 $
4
 
#
5
 
# Copyright (C) 2005, TADA Tadashi <sho@spc.gr.jp>
 
1
# -*- coding: utf-8; -*-
 
2
#
 
3
# 05referer.rb: load/save and show today's referer plugin
 
4
#
 
5
# Copyright (C) 2005, TADA Tadashi <t@tdtds.jp>
6
6
# You can redistribute it and/or modify it under GPL2.
7
7
#
8
8
 
56
56
        alias :add_referer_orig :add_referer
57
57
        def add_referer( ref, count = 1 )
58
58
                return nil unless ref
59
 
                current = @current_date || @refs.keys.sort[-1] || '00000000'
 
59
                current = @current_date || @refs.keys.sort[-1] || '00000101'
60
60
                ref_info = add_referer_orig( ref, count )
61
61
                uref = CGI::unescape( ref )
62
62
                @refs[current] ||= {}
80
80
                        @refs[@current_date].values.sort.reverse.each_with_index do |ary,idx|
81
81
                                break if idx >= limit
82
82
                                yield( ary[0], ary[1] )
83
 
         end
 
83
                        end
84
84
                else
85
85
                        each_referer_orig( limit ) do |count, ref|
86
86
                                yield( count, ref )
105
105
end
106
106
 
107
107
def referer_update( diary )
 
108
        # ignore an invalid URL including a non-ASCII character
 
109
        return if @cgi.referer && !@cgi.referer.match(/^[!-~]+$/)
 
110
 
108
111
        @referer_volatile = RefererDiary::new( @conf.latest_limit )
109
112
 
110
113
        case @mode
145
148
 
146
149
def referer_load( file, diary )
147
150
        begin
148
 
                File::open( file ) do |fh|
 
151
                File::open( file, 'rb' ) do |fh|
149
152
                        fh.flock( File::LOCK_SH )
150
153
                        fh.gets # read magic
151
154
                        fh.read.split( /\r?\n\.\r?\n/ ).each do |l|
152
155
                                headers, body = ::TDiary::parse_tdiary( l )
153
 
                                yield( headers, body )
 
156
                                yield( headers, @conf.to_native( body ) )
154
157
                        end
155
158
                end
156
159
        rescue Errno::ENOENT
284
287
        end
285
288
end
286
289
 
 
290
 
 
291
# Local Variables:
 
292
# mode: ruby
 
293
# indent-tabs-mode: t
 
294
# tab-width: 3
 
295
# ruby-indent-level: 3
 
296
# End: