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

« back to all changes in this revision

Viewing changes to index.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
1
#!/usr/bin/env ruby
2
 
#
3
 
# index.rb $Revision: 1.35 $
4
 
#
5
 
# Copyright (C) 2001-2006, TADA Tadashi <sho@spc.gr.jp>
 
2
# -*- coding: utf-8; -*-
 
3
#
 
4
# index.rb
 
5
#
 
6
# Copyright (C) 2001-2009, TADA Tadashi <t@tdtds.jp>
6
7
# You can redistribute it and/or modify it under GPL2.
7
8
#
8
 
BEGIN { $defout.binmode }
9
 
$KCODE = 'n'
 
9
BEGIN { $stdout.binmode }
 
10
begin
 
11
        Encoding::default_external = 'UTF-8'
 
12
rescue NameError
 
13
        $KCODE = 'n'
 
14
end
10
15
 
11
16
begin
12
17
        if FileTest::symlink?( __FILE__ ) then
13
 
                org_path = File::dirname( File::readlink( __FILE__ ) )
 
18
                org_path = File::dirname( File::readlink( __FILE__ ) ).untaint
14
19
        else
15
 
                org_path = File::dirname( __FILE__ )
 
20
                org_path = File::dirname( __FILE__ ).untaint
16
21
        end
17
 
        $:.unshift( org_path.untaint )
 
22
        $:.unshift( org_path ) unless $:.include?( org_path )
18
23
        require 'tdiary'
19
24
 
20
 
        @cgi = CGI::new
 
25
        encoding_error = {}
 
26
        cgi = CGI::new(:accept_charset => "UTF-8") do |name, value|
 
27
                encoding_error[name] = value
 
28
        end
 
29
        if encoding_error.empty?
 
30
                @cgi = cgi
 
31
        else
 
32
                @cgi = CGI::new(:accept_charset => 'shift_jis')
 
33
                @cgi.params = cgi.params
 
34
        end
 
35
 
21
36
        conf = TDiary::Config::new(@cgi)
22
37
        tdiary = nil
23
38
        status = nil
42
57
                        end
43
58
                elsif @cgi.valid?( 'category' )
44
59
                        tdiary = TDiary::TDiaryCategoryView::new( @cgi, "category.rhtml", conf )
 
60
                elsif @cgi.valid?( 'q' )
 
61
                        tdiary = TDiary::TDiarySearch::new( @cgi, "search.rhtml", conf )
45
62
                else
46
63
                        tdiary = TDiary::TDiaryLatest::new( @cgi, "latest.rhtml", conf )
47
64
                end
68
85
                        if @cgi.mobile_agent? then
69
86
                                body = conf.to_mobile( tdiary.eval_rhtml( 'i.' ) )
70
87
                                head['charset'] = conf.mobile_encoding
71
 
                                head['Content-Length'] = body.size.to_s
 
88
                                head['Content-Length'] = body.bytesize.to_s
72
89
                        else
73
90
                                require 'digest/md5'
74
91
                                body = tdiary.eval_rhtml
78
95
                                        body = ''
79
96
                                else
80
97
                                        head['charset'] = conf.encoding
81
 
                                        head['Content-Length'] = body.size.to_s
 
98
                                        head['Content-Length'] = body.bytesize.to_s
82
99
                                end
83
100
                                head['Pragma'] = 'no-cache'
84
101
                                head['Cache-Control'] = 'no-cache'
87
104
                        print @cgi.header( head )
88
105
                        print body
89
106
                end
90
 
        rescue TDiary::ForceRedirect
91
 
                head = {
92
 
                        #'Location' => $!.path
93
 
                        'type' => 'text/html',
94
 
                }
95
 
                head['cookie'] = tdiary.cookies if tdiary.cookies.size > 0
96
 
                print @cgi.header( head )
97
 
                print %Q[
98
 
                        <html>
99
 
                        <head>
100
 
                        <meta http-equiv="refresh" content="1;url=#{$!.path}">
101
 
                        <title>moving...</title>
102
 
                        </head>
103
 
                        <body>Wait or <a href="#{$!.path}">Click here!</a></body>
104
 
                        </html>]
 
107
        rescue TDiary::NotFound
 
108
                if @cgi then
 
109
                        print @cgi.header( 'status' => CGI::HTTP_STATUS['NOT_FOUND'], 'type' => 'text/html' )
 
110
                else
 
111
                        print "Status: 404 Not Found\n"
 
112
                        print "Content-Type: text/html\n\n"
 
113
                end
 
114
                puts "<h1>404 Not Found</h1>"
 
115
                puts "<div>#{' ' * 500}</div>"
105
116
        end
 
117
rescue TDiary::ForceRedirect
 
118
        head = {
 
119
                #'Location' => $!.path
 
120
                'type' => 'text/html',
 
121
        }
 
122
        head['cookie'] = tdiary.cookies if tdiary && tdiary.cookies.size > 0
 
123
        print @cgi.header( head )
 
124
        print %Q[
 
125
                <html>
 
126
                <head>
 
127
                <meta http-equiv="refresh" content="1;url=#{$!.path}">
 
128
                <title>moving...</title>
 
129
                </head>
 
130
                <body>Wait or <a href="#{$!.path}">Click here!</a></body>
 
131
                </html>]
106
132
rescue Exception
107
133
        if @cgi then
108
134
                print @cgi.header( 'status' => CGI::HTTP_STATUS['SERVER_ERROR'], 'type' => 'text/html' )
119
145
        puts "<div>#{' ' * 500}</div>"
120
146
end
121
147
 
 
148
 
 
149
# Local Variables:
 
150
# mode: ruby
 
151
# indent-tabs-mode: t
 
152
# tab-width: 3
 
153
# ruby-indent-level: 3
 
154
# End: