From 74d1921ab7de66be5554e82b78197faf1eac3d67 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 5 Dec 2021 03:30:06 +0200 Subject: [PATCH] sfd --- files/helpers/sanitize.py | 44 +++++++++++++++---------- files/templates/authforms.html | 4 +-- files/templates/comments.html | 2 +- files/templates/default.html | 11 ++++--- files/templates/home.html | 1 + files/templates/log.html | 4 +-- files/templates/login_2fa.html | 2 +- files/templates/settings.html | 5 ++- files/templates/settings2.html | 8 ++--- files/templates/sign_up.html | 6 ++-- files/templates/sign_up_failed_ref.html | 2 +- files/templates/submission.html | 10 +++--- files/templates/submit.html | 4 +-- 13 files changed, 56 insertions(+), 47 deletions(-) diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index 17d1bc03b..9526ddcf4 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -129,17 +129,17 @@ def sanitize(sanitized, noimages=False): if site not in tag["src"] and not tag["src"].startswith('/'): tag["rel"] = "nofollow noopener noreferrer" tag["class"] = "in-comment-image" + tag["width"] = "150" + tag["height"] = "150" tag["loading"] = "lazy" - # tag["data-src"] = tag["src"] - # tag["src"] = "/assets/images/loading.webp" + tag["data-src"] = tag["src"] + tag["src"] = "/assets/images/loading.webp" link = soup.new_tag("a") - # link["href"] = tag["data-src"] - link["href"] = tag["src"] + link["href"] = tag["data-src"] if site not in link["href"] and not link["href"].startswith('/'): link["rel"] = "nofollow noopener noreferrer" link["target"] = "_blank" - # link["onclick"] = f"expandDesktopImage('{tag['data-src']}');" - link["onclick"] = f"expandDesktopImage('{tag['src']}');" + link["onclick"] = f"expandDesktopImage('{tag['data-src']}');" link["data-bs-toggle"] = "modal" link["data-bs-target"] = "#expandImageModal" @@ -174,13 +174,13 @@ def sanitize(sanitized, noimages=False): for i in re.finditer('(?', sanitized) + sanitized = re.sub(f'(?', sanitized) if emoji in session["favorite_emojis"]: session["favorite_emojis"][emoji] += 1 else: session["favorite_emojis"][emoji] = 1 elif path.isfile(f'./files/assets/images/emojis/{emoji}.webp'): - sanitized = re.sub(f'(?', sanitized) + sanitized = re.sub(f'(?', sanitized) if emoji in session["favorite_emojis"]: session["favorite_emojis"][emoji] += 1 else: session["favorite_emojis"][emoji] = 1 @@ -211,28 +211,36 @@ def sanitize(sanitized, noimages=False): sanitized = sanitized.replace("https://www.", "https://").replace("https://youtu.be/", "https://youtube.com/watch?v=").replace("https://music.youtube.com/watch?v=", "https://youtube.com/watch?v=").replace("https://open.spotify.com/", "https://open.spotify.com/embed/").replace("https://streamable.com/", "https://streamable.com/e/").replace("https://youtube.com/shorts/", "https://youtube.com/watch?v=").replace("https://mobile.twitter", "https://twitter").replace("https://m.facebook", "https://facebook").replace("https://m.wikipedia", "https://wikipedia").replace("https://m.youtube", "https://youtube") + if "https://youtube.com/watch?v=" in sanitized: sanitized = sanitized.replace("?t=", "&t=") - for i in re.finditer('" target="_blank">(https://youtube\.com/watch\?v\=.*?)', sanitized): + for i in re.finditer('" target="_blank">(https://youtube\.com/watch\?v\=(.*?))', sanitized): url = i.group(1) + yt_id = i.group(2).split('&')[0] replacing = f'{url}' - url = url.replace("watch?v=", "embed/").replace("&t", "?start").replace("?t", "?start") - url = re.sub('(\?start=([0-9]*?))s', r'\1', url) - htmlsource = f'' + + params = parse_qs(urlparse(url).query) + t = params.get('t', params.get('start', [0]))[0] + if isinstance(t, str): t = t.replace('s','') + + htmlsource = f'' + sanitized = sanitized.replace(replacing, htmlsource) for i in re.finditer('{url}' - htmlsource = f'' + htmlsource = f'' sanitized = sanitized.replace(replacing, htmlsource) for i in re.finditer('

(https:.*?\.mp4)

', sanitized): - sanitized = sanitized.replace(i.group(0), f'

') + sanitized = sanitized.replace(i.group(0), f'

') for i in re.finditer('{url}' - htmlsource = f'' + htmlsource = f'' sanitized = sanitized.replace(replacing, htmlsource) for rd in ["https://reddit.com/", "https://new.reddit.com/", "https://www.reddit.com/", "https://redd.it/"]: @@ -258,7 +266,7 @@ def filter_title(title): if emoji.startswith("!"): emoji = emoji[1:] if path.isfile(f'./files/assets/images/emojis/{emoji}.webp'): - title = re.sub(f'(?', title) + title = re.sub(f'(?', title) elif path.isfile(f'./files/assets/images/emojis/{emoji}.webp'): title = re.sub(f'(?', title) diff --git a/files/templates/authforms.html b/files/templates/authforms.html index 5d0ba5617..ab3848b48 100644 --- a/files/templates/authforms.html +++ b/files/templates/authforms.html @@ -15,11 +15,11 @@ {% if v %} - + {% if v.agendaposter %}{% elif v.css %}{% endif %} {% else %} - + {% endif %} diff --git a/files/templates/comments.html b/files/templates/comments.html index d17652fb7..08ca7997a 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -749,7 +749,7 @@ {% if v %} - + {% endif %} diff --git a/files/templates/default.html b/files/templates/default.html index 4a723dc1d..950e31e80 100644 --- a/files/templates/default.html +++ b/files/templates/default.html @@ -3,18 +3,16 @@ {% if v %} - + {% if v.agendaposter %}{% elif v.css %}{% endif %} {% else %} - + {% endif %} - - @@ -355,8 +353,11 @@ {% endif %} + + + - + \ No newline at end of file diff --git a/files/templates/home.html b/files/templates/home.html index de142f14a..ca637c953 100644 --- a/files/templates/home.html +++ b/files/templates/home.html @@ -35,6 +35,7 @@ {% endif %} {% endif %} +

diff --git a/files/templates/log.html b/files/templates/log.html index dc3f952d7..5876a5ad6 100644 --- a/files/templates/log.html +++ b/files/templates/log.html @@ -6,11 +6,11 @@ {% block content %} {% if v %} - + {% if v.agendaposter %}{% elif v.css %}{% endif %} {% else %} - + {% endif %}
diff --git a/files/templates/login_2fa.html b/files/templates/login_2fa.html index 9104fb82b..f240106d3 100644 --- a/files/templates/login_2fa.html +++ b/files/templates/login_2fa.html @@ -12,7 +12,7 @@ 2-Step Login - {{'SITE_NAME' | app_config}} - + diff --git a/files/templates/settings.html b/files/templates/settings.html index e0ac498b2..f9b3fb248 100644 --- a/files/templates/settings.html +++ b/files/templates/settings.html @@ -2,8 +2,6 @@ - - @@ -32,7 +30,7 @@ - + {% if v.agendaposter %}{% elif v.css %}{% endif %} @@ -261,6 +259,7 @@ } + diff --git a/files/templates/settings2.html b/files/templates/settings2.html index 0e336d142..3fb2ac4d3 100644 --- a/files/templates/settings2.html +++ b/files/templates/settings2.html @@ -36,10 +36,10 @@ {% if v %} - + {% else %} - + {% endif %} @@ -168,12 +168,12 @@ {% block scripts %} {% endblock %} - - + + \ No newline at end of file diff --git a/files/templates/sign_up.html b/files/templates/sign_up.html index 31fa0553f..e3b84abb3 100644 --- a/files/templates/sign_up.html +++ b/files/templates/sign_up.html @@ -28,7 +28,7 @@ - + @@ -146,14 +146,14 @@
- - {% if hcaptcha %} {% endif %} + + diff --git a/files/templates/sign_up_failed_ref.html b/files/templates/sign_up_failed_ref.html index 568a96c8d..102dc31df 100644 --- a/files/templates/sign_up_failed_ref.html +++ b/files/templates/sign_up_failed_ref.html @@ -29,7 +29,7 @@ - + diff --git a/files/templates/submission.html b/files/templates/submission.html index a9226b37f..bab6ee38a 100644 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -497,7 +497,7 @@ - +
@@ -508,9 +508,9 @@ -