knjrbfw 0.0.111 → 0.0.113
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/knjrbfw.gemspec +3 -7
- data/lib/knj/image.rb +61 -50
- data/lib/knj/scripts/php_to_rb_helper.rb +13 -20
- data/lib/knj/web.rb +135 -136
- metadata +2 -6
- data/lib/knj/datarow.rb +0 -873
- data/lib/knj/datarow_custom.rb +0 -153
- data/lib/knj/scripts/process_meta_exec.rb +0 -144
- data/lib/knj/translations.rb +0 -133
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66637edb9c36f0d7ea2b74ef01525eac6504e558
|
4
|
+
data.tar.gz: 0618414f52721e98c76b6a87d2f1bbd30dfb948a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90be6e975266b2179b6689ff362b150afbb4871ccb9eb175fc1a1bc8b2bf1c823ebc8e36389db3387697fcf07ea45d6ae1bc4aabbacf8051c82532d052b0c13e
|
7
|
+
data.tar.gz: 212fa35ff3ea29a7bc6186be6a1df13dd1ab1d405db62979e6d4407f3203a3e0a0f73b1c978e34e013a996bdd9e627a66a037ac58a8d0432b279594e6a2c52b6
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.113
|
data/knjrbfw.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: knjrbfw 0.0.
|
5
|
+
# stub: knjrbfw 0.0.113 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "knjrbfw"
|
9
|
-
s.version = "0.0.
|
9
|
+
s.version = "0.0.113"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Kasper Johansen"]
|
14
|
-
s.date = "2015-04-
|
14
|
+
s.date = "2015-04-21"
|
15
15
|
s.description = "Including stuff for HTTP, SSH and much more."
|
16
16
|
s.email = "k@spernj.org"
|
17
17
|
s.extra_rdoc_files = [
|
@@ -61,8 +61,6 @@ Gem::Specification.new do |s|
|
|
61
61
|
"lib/knj/compiler.rb",
|
62
62
|
"lib/knj/cpufreq.rb",
|
63
63
|
"lib/knj/csv.rb",
|
64
|
-
"lib/knj/datarow.rb",
|
65
|
-
"lib/knj/datarow_custom.rb",
|
66
64
|
"lib/knj/degulesider.rb",
|
67
65
|
"lib/knj/erb/apache_knjerb.conf",
|
68
66
|
"lib/knj/erb/cache/README",
|
@@ -196,7 +194,6 @@ Gem::Specification.new do |s|
|
|
196
194
|
"lib/knj/scripts/ip2location.rb",
|
197
195
|
"lib/knj/scripts/keepalive.rb",
|
198
196
|
"lib/knj/scripts/php_to_rb_helper.rb",
|
199
|
-
"lib/knj/scripts/process_meta_exec.rb",
|
200
197
|
"lib/knj/scripts/speed_test.rb",
|
201
198
|
"lib/knj/scripts/svn_merge.rb",
|
202
199
|
"lib/knj/scripts/upgrade_knjrbfw_checker.rb",
|
@@ -215,7 +212,6 @@ Gem::Specification.new do |s|
|
|
215
212
|
"lib/knj/thread.rb",
|
216
213
|
"lib/knj/thread2.rb",
|
217
214
|
"lib/knj/threadhandler.rb",
|
218
|
-
"lib/knj/translations.rb",
|
219
215
|
"lib/knj/unix_proc.rb",
|
220
216
|
"lib/knj/web.rb",
|
221
217
|
"lib/knj/webscripts/image.rhtml",
|
data/lib/knj/image.rb
CHANGED
@@ -4,114 +4,125 @@ class Knj::Image
|
|
4
4
|
#===Examples
|
5
5
|
# img = Magick::Image.read(path_str)
|
6
6
|
# Knj::Image.rounded_corners(
|
7
|
-
# :
|
8
|
-
# :
|
9
|
-
# :
|
10
|
-
# :
|
7
|
+
# img: img,
|
8
|
+
# radius: 25,
|
9
|
+
# border: 1,
|
10
|
+
# border_color: "#000000"
|
11
11
|
# )
|
12
12
|
def self.rounded_corners(args)
|
13
|
-
raise "No or invalid ':img' given: '#{args}'."
|
13
|
+
raise "No or invalid ':img' given: '#{args}'." unless args[:img]
|
14
14
|
raise "No or invalid ':radius' given: '#{args}'." if !args[:radius].respond_to?(:to_i) || args[:radius].to_i <= 0
|
15
|
-
|
15
|
+
|
16
16
|
pic = args[:img]
|
17
17
|
raise "Format '#{pic.format}' does not support transparency." if pic.format == "JPEG"
|
18
|
-
|
18
|
+
|
19
19
|
r = args[:radius].to_i
|
20
20
|
r_half = r / 2
|
21
21
|
r2 = r * r
|
22
22
|
d = r * 2
|
23
|
-
|
23
|
+
|
24
24
|
center_x = r - 1
|
25
25
|
center_y = 1
|
26
|
-
|
26
|
+
|
27
27
|
coords = {}
|
28
28
|
0.upto(r) do |x|
|
29
29
|
y = center_y + ::Math.sqrt(r2 - ((x - center_x) * (x - center_x)))
|
30
30
|
coords[x] = y.to_i
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
if args[:border]
|
34
34
|
draw = ::Magick::Draw.new
|
35
35
|
draw.stroke(args[:border_color])
|
36
36
|
draw.stroke_width(1)
|
37
|
-
|
37
|
+
|
38
38
|
0.upto(args[:border] - 1) do |x|
|
39
39
|
draw.line(x, 0, x, pic.rows)
|
40
40
|
draw.line(pic.columns-x-1, 0, pic.columns-x-1, pic.rows)
|
41
|
-
|
41
|
+
|
42
42
|
draw.line(0, x, pic.columns, x)
|
43
43
|
draw.line(0, pic.rows-x-1, pic.columns, pic.rows-x-1)
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
draw.draw(pic)
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
borders = [] if args[:border]
|
50
|
-
|
50
|
+
|
51
51
|
1.upto(4) do |count|
|
52
52
|
r.times do |x|
|
53
53
|
border_from = nil
|
54
54
|
border_to = nil
|
55
55
|
border_mode = nil
|
56
|
-
|
56
|
+
|
57
57
|
case count
|
58
58
|
when 1
|
59
59
|
x_from = x
|
60
|
-
|
60
|
+
|
61
61
|
y_from = 0
|
62
62
|
y_to = r - coords[x]
|
63
|
-
|
64
|
-
if borders
|
63
|
+
|
64
|
+
if borders && x > 0 && x < r_half
|
65
65
|
border_from = y_to
|
66
66
|
border_to = r - coords[x - 1]
|
67
67
|
border_to = 1 if border_to < 1
|
68
|
-
|
68
|
+
|
69
69
|
#top left
|
70
|
-
borders << {:
|
71
|
-
borders << {:
|
72
|
-
|
70
|
+
borders << {x: x_from, yf: border_from, yt: border_to}
|
71
|
+
borders << {y: x_from, xf: border_from, xt: border_to}
|
72
|
+
|
73
73
|
#top right
|
74
|
-
borders << {:
|
75
|
-
borders << {:
|
76
|
-
|
74
|
+
borders << {x: pic.columns - x - 1, yf: border_from, yt: border_to}
|
75
|
+
borders << {y: x_from, xf: pic.columns - border_to, xt: pic.columns - border_from}
|
76
|
+
|
77
77
|
#bottom left
|
78
|
-
borders << {:
|
79
|
-
borders << {:
|
80
|
-
|
78
|
+
borders << {x: x_from, yf: pic.rows - border_to, yt: pic.rows - border_from}
|
79
|
+
borders << {y: pic.rows - x - 1, xf: border_from, xt: border_to}
|
80
|
+
|
81
81
|
#bottom right
|
82
|
-
borders << {:
|
83
|
-
borders << {:
|
82
|
+
borders << {x: pic.columns - x - 1, yf: pic.rows - border_to, yt: pic.rows - border_from}
|
83
|
+
borders << {y: pic.rows - x - 1, xf: pic.columns - border_to, xt: pic.columns - border_from}
|
84
84
|
end
|
85
85
|
when 2
|
86
86
|
x_from = pic.columns - r + x
|
87
|
-
|
87
|
+
|
88
88
|
y_from = 0
|
89
89
|
y_to = r - coords[r - x - 1]
|
90
90
|
when 3
|
91
91
|
x_from = x
|
92
|
-
|
92
|
+
|
93
93
|
y_from = pic.rows - r + coords[x]
|
94
94
|
y_to = pic.rows - y_from
|
95
95
|
when 4
|
96
96
|
x_from = pic.columns - r + x
|
97
|
-
|
97
|
+
|
98
98
|
y_from = pic.rows - r + coords[r - x - 1]
|
99
99
|
y_to = pic.rows - y_from
|
100
100
|
end
|
101
|
-
|
101
|
+
|
102
102
|
next if y_to <= 0
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
103
|
+
|
104
|
+
if RUBY_ENGINE == "jruby"
|
105
|
+
# Hack around missing method in rmagick4j Image#get_pixels. It will be black :-(
|
106
|
+
pixels = []
|
107
|
+
y_to.times do |count|
|
108
|
+
pixel = Magick::Pixel.new(0, 0, 0, 255)
|
109
|
+
pixels << pixel
|
110
|
+
end
|
111
|
+
|
112
|
+
pic.store_pixels(x_from, y_from, 1, y_to, pixels)
|
113
|
+
else
|
114
|
+
pixels = pic.get_pixels(x_from, y_from, 1, y_to)
|
115
|
+
pixels.each do |pixel|
|
116
|
+
pixel.opacity = ::Magick::TransparentOpacity
|
117
|
+
end
|
118
|
+
pic.store_pixels(x_from, y_from, 1, y_to, pixels)
|
107
119
|
end
|
108
|
-
pic.store_pixels(x_from, y_from, 1, y_to, pixels)
|
109
120
|
end
|
110
121
|
end
|
111
|
-
|
122
|
+
|
112
123
|
if borders
|
113
124
|
color = args[:border_color]
|
114
|
-
|
125
|
+
|
115
126
|
borders.each do |border|
|
116
127
|
if border.key?(:x)
|
117
128
|
count_from = border[:yf]
|
@@ -120,18 +131,18 @@ class Knj::Image
|
|
120
131
|
count_from = border[:xf]
|
121
132
|
count_to = border[:xt]
|
122
133
|
end
|
123
|
-
|
134
|
+
|
124
135
|
count_from.upto(count_to - 1) do |coord|
|
125
|
-
if RUBY_ENGINE == "jruby"
|
136
|
+
if RUBY_ENGINE == "jruby" && color[0, 1] == "#"
|
126
137
|
r = color[1, 2].hex
|
127
138
|
b = color[3, 2].hex
|
128
139
|
g = color[5, 2].hex
|
129
|
-
|
140
|
+
|
130
141
|
pixel = ::Magick::Pixel.new(r, b, g)
|
131
142
|
else
|
132
143
|
pixel = ::Magick::Pixel.from_color(color)
|
133
144
|
end
|
134
|
-
|
145
|
+
|
135
146
|
if border.key?(:x)
|
136
147
|
if RUBY_ENGINE == "jruby"
|
137
148
|
pic.store_pixels(border[:x], coord, 1, 1, [pixel])
|
@@ -148,21 +159,21 @@ class Knj::Image
|
|
148
159
|
end
|
149
160
|
end
|
150
161
|
end
|
151
|
-
|
162
|
+
|
152
163
|
pic.matte = true
|
153
164
|
end
|
154
|
-
|
165
|
+
|
155
166
|
#Returns the width relative to the height.
|
156
167
|
#===Examples
|
157
168
|
# Knj::Image.width_for_height(640, 480, 400) #=> 533
|
158
169
|
def self.width_for_height(orig_width, orig_height, new_height)
|
159
170
|
return (orig_width.to_f / (orig_height.to_f / new_height.to_f)).to_i
|
160
171
|
end
|
161
|
-
|
172
|
+
|
162
173
|
#Returns the height relative to the width.
|
163
174
|
#===Examples
|
164
175
|
# Knj::Image.height_for_width(640, 480, 533) #=> 399
|
165
176
|
def self.height_for_width(orig_width, orig_height, new_width)
|
166
177
|
return (orig_height.to_f / (orig_width.to_f / new_width.to_f)).to_i
|
167
178
|
end
|
168
|
-
end
|
179
|
+
end
|
@@ -7,11 +7,11 @@ begin
|
|
7
7
|
options = {}
|
8
8
|
OptionParser.new do |opts|
|
9
9
|
opts.banner = "Usage: example.rb [options]"
|
10
|
-
|
10
|
+
|
11
11
|
opts.on("-f PHPFILE", "--file", "The PHP-file you want help to convert.") do |f|
|
12
12
|
options[:file] = f
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
opts.on("-t", "--tags-remove", "Removes the PHP-tags completely.") do |t|
|
16
16
|
options[:tags] = false
|
17
17
|
end
|
@@ -37,15 +37,8 @@ cont.gsub!(/\A#!\/usr\/bin\/env\s+php5/, "!#/usr/bin/env ruby1.9.1")
|
|
37
37
|
#Replace class extends.
|
38
38
|
cont.scan(/(class\s+(.+?)\s+extends\s+(.+?){)/) do |match|
|
39
39
|
rb_classname = "#{match[1][0..0].upcase}#{match[1][1..999]}"
|
40
|
-
|
41
|
-
if match[2] == "knjdb_row"
|
42
|
-
extends = "Knj::Datarow"
|
43
|
-
else
|
44
|
-
extends = "#{match[2][0..0].upcase}#{match[2][1..999]}"
|
45
|
-
end
|
46
|
-
|
40
|
+
extends = "#{match[2][0..0].upcase}#{match[2][1..999]}"
|
47
41
|
rb_str = "class #{rb_classname} < #{extends}"
|
48
|
-
|
49
42
|
cont = cont.gsub(match[0], rb_str)
|
50
43
|
end
|
51
44
|
|
@@ -54,7 +47,7 @@ end
|
|
54
47
|
cont.scan(/(class\s+(.+?)\s*{)/) do |match|
|
55
48
|
rb_classname = "#{match[1][0..0].upcase}#{match[1][1..999]}"
|
56
49
|
rb_str = "class #{rb_classname}"
|
57
|
-
|
50
|
+
|
58
51
|
cont = cont.gsub(match[0], rb_str)
|
59
52
|
end
|
60
53
|
|
@@ -68,7 +61,7 @@ cont.scan(/(static\s+function\s+(.+?)\((.*?)\)\s*{)/) do |match|
|
|
68
61
|
else
|
69
62
|
func_name = match[1]
|
70
63
|
end
|
71
|
-
|
64
|
+
|
72
65
|
rb_str = "def self.#{func_name}(#{match[2]})"
|
73
66
|
cont = cont.gsub(match[0], rb_str)
|
74
67
|
end
|
@@ -101,7 +94,7 @@ end
|
|
101
94
|
cont.scan(/((\s+?)}\s*catch\s*\(\s*(#{regexes["class"]})\s+\$(#{regexes["var"]})\s*\)\s*{(\s+))/) do |match|
|
102
95
|
classname = "#{match[2][0..0].upcase}#{match[2][1..999]}"
|
103
96
|
classname = "Errno::ENOENT" if classname == "Knjdb_rownotfound_exception"
|
104
|
-
|
97
|
+
|
105
98
|
rb_str = "#{match[1]}rescue #{classname} => #{match[3]}#{match[4]}"
|
106
99
|
cont = cont.gsub(match[0], rb_str)
|
107
100
|
end
|
@@ -111,7 +104,7 @@ end
|
|
111
104
|
cont.scan(/((\s+?)require_once\s+\"(.+)\"\s*;(\s+?))/) do |match|
|
112
105
|
filename = match[2]
|
113
106
|
filename.gsub!(/\.php$/, ".rb")
|
114
|
-
|
107
|
+
|
115
108
|
rb_str = "#{match[1]}require \"#{filename}\"#{match[3]}"
|
116
109
|
cont = cont.gsub(match[0], rb_str)
|
117
110
|
end
|
@@ -123,7 +116,7 @@ cont.scan(/(function\s(.+?)\((.*?)\))/) do |match|
|
|
123
116
|
def_args.scan(/(([A-z]+)\s+\$(#{regexes["var"]}))/) do |match_arg|
|
124
117
|
def_args = def_args.gsub(match_arg[0], "#{match_arg[2]}")
|
125
118
|
end
|
126
|
-
|
119
|
+
|
127
120
|
rb_str = "def #{match[1]}(#{def_args})"
|
128
121
|
cont = cont.gsub(match[0], rb_str)
|
129
122
|
end
|
@@ -267,11 +260,11 @@ end
|
|
267
260
|
#Replace multi-line comments.
|
268
261
|
cont.scan(/((\s+|<\?)\/\*([\s\S]+?)\*\/)/) do |match|
|
269
262
|
rb_str = "\n=begin\n#{match[2]}\n=end\n"
|
270
|
-
|
263
|
+
|
271
264
|
if match[1] == "<?"
|
272
265
|
rb_str = "<%#{rb_str}"
|
273
266
|
end
|
274
|
-
|
267
|
+
|
275
268
|
cont = cont.gsub(match[0], rb_str)
|
276
269
|
end
|
277
270
|
|
@@ -300,14 +293,14 @@ end
|
|
300
293
|
#Replace variable-names.
|
301
294
|
cont.scan(/(([^%\d])(\$(#{regexes["var"]})))/) do |match|
|
302
295
|
vname = match[3]
|
303
|
-
|
296
|
+
|
304
297
|
if vname[-1..-1] == "["
|
305
298
|
vname = vname[0..-2]
|
306
299
|
match[0] = match[0][0..-2]
|
307
300
|
match[2] = match[2][0..-2]
|
308
301
|
match[3] = match[3][0..-2]
|
309
302
|
end
|
310
|
-
|
303
|
+
|
311
304
|
if vname == "this"
|
312
305
|
rb_varname = "self"
|
313
306
|
elsif global_vars.key?(vname)
|
@@ -315,7 +308,7 @@ cont.scan(/(([^%\d])(\$(#{regexes["var"]})))/) do |match|
|
|
315
308
|
else
|
316
309
|
rb_varname = "#{vname}"
|
317
310
|
end
|
318
|
-
|
311
|
+
|
319
312
|
cont = cont.gsub(match[2], rb_varname)
|
320
313
|
end
|
321
314
|
|
data/lib/knj/web.rb
CHANGED
@@ -7,72 +7,72 @@ class Knj::Web
|
|
7
7
|
def self.parse_uri(str)
|
8
8
|
uri_match = str.to_s.match(/^\/(.+?\..*?|)(\?(.*)|)$/)
|
9
9
|
raise "Could not parse the URI: '#{str}'." if !uri_match
|
10
|
-
|
10
|
+
|
11
11
|
return {
|
12
12
|
:path => "/#{uri_match[1]}",
|
13
13
|
:query => uri_match[3]
|
14
14
|
}
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
#Parses cookies-string and returns hash with parsed cookies.
|
18
18
|
def self.parse_cookies(str)
|
19
19
|
ret = {}
|
20
|
-
|
20
|
+
|
21
21
|
str.split(/;\s*/).each do |cookie_str|
|
22
22
|
if !match = cookie_str.match(/^(.*?)=\"(.*)\"$/)
|
23
23
|
match = cookie_str.match(/^(.*?)=(.*)$/)
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
ret[self.urldec(match[1])] = self.urldec(match[2]) if match
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
return ret
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
def self.parse_set_cookies(str)
|
33
33
|
str = String.new(str.to_s)
|
34
34
|
return [] if str.length <= 0
|
35
35
|
args = {}
|
36
36
|
cookie_start_regex = /^(.+?)=(.*?)(;\s*|$)/
|
37
|
-
|
37
|
+
|
38
38
|
match = str.match(cookie_start_regex)
|
39
39
|
raise "Could not match cookie: '#{str}'." if !match
|
40
40
|
str.gsub!(cookie_start_regex, "")
|
41
|
-
|
41
|
+
|
42
42
|
args["name"] = self.urldec(match[1].to_s)
|
43
43
|
args["value"] = self.urldec(match[2].to_s)
|
44
|
-
|
44
|
+
|
45
45
|
while match = str.match(/(.+?)=(.*?)(;\s*|$)/)
|
46
46
|
str = str.gsub(match[0], "")
|
47
47
|
args[match[1].to_s.downcase] = match[2].to_s
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
return [args]
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
def self.cookie_str(cookie_data)
|
54
54
|
raise "Not a hash: '#{cookie_data.class.name}', '#{cookie_data}'." unless cookie_data.is_a?(Hash)
|
55
55
|
cookiestr = "#{self.urlenc(cookie_data["name"])}=#{self.urlenc(cookie_data["value"])}"
|
56
|
-
|
56
|
+
|
57
57
|
cookie_data.each do |key, val|
|
58
58
|
next if key == "name" or key == "value"
|
59
|
-
|
59
|
+
|
60
60
|
if key.to_s.downcase == "expires" and val.is_a?(Time)
|
61
61
|
cookiestr << "; Expires=#{val.httpdate}"
|
62
62
|
else
|
63
63
|
cookiestr << "; #{key}=#{val}"
|
64
64
|
end
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
return cookiestr
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
#Parses a query and returns the various _GET-variables.
|
71
71
|
def self.parse_urlquery(querystr, args = {})
|
72
72
|
get = {}
|
73
73
|
querystr.to_s.split("&").each do |value|
|
74
74
|
pos = value.index("=")
|
75
|
-
|
75
|
+
|
76
76
|
if pos != nil
|
77
77
|
name = value[0..pos-1]
|
78
78
|
name = name.to_sym if args[:syms]
|
@@ -80,10 +80,10 @@ class Knj::Web
|
|
80
80
|
Knj::Web.parse_name(get, Knj::Web.urldec(name), valuestr, args)
|
81
81
|
end
|
82
82
|
end
|
83
|
-
|
83
|
+
|
84
84
|
return get
|
85
85
|
end
|
86
|
-
|
86
|
+
|
87
87
|
def self.parse_name(seton, varname, value, args = {})
|
88
88
|
if value.respond_to?(:filename) and value.filename
|
89
89
|
realvalue = value
|
@@ -92,18 +92,18 @@ class Knj::Web
|
|
92
92
|
realvalue = self.urldec(realvalue) if args[:urldecode]
|
93
93
|
realvalue = realvalue.force_encoding("utf-8") if args[:force_utf8] if realvalue.respond_to?(:force_encoding)
|
94
94
|
end
|
95
|
-
|
95
|
+
|
96
96
|
if varname and varname.index("[") != nil and match = varname.match(/\[(.*?)\]/)
|
97
97
|
namepos = varname.index(match[0])
|
98
98
|
name = varname.slice(0..namepos - 1)
|
99
99
|
name = name.to_sym if args[:syms]
|
100
100
|
seton[name] = {} if !seton.key?(name)
|
101
|
-
|
101
|
+
|
102
102
|
secname, secname_empty = Knj::Web.parse_secname(seton[name], match[1], args)
|
103
|
-
|
103
|
+
|
104
104
|
valuefrom = namepos + secname.to_s.length + 2
|
105
105
|
restname = varname.slice(valuefrom..-1)
|
106
|
-
|
106
|
+
|
107
107
|
if restname and restname.index("[") != nil
|
108
108
|
seton[name][secname] = {} if !seton[name].key?(secname)
|
109
109
|
Knj::Web.parse_name_second(seton[name][secname], restname, value, args)
|
@@ -114,13 +114,13 @@ class Knj::Web
|
|
114
114
|
seton[varname] = realvalue
|
115
115
|
end
|
116
116
|
end
|
117
|
-
|
117
|
+
|
118
118
|
def self.parse_secname(seton, secname, args)
|
119
119
|
secname_empty = false
|
120
120
|
if secname.length <= 0
|
121
121
|
secname_empty = true
|
122
122
|
try = 0
|
123
|
-
|
123
|
+
|
124
124
|
loop do
|
125
125
|
if !seton.key?(try.to_s)
|
126
126
|
break
|
@@ -128,14 +128,14 @@ class Knj::Web
|
|
128
128
|
try += 1
|
129
129
|
end
|
130
130
|
end
|
131
|
-
|
131
|
+
|
132
132
|
secname = try.to_s
|
133
133
|
end
|
134
|
-
|
134
|
+
|
135
135
|
secname = secname.to_sym if args[:syms] and secname.is_a?(String) and !(Float(secname) rescue false)
|
136
136
|
return [secname, secname_empty]
|
137
137
|
end
|
138
|
-
|
138
|
+
|
139
139
|
def self.parse_name_second(seton, varname, value, args = {})
|
140
140
|
if value.respond_to?(:filename) and value.filename
|
141
141
|
realvalue = value
|
@@ -143,16 +143,16 @@ class Knj::Web
|
|
143
143
|
realvalue = value.to_s
|
144
144
|
realvalue = realvalue.force_encoding("utf-8") if args[:force_utf8]
|
145
145
|
end
|
146
|
-
|
146
|
+
|
147
147
|
match = varname.match(/^\[(.*?)\]/)
|
148
148
|
if match
|
149
149
|
namepos = varname.index(match[0])
|
150
150
|
name = match[1]
|
151
151
|
secname, secname_empty = Knj::Web.parse_secname(seton, match[1], args)
|
152
|
-
|
152
|
+
|
153
153
|
valuefrom = namepos + match[1].length + 2
|
154
154
|
restname = varname.slice(valuefrom..-1)
|
155
|
-
|
155
|
+
|
156
156
|
if restname and restname.index("[") != nil
|
157
157
|
seton[secname] = {} if !seton.key?(secname)
|
158
158
|
Knj::Web.parse_name_second(seton[secname], restname, value, args)
|
@@ -163,30 +163,30 @@ class Knj::Web
|
|
163
163
|
seton[varname] = realvalue
|
164
164
|
end
|
165
165
|
end
|
166
|
-
|
166
|
+
|
167
167
|
def self.require_eruby(filepath)
|
168
168
|
cont = File.read(filepath).untaint
|
169
169
|
parse = Erubis.Eruby.new(cont)
|
170
170
|
eval(parse.src.to_s)
|
171
171
|
end
|
172
|
-
|
172
|
+
|
173
173
|
def self.alert(string)
|
174
174
|
require "#{$knjpath}strings"
|
175
|
-
|
175
|
+
|
176
176
|
begin
|
177
177
|
_httpsession.alert_sent = true
|
178
178
|
rescue NameError
|
179
179
|
#ignore.
|
180
180
|
end
|
181
|
-
|
181
|
+
|
182
182
|
@alert_sent = true
|
183
|
-
|
183
|
+
|
184
184
|
html = "<script type=\"text/javascript\">alert(\"#{Knj::Strings.js_safe(string.to_s)}\");</script>"
|
185
185
|
print html
|
186
|
-
|
186
|
+
|
187
187
|
return self
|
188
188
|
end
|
189
|
-
|
189
|
+
|
190
190
|
#Redirects to another URL.
|
191
191
|
#===Examples
|
192
192
|
# Knj::Web.redirect("someotherpage.rhtml")
|
@@ -200,22 +200,22 @@ class Knj::Web
|
|
200
200
|
else
|
201
201
|
_httpsession.resp.status = 303 if !_hb.headers_sent?
|
202
202
|
end
|
203
|
-
|
203
|
+
|
204
204
|
_hb.header("Location", url) if !_hb.headers_sent?
|
205
205
|
end
|
206
206
|
rescue NameError
|
207
207
|
#ignore.
|
208
208
|
end
|
209
|
-
|
209
|
+
|
210
210
|
print "<script type=\"text/javascript\">location.href=\"#{url}\";</script>"
|
211
211
|
exit
|
212
212
|
end
|
213
|
-
|
213
|
+
|
214
214
|
def self.back
|
215
215
|
print "<script type=\"text/javascript\">history.go(-1);</script>"
|
216
216
|
exit
|
217
217
|
end
|
218
|
-
|
218
|
+
|
219
219
|
def self.checkval(value, val1, val2 = nil)
|
220
220
|
if val2 != nil
|
221
221
|
if !value or value == "" or value == "false"
|
@@ -231,7 +231,7 @@ class Knj::Web
|
|
231
231
|
end
|
232
232
|
end
|
233
233
|
end
|
234
|
-
|
234
|
+
|
235
235
|
def self.inputs(arr)
|
236
236
|
html = ""
|
237
237
|
arr.each do |args|
|
@@ -241,38 +241,38 @@ class Knj::Web
|
|
241
241
|
html << self.input(args)
|
242
242
|
end
|
243
243
|
end
|
244
|
-
|
244
|
+
|
245
245
|
return html
|
246
246
|
end
|
247
|
-
|
247
|
+
|
248
248
|
def self.style_html(css)
|
249
249
|
return "" if css.length <= 0
|
250
|
-
|
250
|
+
|
251
251
|
str = " style=\""
|
252
|
-
|
252
|
+
|
253
253
|
css.each do |key, val|
|
254
254
|
str << "#{key}: #{val};"
|
255
255
|
end
|
256
|
-
|
256
|
+
|
257
257
|
str << "\""
|
258
|
-
|
258
|
+
|
259
259
|
return str
|
260
260
|
end
|
261
|
-
|
261
|
+
|
262
262
|
def self.attr_html(attrs)
|
263
263
|
return "" if attrs.length <= 0
|
264
|
-
|
264
|
+
|
265
265
|
html = ""
|
266
266
|
attrs.each do |key, val|
|
267
267
|
html << " #{key}=\"#{val.to_s.html}\""
|
268
268
|
end
|
269
|
-
|
269
|
+
|
270
270
|
return html
|
271
271
|
end
|
272
|
-
|
272
|
+
|
273
273
|
def self.input(args)
|
274
274
|
Knj::ArrayExt.hash_sym(args)
|
275
|
-
|
275
|
+
|
276
276
|
if args.key?(:value)
|
277
277
|
if args[:value].is_a?(Array) and (args[:value].first.is_a?(NilClass) or args[:value].first == false)
|
278
278
|
value = nil
|
@@ -290,18 +290,18 @@ class Knj::Web
|
|
290
290
|
value = args[:value]
|
291
291
|
end
|
292
292
|
end
|
293
|
-
|
293
|
+
|
294
294
|
args[:value_default] = args[:default] if args[:default]
|
295
|
-
|
295
|
+
|
296
296
|
if value.is_a?(NilClass) and args[:value_default]
|
297
297
|
value = args[:value_default]
|
298
298
|
elsif value.is_a?(NilClass)
|
299
299
|
value = ""
|
300
300
|
end
|
301
|
-
|
301
|
+
|
302
302
|
if value and args.key?(:value_func) and args[:value_func]
|
303
303
|
cback = args[:value_func]
|
304
|
-
|
304
|
+
|
305
305
|
if cback.is_a?(Method)
|
306
306
|
value = cback.call(value)
|
307
307
|
elsif cback.is_a?(Array)
|
@@ -312,10 +312,10 @@ class Knj::Web
|
|
312
312
|
raise "Unknown class: #{cback.class.name}."
|
313
313
|
end
|
314
314
|
end
|
315
|
-
|
315
|
+
|
316
316
|
value = args[:values] if args[:values]
|
317
317
|
args[:id] = args[:name] if !args[:id]
|
318
|
-
|
318
|
+
|
319
319
|
if !args[:type]
|
320
320
|
if args[:opts]
|
321
321
|
args[:type] = :select
|
@@ -329,7 +329,7 @@ class Knj::Web
|
|
329
329
|
else
|
330
330
|
args[:type] = args[:type].to_sym
|
331
331
|
end
|
332
|
-
|
332
|
+
|
333
333
|
attr = {
|
334
334
|
"name" => args[:name],
|
335
335
|
"id" => args[:id],
|
@@ -339,46 +339,46 @@ class Knj::Web
|
|
339
339
|
attr.merge!(args[:attr]) if args[:attr]
|
340
340
|
attr["disabled"] = "disabled" if args[:disabled]
|
341
341
|
attr["maxlength"] = args[:maxlength] if args.key?(:maxlength)
|
342
|
-
|
342
|
+
|
343
343
|
raise "No name given to the Web::input()-method." if !args[:name] and args[:type] != :info and args[:type] != :textshow and args[:type] != :plain and args[:type] != :spacer and args[:type] != :headline
|
344
|
-
|
344
|
+
|
345
345
|
css = {}
|
346
346
|
css["text-align"] = args[:align] if args.key?(:align)
|
347
347
|
css.merge!(args[:css]) if args.key?(:css)
|
348
|
-
|
348
|
+
|
349
349
|
attr_keys = [:onchange]
|
350
350
|
attr_keys.each do |tag|
|
351
351
|
if args.key?(tag)
|
352
352
|
attr[tag] = args[tag]
|
353
353
|
end
|
354
354
|
end
|
355
|
-
|
355
|
+
|
356
356
|
classes_tr = []
|
357
357
|
classes_tr += args[:classes_tr] if args[:classes_tr]
|
358
|
-
|
358
|
+
|
359
359
|
if !classes_tr.empty?
|
360
360
|
classes_tr_html = " class=\"#{classes_tr.join(" ")}\""
|
361
361
|
else
|
362
362
|
classes_tr_html = ""
|
363
363
|
end
|
364
|
-
|
364
|
+
|
365
365
|
if args.key?(:title)
|
366
366
|
title_html = args[:title].to_s.html
|
367
367
|
elsif args.key?(:title_html)
|
368
368
|
title_html = args[:title_html]
|
369
369
|
end
|
370
|
-
|
370
|
+
|
371
371
|
html = ""
|
372
|
-
|
372
|
+
|
373
373
|
classes = ["input_#{args[:type]}"]
|
374
374
|
classes = classes | args[:classes] if args.key?(:classes)
|
375
375
|
attr["class"] = classes.join(" ")
|
376
|
-
|
376
|
+
|
377
377
|
if args[:type] == :checkbox
|
378
378
|
attr["value"] = args[:value_active] if args.key?(:value_active)
|
379
379
|
attr["checked"] = "checked" if value.is_a?(String) and value == "1" or value.to_s == "1" or value.to_s == "on" or value.to_s == "true"
|
380
380
|
attr["checked"] = "checked" if value.is_a?(TrueClass)
|
381
|
-
|
381
|
+
|
382
382
|
html << "<tr#{classes_tr_html}>"
|
383
383
|
html << "<td colspan=\"2\" class=\"tdcheck\">"
|
384
384
|
html << "<input#{self.attr_html(attr)} />"
|
@@ -395,7 +395,7 @@ class Knj::Web
|
|
395
395
|
html << title_html
|
396
396
|
html << "</div></td>"
|
397
397
|
html << "<td#{self.style_html(css)} class=\"tdc\" id=\"#{Knj::Web.html("#{args[:id]}_content")}\"><div>"
|
398
|
-
|
398
|
+
|
399
399
|
if args[:type] == :textarea
|
400
400
|
if args.key?(:height)
|
401
401
|
if (Float(args[:height]) rescue false)
|
@@ -404,11 +404,11 @@ class Knj::Web
|
|
404
404
|
css["height"] = args[:height]
|
405
405
|
end
|
406
406
|
end
|
407
|
-
|
407
|
+
|
408
408
|
html << "<textarea#{self.style_html(css)} class=\"input_textarea\" name=\"#{args[:name].html}\" id=\"#{args[:id].html}\">#{value}</textarea>"
|
409
409
|
elsif args[:type] == :fckeditor
|
410
410
|
args[:height] = 400 if !args[:height]
|
411
|
-
|
411
|
+
|
412
412
|
require "/usr/share/fckeditor/fckeditor.rb" if !Kernel.const_defined?(:FCKeditor)
|
413
413
|
fck = FCKeditor.new(args[:name])
|
414
414
|
fck.Height = args[:height].to_i
|
@@ -423,11 +423,11 @@ class Knj::Web
|
|
423
423
|
elsif args[:type] == :select
|
424
424
|
attr["multiple"] = "multiple" if args[:multiple]
|
425
425
|
attr["size"] = args["size"] if args[:size]
|
426
|
-
|
426
|
+
|
427
427
|
html << "<select#{self.attr_html(attr)}>"
|
428
428
|
html << Knj::Web.opts(args[:opts], value, args[:opts_args])
|
429
429
|
html << "</select>"
|
430
|
-
|
430
|
+
|
431
431
|
if args[:moveable]
|
432
432
|
html << "<div style=\"padding-top: 3px;\">"
|
433
433
|
html << "<input type=\"button\" value=\"#{_("Up")}\" onclick=\"select_moveup($('##{args[:id]}'));\" />"
|
@@ -438,20 +438,20 @@ class Knj::Web
|
|
438
438
|
html << "<table class=\"designtable\"><tr#{classes_tr_html}><td style=\"width: 100%;\">"
|
439
439
|
html << "<input type=\"file\" name=\"#{args[:name].html}\" class=\"input_file\" />"
|
440
440
|
html << "</td><td style=\"padding-left: 5px;\">"
|
441
|
-
|
441
|
+
|
442
442
|
raise "No path given for imageupload-input." if !args.key?(:path)
|
443
443
|
raise "No value given in arguments for imageupload-input." if !args.key?(:value)
|
444
|
-
|
444
|
+
|
445
445
|
path = args[:path].gsub("%value%", value.to_s).untaint
|
446
446
|
if File.exists?(path)
|
447
447
|
html << "<img src=\"image.rhtml?path=#{self.urlenc(path).html}&smartsize=100&rounded_corners=10&border_color=black&force=true&ts=#{Time.new.to_f}\" alt=\"Image\" />"
|
448
|
-
|
448
|
+
|
449
449
|
if args[:dellink]
|
450
450
|
dellink = args[:dellink].gsub("%value%", value.to_s)
|
451
451
|
html << "<div style=\"text-align: center;\">(<a href=\"javascript: if (confirm('#{_("Do you want to delete the image?")}')){location.href='#{dellink}';}\">#{_("delete")}</a>)</div>"
|
452
452
|
end
|
453
453
|
end
|
454
|
-
|
454
|
+
|
455
455
|
html << "</td></tr></table>"
|
456
456
|
elsif args[:type] == :file
|
457
457
|
html << "<input type=\"#{args[:type].to_s}\" class=\"input_#{args[:type].to_s}\" name=\"#{args[:name].html}\" />"
|
@@ -463,17 +463,17 @@ class Knj::Web
|
|
463
463
|
css["width"] = "100%"
|
464
464
|
css["height"] = args[:height] if args.key?(:height)
|
465
465
|
html << "<textarea#{self.attr_html(attr)}#{self.style_html(css)} id=\"#{args[:id]}\" name=\"#{args[:name]}\">#{value}</textarea>"
|
466
|
-
|
466
|
+
|
467
467
|
jshash = {
|
468
468
|
"id" => args[:id],
|
469
469
|
"start_highlight" => true
|
470
470
|
}
|
471
|
-
|
471
|
+
|
472
472
|
pos_keys = [:skip_init, :allow_toggle, :replace_tab_by_spaces, :toolbar, :syntax]
|
473
473
|
pos_keys.each do |key|
|
474
474
|
jshash[key.to_s] = args[key] if args.key?(key)
|
475
475
|
end
|
476
|
-
|
476
|
+
|
477
477
|
html << "<script type=\"text/javascript\">"
|
478
478
|
html << "function knj_web_init_#{args[:name]}(){"
|
479
479
|
html << "editAreaLoader.init(#{Php4r.json_encode(jshash)});"
|
@@ -487,35 +487,34 @@ class Knj::Web
|
|
487
487
|
attr[:value] = value
|
488
488
|
html << "<input#{self.attr_html(attr)} />"
|
489
489
|
end
|
490
|
-
|
490
|
+
|
491
491
|
html << "</div></td></tr>"
|
492
492
|
end
|
493
|
-
|
493
|
+
|
494
494
|
html << "<tr#{classes_tr_html}><td colspan=\"2\" class=\"tdd\">#{args[:descr]}</td></tr>" if args[:descr]
|
495
495
|
return html
|
496
496
|
end
|
497
|
-
|
497
|
+
|
498
498
|
def self.opts(opthash, curvalue = nil, opts_args = {})
|
499
499
|
opts_args = {} if !opts_args
|
500
500
|
Knj::ArrayExt.hash_sym(opts_args)
|
501
|
-
|
501
|
+
|
502
502
|
return "" if !opthash
|
503
503
|
cname = curvalue.class.name
|
504
|
-
|
505
|
-
|
504
|
+
|
506
505
|
html = ""
|
507
506
|
addsel = " selected=\"selected\"" if !curvalue
|
508
|
-
|
507
|
+
|
509
508
|
html << "<option#{addsel} value=\"\">#{_("Add new")}</option>" if opts_args and (opts_args[:add] or opts_args[:addnew])
|
510
509
|
html << "<option#{addsel} value=\"\">#{_("Choose")}</option>" if opts_args and opts_args[:choose]
|
511
510
|
html << "<option#{addsel} value=\"\">#{_("None")}</option>" if opts_args and opts_args[:none]
|
512
511
|
html << "<option#{addsel} value=\"\">#{_("All")}</option>" if opts_args and opts_args[:all]
|
513
|
-
|
512
|
+
|
514
513
|
if opthash.is_a?(Hash) or opthash.class.to_s == "Dictionary"
|
515
514
|
opthash.each do |key, value|
|
516
515
|
html << "<option"
|
517
516
|
sel = false
|
518
|
-
|
517
|
+
|
519
518
|
if curvalue.is_a?(Array) and curvalue.index(key) != nil
|
520
519
|
sel = true
|
521
520
|
elsif curvalue.to_s == key.to_s
|
@@ -523,7 +522,7 @@ class Knj::Web
|
|
523
522
|
elsif curvalue and curvalue.respond_to?(:is_knj?) and curvalue.id.to_s == key.to_s
|
524
523
|
sel = true
|
525
524
|
end
|
526
|
-
|
525
|
+
|
527
526
|
html << " selected=\"selected\"" if sel
|
528
527
|
html << " value=\"#{Knj::Web.html(key)}\">#{Knj::Web.html(value)}</option>"
|
529
528
|
end
|
@@ -536,18 +535,18 @@ class Knj::Web
|
|
536
535
|
end
|
537
536
|
end
|
538
537
|
end
|
539
|
-
|
538
|
+
|
540
539
|
return html
|
541
540
|
end
|
542
|
-
|
541
|
+
|
543
542
|
def self.rendering_engine(servervar = nil)
|
544
543
|
servervar = _server if !servervar
|
545
544
|
if !servervar
|
546
545
|
raise "Could not figure out meta data."
|
547
546
|
end
|
548
|
-
|
547
|
+
|
549
548
|
agent = servervar["HTTP_USER_AGENT"].to_s.downcase
|
550
|
-
|
549
|
+
|
551
550
|
if agent.include?("webkit") != nil
|
552
551
|
return "webkit"
|
553
552
|
elsif agent.include?("gecko") != nil
|
@@ -561,15 +560,15 @@ class Knj::Web
|
|
561
560
|
return false
|
562
561
|
end
|
563
562
|
end
|
564
|
-
|
563
|
+
|
565
564
|
def self.os(servervar = nil)
|
566
565
|
servervar = _server if !servervar
|
567
566
|
if !servervar
|
568
567
|
raise "Could not figure out meta data."
|
569
568
|
end
|
570
|
-
|
569
|
+
|
571
570
|
agent = servervar["HTTP_USER_AGENT"].to_s.downcase
|
572
|
-
|
571
|
+
|
573
572
|
if agent.include?("(windows;") != nil or agent.include?("windows nt") != nil
|
574
573
|
return {
|
575
574
|
"os" => "win",
|
@@ -581,16 +580,16 @@ class Knj::Web
|
|
581
580
|
"title" => "Linux"
|
582
581
|
}
|
583
582
|
end
|
584
|
-
|
583
|
+
|
585
584
|
raise "Unknown OS: #{agent}"
|
586
585
|
end
|
587
|
-
|
586
|
+
|
588
587
|
#Returns various information about the current browser. Currently only works with the Hayabusa-project.
|
589
588
|
def self.browser(servervar = nil)
|
590
589
|
servervar = _server if !servervar
|
591
590
|
raise "Could not figure out meta data." if !servervar
|
592
591
|
agent = servervar["HTTP_USER_AGENT"].to_s.downcase
|
593
|
-
|
592
|
+
|
594
593
|
if match = agent.include?("knj:true")
|
595
594
|
browser = "bot"
|
596
595
|
title = "Bot"
|
@@ -704,7 +703,7 @@ class Knj::Web
|
|
704
703
|
title = "(unknown browser)"
|
705
704
|
version = "(unknown version)"
|
706
705
|
end
|
707
|
-
|
706
|
+
|
708
707
|
os = nil
|
709
708
|
os_version = nil
|
710
709
|
if agent.include?("linux") != nil
|
@@ -713,12 +712,12 @@ class Knj::Web
|
|
713
712
|
os = "mac"
|
714
713
|
elsif match = agent.match(/windows\s+nt\s+([\d\.]+)/)
|
715
714
|
os = "windows"
|
716
|
-
|
715
|
+
|
717
716
|
if match[1] == "5.1"
|
718
717
|
os_version = "xp"
|
719
718
|
end
|
720
719
|
end
|
721
|
-
|
720
|
+
|
722
721
|
return {
|
723
722
|
"browser" => browser,
|
724
723
|
"title" => title,
|
@@ -727,23 +726,23 @@ class Knj::Web
|
|
727
726
|
"os_version" => os_version
|
728
727
|
}
|
729
728
|
end
|
730
|
-
|
729
|
+
|
731
730
|
def self.locale(args = {})
|
732
731
|
if args[:servervar]
|
733
732
|
servervar = args[:servervar]
|
734
733
|
else
|
735
734
|
servervar = _server
|
736
735
|
end
|
737
|
-
|
736
|
+
|
738
737
|
if !servervar
|
739
738
|
raise "Could not figure out meta data."
|
740
739
|
end
|
741
|
-
|
740
|
+
|
742
741
|
ret = {
|
743
742
|
:recommended => [],
|
744
743
|
:browser => []
|
745
744
|
}
|
746
|
-
|
745
|
+
|
747
746
|
alangs = servervar["HTTP_ACCEPT_LANGUAGE"].to_s
|
748
747
|
if alangs.length > 0
|
749
748
|
alangs.split(/\s*,\s*/).each do |alang|
|
@@ -753,7 +752,7 @@ class Knj::Web
|
|
753
752
|
else
|
754
753
|
q = 1.0
|
755
754
|
end
|
756
|
-
|
755
|
+
|
757
756
|
if match = alang.match(/^([A-z]+)-([A-z]+)$/)
|
758
757
|
locale = match[1]
|
759
758
|
sublocale = match[2]
|
@@ -761,7 +760,7 @@ class Knj::Web
|
|
761
760
|
locale = alang
|
762
761
|
sublocale = false
|
763
762
|
end
|
764
|
-
|
763
|
+
|
765
764
|
ret[:browser] << {
|
766
765
|
:locale => locale,
|
767
766
|
:sublocale => sublocale,
|
@@ -769,7 +768,7 @@ class Knj::Web
|
|
769
768
|
}
|
770
769
|
end
|
771
770
|
end
|
772
|
-
|
771
|
+
|
773
772
|
if args[:supported] and ret[:browser]
|
774
773
|
ret[:browser].each do |locale|
|
775
774
|
args[:supported].each do |supported_locale|
|
@@ -785,17 +784,17 @@ class Knj::Web
|
|
785
784
|
end
|
786
785
|
end
|
787
786
|
end
|
788
|
-
|
787
|
+
|
789
788
|
if args[:default]
|
790
789
|
ret[:recommended] << args[:default] if ret[:recommended].index(args[:default]) == nil
|
791
790
|
end
|
792
|
-
|
791
|
+
|
793
792
|
return ret
|
794
793
|
end
|
795
|
-
|
794
|
+
|
796
795
|
def self.hiddens(hidden_arr)
|
797
796
|
html = ""
|
798
|
-
|
797
|
+
|
799
798
|
hidden_arr.each do |hidden_hash|
|
800
799
|
if hidden_hash.is_a?(Array)
|
801
800
|
hidden_hash = {
|
@@ -813,18 +812,18 @@ class Knj::Web
|
|
813
812
|
end
|
814
813
|
end
|
815
814
|
end
|
816
|
-
|
815
|
+
|
817
816
|
html << "<input type=\"hidden\" name=\"#{hidden_hash[:name].to_s.html}\" value=\"#{hidden_hash[:value].to_s.html}\" />"
|
818
817
|
end
|
819
|
-
|
818
|
+
|
820
819
|
return html
|
821
820
|
end
|
822
|
-
|
821
|
+
|
823
822
|
#Parses a string to be safe for use in <a href="">.
|
824
823
|
def self.ahref_parse(str)
|
825
824
|
return str.to_s.gsub("&", "&")
|
826
825
|
end
|
827
|
-
|
826
|
+
|
828
827
|
#URL-encodes a string.
|
829
828
|
def self.urlenc(string)
|
830
829
|
#Thanks to CGI framework
|
@@ -832,7 +831,7 @@ class Knj::Web
|
|
832
831
|
'%' + $1.unpack('H2' * $1.bytesize).join('%').upcase
|
833
832
|
end.tr(' ', '+')
|
834
833
|
end
|
835
|
-
|
834
|
+
|
836
835
|
#URL-decodes a string.
|
837
836
|
def self.urldec(string)
|
838
837
|
#Thanks to CGI framework
|
@@ -840,21 +839,21 @@ class Knj::Web
|
|
840
839
|
[$1.delete('%')].pack('H*')
|
841
840
|
end
|
842
841
|
end
|
843
|
-
|
842
|
+
|
844
843
|
#Escapes HTML-characters in a string.
|
845
844
|
def self.html(string)
|
846
845
|
return string.to_s.gsub(/&/, "&").gsub(/\"/, """).gsub(/>/, ">").gsub(/</, "<")
|
847
846
|
end
|
848
|
-
|
847
|
+
|
849
848
|
def self.html_args(h)
|
850
849
|
str = ""
|
851
850
|
h.each do |key, val|
|
852
851
|
str << "&#{Php4r.urlencode(key)}=#{Php4r.urlencode(val)}"
|
853
852
|
end
|
854
|
-
|
853
|
+
|
855
854
|
return str
|
856
855
|
end
|
857
|
-
|
856
|
+
|
858
857
|
#Calculates the URL from meta hash.
|
859
858
|
def self.url(args = {})
|
860
859
|
if args[:meta]
|
@@ -862,21 +861,21 @@ class Knj::Web
|
|
862
861
|
else
|
863
862
|
meta = _meta
|
864
863
|
end
|
865
|
-
|
864
|
+
|
866
865
|
url = ""
|
867
|
-
|
866
|
+
|
868
867
|
if meta["HTTP_SSL_ENABLED"] == "1"
|
869
868
|
url << "https://"
|
870
869
|
else
|
871
870
|
url << "http://"
|
872
871
|
end
|
873
|
-
|
872
|
+
|
874
873
|
url << meta["HTTP_HOST"]
|
875
874
|
url << meta["REQUEST_URI"] if !args.key?(:uri) or args[:uri]
|
876
|
-
|
875
|
+
|
877
876
|
return url
|
878
877
|
end
|
879
|
-
|
878
|
+
|
880
879
|
URL_SAFE_REPLACES = {
|
881
880
|
"ø" => "oe",
|
882
881
|
"æ" => "ae",
|
@@ -886,11 +885,11 @@ class Knj::Web
|
|
886
885
|
}
|
887
886
|
def self.url_safe(str)
|
888
887
|
str = str.to_s.downcase
|
889
|
-
|
888
|
+
|
890
889
|
URL_SAFE_REPLACES.each do |key, val|
|
891
890
|
str.gsub!(key, val)
|
892
891
|
end
|
893
|
-
|
892
|
+
|
894
893
|
return Knj::Strings.remove_non_ascii(str)
|
895
894
|
end
|
896
895
|
end
|
@@ -899,14 +898,14 @@ class String
|
|
899
898
|
def html
|
900
899
|
return Knj::Web.html(self)
|
901
900
|
end
|
902
|
-
|
901
|
+
|
903
902
|
def sql
|
904
903
|
begin
|
905
904
|
return _db.escape(self)
|
906
905
|
rescue NameError
|
907
906
|
#ignore - not i KnjAppServer HTTP-session.
|
908
907
|
end
|
909
|
-
|
908
|
+
|
910
909
|
raise "Could not figure out where to find db object."
|
911
910
|
end
|
912
911
|
end
|
@@ -915,7 +914,7 @@ class Symbol
|
|
915
914
|
def html
|
916
915
|
return self.to_s.html
|
917
916
|
end
|
918
|
-
|
917
|
+
|
919
918
|
def sql
|
920
919
|
return self.to_s.sql
|
921
920
|
end
|
@@ -925,7 +924,7 @@ class Fixnum
|
|
925
924
|
def sql
|
926
925
|
return self.to_s.sql
|
927
926
|
end
|
928
|
-
|
927
|
+
|
929
928
|
def html
|
930
929
|
return self.to_s.html
|
931
930
|
end
|