From 50ce31f6ace11539a5f37d9773f9f99c9d6ba6d7 Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Tue, 19 Sep 2023 18:24:57 -0700 Subject: [PATCH] Blur explicit photos option --- pkg/config/enum.go | 2 +- pkg/controller/account/settings.go | 6 +++++- pkg/templates/template_funcs.go | 19 +++++++++++++++++++ web/static/css/theme.css | 5 +++++ web/static/js/bulma.js | 9 ++++++++- web/templates/account/settings.html | 14 +++++++++++++- web/templates/forum/thread.html | 4 ++-- web/templates/photo/gallery.html | 8 ++++---- web/templates/photo/permalink.html | 4 ++-- 9 files changed, 59 insertions(+), 12 deletions(-) diff --git a/pkg/config/enum.go b/pkg/config/enum.go index cf3ddf5..70e1049 100644 --- a/pkg/config/enum.go +++ b/pkg/config/enum.go @@ -65,7 +65,7 @@ var ( "hide_age", // Site prefs - // "dm_privacy", + // "dm_privacy", "blur_explicit", } // Choices for the Contact Us subject diff --git a/pkg/controller/account/settings.go b/pkg/controller/account/settings.go index 7fff97b..a39f647 100644 --- a/pkg/controller/account/settings.go +++ b/pkg/controller/account/settings.go @@ -122,11 +122,15 @@ func Settings() http.HandlerFunc { case "preferences": hashtag = "#prefs" var ( - explicit = r.PostFormValue("explicit") == "true" + explicit = r.PostFormValue("explicit") == "true" + blurExplicit = r.PostFormValue("blur_explicit") ) user.Explicit = explicit + // Set profile field prefs. + user.SetProfileField("blur_explicit", blurExplicit) + if err := user.Save(); err != nil { session.FlashError(w, r, "Failed to save user to database: %s", err) } diff --git a/pkg/templates/template_funcs.go b/pkg/templates/template_funcs.go index f2e82df..30753e2 100644 --- a/pkg/templates/template_funcs.go +++ b/pkg/templates/template_funcs.go @@ -62,6 +62,9 @@ func TemplateFuncs(r *http.Request) template.FuncMap { "QueryPlus": QueryPlus(r), "SimplePager": SimplePager(r), "HasSuffix": strings.HasSuffix, + + // Test if a photo should be blurred ({{BlurExplicit .Photo}}) + "BlurExplicit": BlurExplicit(r), } } @@ -81,6 +84,22 @@ func InputCSRF(r *http.Request) func() template.HTML { } } +// BlurExplicit returns true if the current user has the blur_explicit setting on and the given Photo is Explicit. +func BlurExplicit(r *http.Request) func(*models.Photo) bool { + return func(photo *models.Photo) bool { + if !photo.Explicit { + return false + } + + currentUser, err := session.CurrentUser(r) + if err != nil { + return false + } + + return currentUser.GetProfileField("blur_explicit") == "true" + } +} + // SincePrettyCoarse formats a time.Duration in plain English. Intended for "joined 2 months ago" type // strings - returns the coarsest level of granularity. func SincePrettyCoarse() func(time.Time) template.HTML { diff --git a/web/static/css/theme.css b/web/static/css/theme.css index db6f868..66468f9 100644 --- a/web/static/css/theme.css +++ b/web/static/css/theme.css @@ -92,6 +92,11 @@ abbr { display: none; } +/* Blurred explicit photo */ +.blurred-explicit { + filter: blur(14px); +} + /* Bulma hack: smaller tag size inside of tab buttons. The default tag height is set to 2em which makes the boxed tabs too tall and the bottom line doesn't draw correctly. Seen on e.g. Profile Pages for the tag # of photos. */ diff --git a/web/static/js/bulma.js b/web/static/js/bulma.js index c4d80d5..c473729 100644 --- a/web/static/js/bulma.js +++ b/web/static/js/bulma.js @@ -126,5 +126,12 @@ document.addEventListener('DOMContentLoaded', () => { } } }); - }) + }); + + // Reveal all blurred images on click. + (document.querySelectorAll(".blurred-explicit") || []).forEach(node => { + node.addEventListener("click", e => { + node.classList.remove("blurred-explicit"); + }); + }); }); diff --git a/web/templates/account/settings.html b/web/templates/account/settings.html index 281a1ea..a6ad61e 100644 --- a/web/templates/account/settings.html +++ b/web/templates/account/settings.html @@ -38,7 +38,7 @@ Website Preferences

- Explicit content filter. + Explicit content filter ; photo blur.

@@ -333,6 +333,18 @@ include erections or sexually charged content. These may appear on the Site Gallery as well as user profile pages.

+ + +

+ Explicit photos on Gallery pages will be blurred by default until clicked. Photos + on explicit Forum threads will also be blurred until clicked. +

diff --git a/web/templates/forum/thread.html b/web/templates/forum/thread.html index df561b9..f248886 100644 --- a/web/templates/forum/thread.html +++ b/web/templates/forum/thread.html @@ -219,8 +219,8 @@ {{else}} -
- +
+
{{end}} {{end}} diff --git a/web/templates/photo/gallery.html b/web/templates/photo/gallery.html index 67fcb88..3c09f68 100644 --- a/web/templates/photo/gallery.html +++ b/web/templates/photo/gallery.html @@ -400,14 +400,14 @@ {{end}} -
+
{{if HasSuffix .Filename ".mp4"}} {{else}} - + {{end}}
@@ -506,7 +506,7 @@ {{end}} -
+
{{if HasSuffix .Filename ".mp4"}}
diff --git a/web/templates/photo/permalink.html b/web/templates/photo/permalink.html index a6eb11e..3c71bd1 100644 --- a/web/templates/photo/permalink.html +++ b/web/templates/photo/permalink.html @@ -68,14 +68,14 @@
-
+
{{if HasSuffix .Photo.Filename ".mp4"}} {{else}} - + {{end}}