summaryrefslogtreecommitdiffstats
path: root/filters/email-libravatar-hover.lua
diff options
context:
space:
mode:
Diffstat (limited to 'filters/email-libravatar-hover.lua')
-rwxr-xr-xfilters/email-libravatar-hover.lua42
1 files changed, 42 insertions, 0 deletions
diff --git a/filters/email-libravatar-hover.lua b/filters/email-libravatar-hover.lua
new file mode 100755
index 0000000..f94a980
--- /dev/null
+++ b/filters/email-libravatar-hover.lua
@@ -0,0 +1,42 @@
+#!/usr/bin/env luajit51
+local digest = require("openssl.digest")
+
+-- Function to calculate MD5 hash of the input
+function md5_hex(input)
+ print("Calculating MD5 for:", input) -- Debug print
+ local b = digest.new("md5"):final(input)
+ local x = ""
+ for i = 1, #b do
+ x = x .. string.format("%.2x", string.byte(b, i))
+ end
+ print("MD5 Hash:", x) -- Debug print
+ return x
+end
+
+-- Called when the filter opens
+function filter_open(email, page)
+ print("Filter Open. Email:", email) -- Debug print
+ buffer = ""
+ hexdigest = md5_hex(email:sub(2, -2):lower())
+ print("Hex Digest:", hexdigest) -- Debug print
+end
+
+-- Called when the filter closes
+function filter_close()
+ local baseurl = os.getenv("HTTPS") and "https://seccdn.libravatar.org/" or "http://cdn.libravatar.org/"
+ print("Base URL:", baseurl) -- Debug print
+ print("Hex Digest in filter_close:", hexdigest) -- Debug print
+ local avatar_url_small = baseurl .. "avatar/" .. hexdigest .. "?s=13&d=retro"
+ local avatar_url_large = baseurl .. "avatar/" .. hexdigest .. "?s=128&d=retro"
+ print("Avatar URL Small:", avatar_url_small) -- Debug print
+ print("Avatar URL Large:", avatar_url_large) -- Debug print
+
+ html("<span class='libravatar'><img class='inline' src='" .. avatar_url_small .. "' /><img class='onhover' src='" .. avatar_url_large .. "' /></span>" .. buffer)
+ return 0
+end
+
+-- Called when writing to the filter
+function filter_write(str)
+ print("Filter Write:", str) -- Debug print
+ buffer = buffer .. str
+end