<% local links = { delicious = "http://delicious.com/catwell", archfr = "http://forums.archlinux.fr/", imgup = "http://img.flashtux.org/", w3c_xhtml = "http://validator.w3.org/check?uri=http://catwell.info/", w3c_atom = "http://validator.w3.org/feed/check.cgi?url=http://catwell.info/feed/", } local searchStrings = { Google = "http://google.fr/search?q=%s", AUR = "http://aur.archlinux.org/packages.php?K=%s", YouTube = "http://www.youtube.com/results?search_query=%s", WhosWho = "https://resel.fr/annuaire/index.php?action=search&chaine=%s", en2fr = "http://www.wordreference.com/enfr/%s", fr2en = "http://www.wordreference.com/fren/%s", tresor = "http://www.cnrtl.fr/definition/%s", clusty = "http://clusty.com/search?query=%s", } local bt = cgilua.POST.searchBt local field = cgilua.POST.searchField or "" local getlink = function(t) if links[t] then return links[t] end local n = 0 local r = nil for k,l in pairs(links) do if (k:find(t) == 1) then n = n + 1 r = l end end if n == 1 then return r else if n == 0 then return nil, "notfound" else return nil, "many" end end end if bt then if bt == "Go" then local link, e = getlink(field) if link then cgilua.redirect(link) elseif e == "notfound" then if string.match(field, "^https?://") then cgilua.redirect(field) else cgilua.redirect("http://" .. field) end end -- else (e == many): do nothing else cgilua.redirect(searchStrings[bt]:format(field)) end end %> ~@target
cw


<% for s,_ in pairs(searchStrings) do print(string.format("", s)) end %>


<% for t,l in pairs(links) do print(string.format("%s  ",l,t,t)) end %>