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

« back to all changes in this revision

Viewing changes to contrib2/plugin/google_sitemaps.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
# google_sitemap.rb
 
2
# Copyright (c) 2006 http://d.bulkitem.com/
 
3
# Distributed under the GPL
 
4
 
 
5
add_update_proc do
 
6
  require 'time'
 
7
 
 
8
  headers = Array.new
 
9
  header = Hash.new
 
10
 
 
11
  Dir.glob(@conf.data_path + '/????/*.td2') { |data_file|
 
12
    File.open(data_file) { |buffer|
 
13
      buffer.each { |line|
 
14
        line.strip!
 
15
        if line == "." then
 
16
          if  header['visible'] then
 
17
            headers.push(header.clone)
 
18
          end
 
19
          header.clear
 
20
        end
 
21
        if %r|^Date: ([0-9]+)$|i =~ line then
 
22
          header['loc'] = sprintf(@conf['google_sitemaps.uri_format'], $1)
 
23
        end
 
24
        if %r|^Last-Modified: ([0-9]+)$|i =~ line then
 
25
          header['lastmod'] = Time.at($1.to_i).iso8601
 
26
        end
 
27
        if %r|^Visible: (.+)$|i =~ line then
 
28
          if $1.upcase == "TRUE" then
 
29
            header['visible'] = true
 
30
          else
 
31
            header['visible'] = false
 
32
          end
 
33
        end
 
34
      }
 
35
    }
 
36
  }
 
37
 
 
38
  headers.sort! { |a, b| b['loc'] <=> a['loc']}
 
39
 
 
40
  top_page_uri = File::dirname(@conf['google_sitemaps.uri_format']) + '/'
 
41
  now_datetime = Time.now.iso8601
 
42
 
 
43
  File.open(@conf['google_sitemaps.output_file'], 'w') do |fp|
 
44
    fp.write %Q[<?xml version="1.0" encoding="UTF-8"?>\n]
 
45
    fp.write %Q[<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">\n]
 
46
    fp.write %Q[ <url><loc>#{CGI::escapeHTML(top_page_uri)}</loc><lastmod>#{now_datetime}</lastmod></url>\n]
 
47
    headers.each { |entry|
 
48
      fp.write %Q[ <url><loc>#{CGI::escapeHTML(entry['loc'])}</loc><lastmod>#{entry['lastmod']}</lastmod></url>\n]
 
49
    }
 
50
    fp.write %Q[</urlset>\n]
 
51
  end
 
52
end
 
53
 
 
54
def saveconf_google_sitemaps
 
55
  if @mode == 'saveconf' then
 
56
    @conf['google_sitemaps.uri_format'] = @cgi.params['google_sitemaps.uri_format'][0]
 
57
    @conf['google_sitemaps.output_file'] = @cgi.params['google_sitemaps.output_file'][0]
 
58
  end
 
59
end
 
60