knjrbfw 0.0.110 → 0.0.114

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +5 -5
  2. data/Rakefile +0 -14
  3. data/lib/knj/autoload.rb +1 -2
  4. data/lib/knj/gtk2_window.rb +7 -7
  5. data/lib/knj/image.rb +60 -51
  6. data/lib/knj/scripts/php_to_rb_helper.rb +13 -20
  7. data/lib/knj/unix_proc.rb +35 -35
  8. data/lib/knj/web.rb +135 -136
  9. metadata +32 -85
  10. data/.document +0 -5
  11. data/.rspec +0 -1
  12. data/Gemfile +0 -22
  13. data/Gemfile.lock +0 -90
  14. data/VERSION +0 -1
  15. data/knjrbfw.gemspec +0 -318
  16. data/lib/knj/.gitignore +0 -1
  17. data/lib/knj/datarow.rb +0 -873
  18. data/lib/knj/datarow_custom.rb +0 -153
  19. data/lib/knj/db.rb +0 -1
  20. data/lib/knj/knjdb/dbtime.rb +0 -35
  21. data/lib/knj/knjdb/drivers/mysql/knjdb_mysql.rb +0 -604
  22. data/lib/knj/knjdb/drivers/mysql/knjdb_mysql_columns.rb +0 -155
  23. data/lib/knj/knjdb/drivers/mysql/knjdb_mysql_indexes.rb +0 -69
  24. data/lib/knj/knjdb/drivers/mysql/knjdb_mysql_sqlspecs.rb +0 -5
  25. data/lib/knj/knjdb/drivers/mysql/knjdb_mysql_tables.rb +0 -443
  26. data/lib/knj/knjdb/drivers/sqlite3/knjdb_sqlite3.rb +0 -184
  27. data/lib/knj/knjdb/drivers/sqlite3/knjdb_sqlite3_columns.rb +0 -177
  28. data/lib/knj/knjdb/drivers/sqlite3/knjdb_sqlite3_indexes.rb +0 -29
  29. data/lib/knj/knjdb/drivers/sqlite3/knjdb_sqlite3_sqlspecs.rb +0 -5
  30. data/lib/knj/knjdb/drivers/sqlite3/knjdb_sqlite3_tables.rb +0 -449
  31. data/lib/knj/knjdb/dump.rb +0 -122
  32. data/lib/knj/knjdb/idquery.rb +0 -109
  33. data/lib/knj/knjdb/libknjdb.rb +0 -797
  34. data/lib/knj/knjdb/libknjdb_java_sqlite3.rb +0 -83
  35. data/lib/knj/knjdb/libknjdb_row.rb +0 -153
  36. data/lib/knj/knjdb/libknjdb_sqlite3_ironruby.rb +0 -69
  37. data/lib/knj/knjdb/query_buffer.rb +0 -87
  38. data/lib/knj/knjdb/revision.rb +0 -342
  39. data/lib/knj/knjdb/sqlspecs.rb +0 -5
  40. data/lib/knj/objects.rb +0 -957
  41. data/lib/knj/process.rb +0 -480
  42. data/lib/knj/process_meta.rb +0 -569
  43. data/lib/knj/scripts/process_meta_exec.rb +0 -144
  44. data/lib/knj/sshrobot/sshrobot.rb +0 -135
  45. data/lib/knj/sshrobot.rb +0 -1
  46. data/lib/knj/translations.rb +0 -133
  47. data/spec/amixer_spec.rb +0 -32
  48. data/spec/arrayext_spec.rb +0 -42
  49. data/spec/autoload_spec.rb +0 -7
  50. data/spec/cmd_parser_spec.rb +0 -25
  51. data/spec/db_spec.rb +0 -282
  52. data/spec/db_spec_encoding_test_file.txt +0 -1
  53. data/spec/knjrbfw_spec.rb +0 -109
  54. data/spec/locales_spec.rb +0 -9
  55. data/spec/objects_spec.rb +0 -394
  56. data/spec/process_meta_spec.rb +0 -172
  57. data/spec/process_spec.rb +0 -115
  58. data/spec/spec_helper.rb +0 -12
  59. data/spec/strings_spec.rb +0 -65
  60. data/spec/web_spec.rb +0 -77
  61. data/testfiles/image.jpg +0 -0
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
- curvalue = curvalue.id if (cname == "Knj::Db_row" or cname == "Knj::Datarow")
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("&", "&amp;")
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(/&/, "&amp;").gsub(/\"/, "&quot;").gsub(/>/, "&gt;").gsub(/</, "&lt;")
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