lib/knj/php.rb in knjrbfw-0.0.7 vs lib/knj/php.rb in knjrbfw-0.0.8
- old
+ new
@@ -11,11 +11,11 @@
elsif paras[0].is_a?(Array)
send_paras = [paras[0][1].to_sym]
send_paras << paras[1] if paras[1]
paras[0][0].send(*send_paras)
else
- raise "Unknown user-func."
+ raise "Unknown user-func: '#{paras[0].class.name}'."
end
end
def print_r(argument, ret = false, count = 1)
retstr = ""
@@ -116,10 +116,46 @@
elsif argument.is_a?(Exception)
retstr += "#\{#{argument.class.to_s}: #{argument.message}}\n"
elsif cstr == "Knj::Unix_proc"
retstr += "#{argument.class.to_s}::data - "
retstr += print_r(argument.data, true, count).to_s
+ elsif cstr == "Thread"
+ retstr += "#{argument.class.to_s} - "
+
+ hash = {}
+ argument.keys.each do |key|
+ hash[key] = argument[key]
+ end
+
+ retstr += print_r(hash, true, count).to_s
+ elsif cstr == "Class"
+ retstr += "#{argument.class.to_s} - "
+ hash = {"name" => argument.name}
+ retstr += print_r(hash, true, count).to_s
+ elsif cstr == "URI::Generic"
+ retstr += "#{argument.class.to_s}{\n"
+ methods = [:host, :port, :scheme, :path]
+ count += 1
+ methods.each do |method|
+ i_spaces = 0
+ while(i_spaces < count - 1)
+ retstr += " "
+ i_spaces += 1
+ end
+
+ retstr += "#{method}: #{argument.send(method)}\n"
+ end
+
+ count -= 1
+
+ i = 0
+ while(i < count - 1)
+ retstr += " "
+ i += 1
+ end
+
+ retstr += "}\n"
else
#print argument.to_s, "\n"
retstr += "Unknown class: " + cstr + "\n"
end
@@ -193,12 +229,11 @@
def strtolower(str)
return str.to_s.downcase
end
def htmlspecialchars(string)
- require "cgi"
- return CGI.escapeHTML(string)
+ return Knj::Web.html(string)
end
def isset(var)
return false if var == nil or var == false
return true
@@ -248,20 +283,20 @@
Apache.request.headers_out[key] = value
sent = true
end
begin
- _httpsession.eruby.header(key, value) #This is for knjAppServer - knj.
+ _kas.header(key, value) #This is for knjAppServer - knj.
sent = true
rescue NameError => e
if $knj_eruby
$knj_eruby.header(key, value)
sent = true
- elsif $cgi.is_a?(CGI)
+ elsif $cgi.class.name == "CGI"
sent = true
$cgi.header(key => value)
- elsif $_CGI.is_a?(CGI)
+ elsif $_CGI.class.name == "CGI"
sent = true
$_CGI.header(key => value)
end
end
@@ -271,28 +306,22 @@
def nl2br(string)
return string.to_s.gsub("\n", "<br />\n")
end
def urldecode(string)
- #require "cgi"
- #return CGI.unescape(string)
-
- #Thanks to CGI framework
- str = string.to_s.tr('+', ' ').gsub(/((?:%[0-9a-fA-F]{2})+)/) do
- [$1.delete('%')].pack('H*')
- end
+ return Knj::Web.urldec(string)
end
def urlencode(string)
- #require "cgi"
- #return CGI.escape(string.to_s)
-
- #Thanks to CGI framework
- string.to_s.gsub(/([^ a-zA-Z0-9_.-]+)/) do
- '%' + $1.unpack('H2' * $1.bytesize).join('%').upcase
- end.tr(' ', '+')
+ return Knj::Web.urlenc(string)
end
+
+ def parse_str(str, hash)
+ CGI.parse(str).each do |key, val|
+ hash[key] = val
+ end
+ end
def file_put_contents(filepath, content)
File.open(filepath.untaint, "w") do |file|
file.write(content)
end
@@ -419,12 +448,11 @@
return false
end
end
def html_entity_decode(string)
- require "cgi"
- string = CGI.unescapeHTML(string.to_s)
+ string = Knj::Web.html(string)
string = string.gsub("ø", "ø").gsub("æ", "æ").gsub("å", "å").gsub("€", "€").gsub("#39;", "'")
return string
end
def strip_tags(htmlstr)
@@ -525,13 +553,18 @@
"path" => "/"
}
args["expires"] = Time.at(expire) if expire
args["domain"] = domain if domain
- cookie = CGI::Cookie.new(args)
- status = Knj::Php.header("Set-Cookie: #{cookie.to_s}")
- $_COOKIE[cname] = cvalue if $_COOKIE
+ begin
+ _kas.cookie(args)
+ rescue NameError
+ cookie = CGI::Cookie.new(args)
+ status = Knj::Php.header("Set-Cookie: #{cookie.to_s}")
+ $_COOKIE[cname] = cvalue if $_COOKIE
+ end
+
return status
end
def explode(expl, strexp)
return strexp.to_s.split(expl)
@@ -608,11 +641,11 @@
sec = cur_time.sec if sec == nil
date = cur_time.date if date == nil
month = cur_time.month if month == nil
year = cur_time.year if year == nil
- new_time = Datestamp.from_dbstr("#{year.to_s}-#{month.to_s}-#{date.to_s} #{hour.to_s}:#{min.to_s}:#{sec.to_s}")
+ new_time = Knj::Datet.in("#{year.to_s}-#{month.to_s}-#{date.to_s} #{hour.to_s}:#{min.to_s}:#{sec.to_s}")
return new_time.to_i
end
def date(date_format, date_unixt = nil)
date_unixt = Time.now.to_i if date_unixt == nil
@@ -709,9 +742,23 @@
plain_str = zstream.inflate(str.to_s)
zstream.finish
zstream.close
return plain_str.to_s
+ end
+
+ #Sort methods.
+ def ksort(hash)
+ nhash = hash.sort do |a, b|
+ a[0] <=> b[0]
+ end
+
+ newhash = {}
+ nhash.each do |val|
+ newhash[val[0]] = val[1][0]
+ end
+
+ return newhash
end
module_function(*instance_methods)
end
\ No newline at end of file