aboutsummaryrefslogtreecommitdiff
path: root/filters/email-libravatar-hover.lua
blob: c14b618b1c5c5b26d8d1ea3f598950f5cb101351 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
local digest = require("openssl.digest")

function md5_hex(input)
	local b = digest.new("md5"):final(input)
	local x = ""
	for i = 1, #b do
		x = x .. string.format("%.2x", string.byte(b, i))
	end
	return x
end

function filter_open(email, page)
	buffer = ""
	hexdigest = md5_hex(email:sub(2, -2):lower())
end

function filter_close()
	baseurl = os.getenv("HTTPS") and "https://seccdn.libravatar.org/" or "http://cdn.libravatar.org/"
	html("<span class='libravatar'><img class='inline' src='" .. baseurl .. "avatar/" .. hexdigest .. "?s=13&amp;d=retro' /><img class='onhover' src='" .. baseurl .. "avatar/" .. hexdigest .. "?s=128&amp;d=retro' /></span>" .. buffer)
	return 0
end

function filter_write(str)
	buffer = buffer .. str
end