cgi-bin/tek/class/loona.lua
changeset 250 5107767c6c1e
parent 249 2407b197ed8b
child 251 2de5931b723d
     1.1 --- a/cgi-bin/tek/class/loona.lua	Mon Oct 20 00:56:02 2008 +0200
     1.2 +++ b/cgi-bin/tek/class/loona.lua	Fri Oct 24 01:19:42 2008 +0200
     1.3 @@ -28,16 +28,20 @@
     1.4  
     1.5  local table, string, assert, unpack, ipairs, pairs, type, require, setfenv =
     1.6  	table, string, assert, unpack, ipairs, pairs, type, require, setfenv
     1.7 -local open, remove, rename, getenv, time, date =
     1.8 +local open, os_remove, rename, getenv, time, date =
     1.9  	io.open, os.remove, os.rename, os.getenv, os.time, os.date
    1.10  local setmetatable = setmetatable
    1.11 +local loadfile = loadfile
    1.12 +local insert = table.insert
    1.13 +local concat = table.concat
    1.14 +local remove = table.remove
    1.15  
    1.16  -------------------------------------------------------------------------------
    1.17  --	Module setup:
    1.18  -------------------------------------------------------------------------------
    1.19  
    1.20  module("tek.class.loona", tek.class)
    1.21 -_VERSION = "LOona Class 5.7"
    1.22 +_VERSION = "LOona Class 5.8"
    1.23  
    1.24  -------------------------------------------------------------------------------
    1.25  --	Markup:
    1.26 @@ -63,11 +67,11 @@
    1.27  		self.is_dynamic_content = true
    1.28  	end
    1.29  	local t = { '<%loona:include("', args[1], '"' }
    1.30 -	table.remove(args, 1)
    1.31 +	remove(args, 1)
    1.32  	for _, v in ipairs(args) do
    1.33 -		table.insert(t, ',' .. v)
    1.34 +		insert(t, ',' .. v)
    1.35  	end
    1.36 -	return table.concat(t), ')%>'
    1.37 +	return concat(t), ')%>'
    1.38  end
    1.39  
    1.40  function Markup:link(link)
    1.41 @@ -121,7 +125,7 @@
    1.42  end
    1.43  
    1.44  function Session:delete()
    1.45 -	remove(self.filename)
    1.46 +	os_remove(self.filename)
    1.47  end
    1.48  
    1.49  -------------------------------------------------------------------------------
    1.50 @@ -160,10 +164,10 @@
    1.51  function Loona:deleteprofile(p, lang)
    1.52  	p = self.config.contentdir .. "/" .. p .. "_" .. (lang or self.lang)
    1.53  	for e in util.readdir(p) do
    1.54 - 		local success, msg = remove(p .. "/" .. e)
    1.55 + 		local success, msg = os_remove(p .. "/" .. e)
    1.56  		assert(success, self:dbmsg("Error removing entry in profile", msg))
    1.57  	end
    1.58 -	return remove(p)
    1.59 +	return os_remove(p)
    1.60  end
    1.61  
    1.62  
    1.63 @@ -220,7 +224,7 @@
    1.64  	for e in util.readdir(self.config.contentdir) do
    1.65  		local l = e:match(lmatch)
    1.66  		if l then
    1.67 -			table.insert(plangs, l)
    1.68 +			insert(plangs, l)
    1.69  		end
    1.70  	end
    1.71  
    1.72 @@ -264,8 +268,8 @@
    1.73  	for e in util.readdir(cache) do
    1.74  		local f = e:match("^.*%.html%.?(%w*)$")
    1.75  		if f and f ~= "tmp" then
    1.76 -			local success, msg = remove(htdocs .. "/" .. e)
    1.77 -			success, msg = remove(cache .. "/" .. e)
    1.78 +			local success, msg = os_remove(htdocs .. "/" .. e)
    1.79 +			success, msg = os_remove(cache .. "/" .. e)
    1.80   			assert(success,
    1.81   				self:dbmsg("Could not purge cached HTML file", msg))
    1.82  		end
    1.83 @@ -334,7 +338,7 @@
    1.84  				tab[#tab].name = a
    1.85  				ss = s.subs
    1.86  				if ss then
    1.87 -					table.insert(tab, { entries = ss })
    1.88 +					insert(tab, { entries = ss })
    1.89  				end
    1.90  			else
    1.91  				ss = nil -- stop.
    1.92 @@ -344,7 +348,7 @@
    1.93  	if not self.section and not sectionpath then
    1.94  		sectionpath = self.sections[default]
    1.95  		if sectionpath then
    1.96 -			table.insert(tab, { entries = sectionpath.subs })
    1.97 +			insert(tab, { entries = sectionpath.subs })
    1.98  		end
    1.99  	end
   1.100  	return tab, sectionpath or false
   1.101 @@ -357,26 +361,26 @@
   1.102  	maxdepth = maxdepth or #self.submenus
   1.103  	for _, menu in ipairs(self.submenus) do
   1.104  		if menu.name then
   1.105 -			table.insert(t, menu.name)
   1.106 +			insert(t, menu.name)
   1.107  		end
   1.108  		d = d + 1
   1.109  		if d == maxdepth then
   1.110  			break
   1.111  		end
   1.112  	end
   1.113 -	return table.concat(t, delimiter or "/")
   1.114 +	return concat(t, delimiter or "/")
   1.115  end
   1.116  
   1.117  
   1.118  function Loona:deletesection(fname, all_bodies)
   1.119  	local fullname = self.contentdir .. "/" .. fname
   1.120 -	local success, msg = remove(fullname)
   1.121 +	local success, msg = os_remove(fullname)
   1.122  	if all_bodies then
   1.123  		local pat = "^" .. -- TODO: check
   1.124  			fname:gsub("%^%$%(%)%%%.%[%]%*%+%-%?", "%%%1") .. "%..*$"
   1.125  		for e in util.readdir(self.contentdir) do
   1.126  			if e:match(pat) then
   1.127 -				remove(self.contentdir .. "/" .. e)
   1.128 +				os_remove(self.contentdir .. "/" .. e)
   1.129  			end
   1.130  		end
   1.131  	end
   1.132 @@ -395,7 +399,7 @@
   1.133  				end
   1.134  				tab = s.subs
   1.135  			else
   1.136 -				table.insert(tab, e)
   1.137 +				insert(tab, e)
   1.138  				tab[a] = e
   1.139   				tab = nil -- stop
   1.140  			end
   1.141 @@ -425,7 +429,7 @@
   1.142  					parent = tab[idx]
   1.143  					tab = tab[idx].subs
   1.144  				else
   1.145 -					table.remove(tab, idx)
   1.146 +					remove(tab, idx)
   1.147  					tab[a] = nil
   1.148  					if #tab == 0 and parent then
   1.149  						parent.subs = nil
   1.150 @@ -492,7 +496,7 @@
   1.151  
   1.152  
   1.153  function Loona:unlockfile(file)
   1.154 -	return not self.session and true or remove(file .. ".LOCK")
   1.155 +	return not self.session and true or os_remove(file .. ".LOCK")
   1.156  end
   1.157  
   1.158  
   1.159 @@ -553,9 +557,9 @@
   1.160  	for _, a in ipairs(arg) do
   1.161  		local key, val = a:match("^([%w_]+)=(.*)$")
   1.162  		if key and val then -- "arg=val" sets/overrides argument
   1.163 -			table.insert(args2, { name = key, value = val })
   1.164 +			insert(args2, { name = key, value = val })
   1.165  		elseif self.args[a] then -- just "arg" propagates argument
   1.166 -			table.insert(args2, { name = a, value = self.args[a] })
   1.167 +			insert(args2, { name = a, value = self.args[a] })
   1.168  		end
   1.169  	end
   1.170  	local doc = self:getdocname(section, #args2 > 0)
   1.171 @@ -564,16 +568,16 @@
   1.172  	local href = { anch and url or doc }
   1.173  	for i, arg in ipairs(args2) do
   1.174  		if i > 1 or notfirst then
   1.175 -			table.insert(href, "&amp;")
   1.176 +			insert(href, "&amp;")
   1.177  		else
   1.178 -			table.insert(href, "?")
   1.179 +			insert(href, "?")
   1.180  		end
   1.181 -		table.insert(href, arg.name .. "=" .. cgi.encodeurl(arg.value))
   1.182 +		insert(href, arg.name .. "=" .. cgi.encodeurl(arg.value))
   1.183  	end
   1.184  	if anch then
   1.185 -		table.insert(href, anch)
   1.186 +		insert(href, anch)
   1.187  	end
   1.188 -	return table.concat(href)
   1.189 +	return concat(href)
   1.190  end
   1.191  
   1.192  
   1.193 @@ -581,11 +585,11 @@
   1.194  
   1.195  function Loona:href(section, ...)
   1.196  	if self.session then
   1.197 -		table.insert(arg, 1, "profile")
   1.198 -		table.insert(arg, 1, "session")
   1.199 +		insert(arg, 1, "profile")
   1.200 +		insert(arg, 1, "session")
   1.201  	end
   1.202  	if self.explicitlang then
   1.203 -		table.insert(arg, 1, "lang")
   1.204 +		insert(arg, 1, "lang")
   1.205  	end
   1.206  	return self:shref(section, arg)
   1.207  end
   1.208 @@ -641,7 +645,7 @@
   1.209  		if posix.lstat(dir .. "/" .. f, "mode") == "directory" then
   1.210  			f = func(f)
   1.211  			if f then
   1.212 -				table.insert(tab, f)
   1.213 +				insert(tab, f)
   1.214  			end
   1.215  		end
   1.216  	end
   1.217 @@ -680,11 +684,11 @@
   1.218  		local visible = { }
   1.219  		for _, e in ipairs(sub.entries) do
   1.220  			if not e.notvisible then
   1.221 -				table.insert(visible, e)
   1.222 +				insert(visible, e)
   1.223  			end
   1.224  		end
   1.225  		if addnew then
   1.226 -			table.insert(visible, newent)
   1.227 +			insert(visible, newent)
   1.228  		end
   1.229  		local numvis = #visible
   1.230  		if numvis > 0 then
   1.231 @@ -762,7 +766,7 @@
   1.232  
   1.233  	if self.authuser_edit or self.authuser_profile or self.authuser_menu then
   1.234  
   1.235 -		local hiddenvars = table.concat( {
   1.236 +		local hiddenvars = concat( {
   1.237  			self:hidden("lang", self.args.lang),
   1.238  			self:hidden("profile", self.profile),
   1.239  			self:hidden("session", self.session.id),
   1.240 @@ -1065,7 +1069,7 @@
   1.241  					if tab and tab.id == self.session.id then
   1.242  						-- lock already held and is mine - try to save:
   1.243  						local savec = c:gsub("&nbsp;", "\194\160") -- TODO
   1.244 -						remove(contentdir .. "/" .. savename .. ".html")
   1.245 +						os_remove(contentdir .. "/" .. savename .. ".html")
   1.246  						self:savebody(savename, savec)
   1.247  						-- TODO: error handling
   1.248  						self:unlockfile(lockfname)
   1.249 @@ -1206,8 +1210,8 @@
   1.250  	local t, path, section = { }
   1.251  	for _, menu in ipairs(self.submenus) do
   1.252  		if menu.entries and menu.entries[menu.name] then
   1.253 -			table.insert(t, menu.name)
   1.254 -			local fn = table.concat(t, "_")
   1.255 +			insert(t, menu.name)
   1.256 +			local fn = concat(t, "_")
   1.257  			if posix.stat(self.contentdir .. "/" .. fn .. ext,
   1.258  				"mode") == "file" then
   1.259  				path, section = fn, menu
   1.260 @@ -1235,15 +1239,12 @@
   1.261  	local l = self.requestlang or self.args.lang
   1.262  	self.langs = { l and l:match("^%w+$") }
   1.263  	local s = self.request.HTTP_ACCEPT_LANGUAGE
   1.264 -	while s do
   1.265 -		local l, r = s:match("^([%w.=]+)[,;](.*)$")
   1.266 -		l = l or s
   1.267 -		s = r
   1.268 -		if l:match("^%w+$") then
   1.269 -			table.insert(self.langs, l)
   1.270 +	if s then
   1.271 +		for l in (s .. ";"):gmatch("([%a-]+)[,;]") do
   1.272 +			insert(self.langs, l)
   1.273  		end
   1.274  	end
   1.275 -	table.insert(self.langs, self.config.deflang)
   1.276 +	insert(self.langs, self.config.deflang)
   1.277  
   1.278  	-- get list of possible profiles
   1.279  
   1.280 @@ -1395,8 +1396,8 @@
   1.281  							self:hidden("actionconfirm", "true")
   1.282  					}
   1.283  				else
   1.284 -					local item = table.remove(t, i)
   1.285 -					table.insert(t, i - 1, item)
   1.286 +					local item = remove(t, i)
   1.287 +					insert(t, i - 1, item)
   1.288  					save = true
   1.289  				end
   1.290  			end
   1.291 @@ -1416,8 +1417,8 @@
   1.292  							self:hidden("actionconfirm", "true")
   1.293  					}
   1.294  				else
   1.295 -					local item = table.remove(t, i)
   1.296 -					table.insert(t, i + 1, item)
   1.297 +					local item = remove(t, i)
   1.298 +					insert(t, i + 1, item)
   1.299  					save = true
   1.300  				end
   1.301  			end
   1.302 @@ -1592,8 +1593,8 @@
   1.303  	local t = { }
   1.304  	local is_dynamic = Markup:new { input = s,
   1.305  		features = "hespcadlintf", indentchar = " ",
   1.306 -		wrfunc = function(s) table.insert(t, s) end }:run()
   1.307 -	return table.concat(t), is_dynamic
   1.308 +		wrfunc = function(s) insert(t, s) end }:run()
   1.309 +	return concat(t), is_dynamic
   1.310  end
   1.311  
   1.312  
   1.313 @@ -1893,7 +1894,7 @@
   1.314  	local outbuf = { }
   1.315  	o = o or { }
   1.316  	o.nologin = true
   1.317 -	o.out = function(self, s) table.insert(outbuf, s) end
   1.318 +	o.out = function(self, s) insert(outbuf, s) end
   1.319  	o.addheader = function(self, s) end
   1.320  
   1.321  	o = self:new(o):run()