df
This commit is contained in:
parent
116989a320
commit
922241b4bf
4 changed files with 64 additions and 77 deletions
|
@ -393,7 +393,7 @@ class Submission(Base, Stndrd, Age_times, Scores, Fuzzing):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_image(self):
|
def is_image(self):
|
||||||
if self.url: return self.url.lower().endswith('.jpg') or self.url.lower().endswith('.png') or self.url.lower().endswith('.gif') or self.url.lower().endswith('.jpeg') or self.url.lower().endswith('?maxwidth=9999') or self.url.lower().endswith('?maxwidth=8888')
|
if self.url: return self.url.lower().endswith('.jpg') or self.url.lower().endswith('.png') or self.url.lower().endswith('.gif') or self.url.lower().endswith('.jpeg') or self.url.lower().endswith('?maxwidth=9999')
|
||||||
else: return False
|
else: return False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -59,8 +59,7 @@ _allowed_styles =[
|
||||||
|
|
||||||
# filter to make all links show domain on hover
|
# filter to make all links show domain on hover
|
||||||
|
|
||||||
|
def a_modify(attrs):
|
||||||
def a_modify(attrs, new=False):
|
|
||||||
|
|
||||||
raw_url=attrs.get((None, "href"), None)
|
raw_url=attrs.get((None, "href"), None)
|
||||||
if raw_url:
|
if raw_url:
|
||||||
|
@ -85,16 +84,14 @@ def a_modify(attrs, new=False):
|
||||||
return attrs
|
return attrs
|
||||||
|
|
||||||
|
|
||||||
|
def sanitize(sanitized):
|
||||||
|
|
||||||
|
sanitized = sanitized.replace("\ufeff", "").replace("m.youtube.com", "youtube.com")
|
||||||
|
|
||||||
|
for i in re.finditer('https://i.imgur.com/(.*?)\.(jpg|png|jpeg|)', sanitized):
|
||||||
|
sanitized = sanitized.replace(i.group(1), i.group(1) + "_d." + i.group(2))
|
||||||
|
|
||||||
|
sanitized = bleach.Cleaner(tags=_allowed_tags,
|
||||||
_clean_wo_links = bleach.Cleaner(tags=_allowed_tags,
|
|
||||||
attributes=_allowed_attributes,
|
|
||||||
protocols=_allowed_protocols,
|
|
||||||
)
|
|
||||||
|
|
||||||
_clean_w_links = bleach.Cleaner(tags=_allowed_tags,
|
|
||||||
attributes=_allowed_attributes,
|
attributes=_allowed_attributes,
|
||||||
protocols=_allowed_protocols,
|
protocols=_allowed_protocols,
|
||||||
styles=_allowed_styles,
|
styles=_allowed_styles,
|
||||||
|
@ -104,74 +101,64 @@ _clean_w_links = bleach.Cleaner(tags=_allowed_tags,
|
||||||
callbacks=[a_modify]
|
callbacks=[a_modify]
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
)
|
).clean(sanitized)
|
||||||
|
|
||||||
|
#soupify
|
||||||
|
soup = BeautifulSoup(sanitized, features="html.parser")
|
||||||
|
|
||||||
|
#img elements - embed
|
||||||
|
for tag in soup.find_all("img"):
|
||||||
|
|
||||||
|
url = tag.get("src", "")
|
||||||
|
if not url: continue
|
||||||
|
|
||||||
|
if "profile-pic-20" not in tag.get("class", ""):
|
||||||
|
#print(tag.get('class'))
|
||||||
|
# set classes and wrap in link
|
||||||
|
|
||||||
|
tag["rel"] = "nofollow"
|
||||||
|
tag["style"] = "max-height: 100px; max-width: 100%;"
|
||||||
|
tag["class"] = "in-comment-image rounded-sm my-2"
|
||||||
|
|
||||||
|
link = soup.new_tag("a")
|
||||||
|
link["href"] = tag["src"]
|
||||||
|
link["rel"] = "nofollow noopener"
|
||||||
|
link["target"] = "_blank"
|
||||||
|
|
||||||
|
link["onclick"] = f"expandDesktopImage('{tag['src']}');"
|
||||||
|
link["data-toggle"] = "modal"
|
||||||
|
link["data-target"] = "#expandImageModal"
|
||||||
|
|
||||||
|
tag.wrap(link)
|
||||||
|
|
||||||
|
#disguised link preventer
|
||||||
|
for tag in soup.find_all("a"):
|
||||||
|
|
||||||
|
if re.match("https?://\S+", str(tag.string)):
|
||||||
|
try:
|
||||||
|
tag.string = tag["href"]
|
||||||
|
except:
|
||||||
|
tag.string = ""
|
||||||
|
|
||||||
|
#clean up tags in code
|
||||||
|
for tag in soup.find_all("code"):
|
||||||
|
tag.contents=[x.string for x in tag.contents if x.string]
|
||||||
|
|
||||||
|
#whatever else happens with images, there are only two sets of classes allowed
|
||||||
|
for tag in soup.find_all("img"):
|
||||||
|
if 'profile-pic-20' not in tag.attrs.get("class",""):
|
||||||
|
tag.attrs['class']="in-comment-image rounded-sm my-2"
|
||||||
|
|
||||||
|
#table format
|
||||||
|
for tag in soup.find_all("table"):
|
||||||
|
tag.attrs['class']="table table-striped"
|
||||||
|
|
||||||
|
for tag in soup.find_all("thead"):
|
||||||
|
tag.attrs['class']="bg-primary text-white"
|
||||||
|
|
||||||
|
|
||||||
def sanitize(text, linkgen=False):
|
sanitized = str(soup)
|
||||||
|
|
||||||
text = text.replace("\ufeff", "").replace("m.youtube.com", "youtube.com")
|
|
||||||
|
|
||||||
if linkgen:
|
|
||||||
sanitized = _clean_w_links.clean(text)
|
|
||||||
|
|
||||||
#soupify
|
|
||||||
soup = BeautifulSoup(sanitized, features="html.parser")
|
|
||||||
|
|
||||||
#img elements - embed
|
|
||||||
for tag in soup.find_all("img"):
|
|
||||||
|
|
||||||
url = tag.get("src", "")
|
|
||||||
if not url: continue
|
|
||||||
|
|
||||||
if "profile-pic-20" not in tag.get("class", ""):
|
|
||||||
#print(tag.get('class'))
|
|
||||||
# set classes and wrap in link
|
|
||||||
|
|
||||||
tag["rel"] = "nofollow"
|
|
||||||
tag["style"] = "max-height: 100px; max-width: 100%;"
|
|
||||||
tag["class"] = "in-comment-image rounded-sm my-2"
|
|
||||||
|
|
||||||
link = soup.new_tag("a")
|
|
||||||
link["href"] = tag["src"]
|
|
||||||
link["rel"] = "nofollow noopener"
|
|
||||||
link["target"] = "_blank"
|
|
||||||
|
|
||||||
link["onclick"] = f"expandDesktopImage('{tag['src']}');"
|
|
||||||
link["data-toggle"] = "modal"
|
|
||||||
link["data-target"] = "#expandImageModal"
|
|
||||||
|
|
||||||
tag.wrap(link)
|
|
||||||
|
|
||||||
#disguised link preventer
|
|
||||||
for tag in soup.find_all("a"):
|
|
||||||
|
|
||||||
if re.match("https?://\S+", str(tag.string)):
|
|
||||||
try:
|
|
||||||
tag.string = tag["href"]
|
|
||||||
except:
|
|
||||||
tag.string = ""
|
|
||||||
|
|
||||||
#clean up tags in code
|
|
||||||
for tag in soup.find_all("code"):
|
|
||||||
tag.contents=[x.string for x in tag.contents if x.string]
|
|
||||||
|
|
||||||
#whatever else happens with images, there are only two sets of classes allowed
|
|
||||||
for tag in soup.find_all("img"):
|
|
||||||
if 'profile-pic-20' not in tag.attrs.get("class",""):
|
|
||||||
tag.attrs['class']="in-comment-image rounded-sm my-2"
|
|
||||||
|
|
||||||
#table format
|
|
||||||
for tag in soup.find_all("table"):
|
|
||||||
tag.attrs['class']="table table-striped"
|
|
||||||
|
|
||||||
for tag in soup.find_all("thead"):
|
|
||||||
tag.attrs['class']="bg-primary text-white"
|
|
||||||
|
|
||||||
|
|
||||||
sanitized = str(soup)
|
|
||||||
|
|
||||||
else:
|
|
||||||
sanitized = _clean_wo_links.clean(text)
|
|
||||||
|
|
||||||
start = '<s>'
|
start = '<s>'
|
||||||
end = '</s>'
|
end = '</s>'
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<pre class="d-none d-md-inline-block"></pre>
|
<pre class="d-none d-md-inline-block"></pre>
|
||||||
<h5 style="font-weight:bold;">admins</h5>
|
<h5 style="font-weight:bold;">Admins</h5>
|
||||||
<pre></pre>
|
<pre></pre>
|
||||||
<table class="table table-striped mb-5">
|
<table class="table table-striped mb-5">
|
||||||
<thead class="bg-primary text-white">
|
<thead class="bg-primary text-white">
|
||||||
|
|
|
@ -98,7 +98,7 @@
|
||||||
<a class="nav-link{% if request.path.endswith('/leaderboard') %} active{% endif %}" href="/leaderboard"><i class="fas fa-trophy"></i>Leaderboard</a>
|
<a class="nav-link{% if request.path.endswith('/leaderboard') %} active{% endif %}" href="/leaderboard"><i class="fas fa-trophy"></i>Leaderboard</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link{% if request.path.endswith('/admins') %} active{% endif %}" href="/admins"><i class="fas fa-crown"></i>admins</a>
|
<a class="nav-link{% if request.path.endswith('/admins') %} active{% endif %}" href="/admins"><i class="fas fa-crown"></i>Admins</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link{% if request.path.endswith('/log') %} active{% endif %}" href="/log"><i class="fas fa-scroll-old"></i>Moderation Log</a>
|
<a class="nav-link{% if request.path.endswith('/log') %} active{% endif %}" href="/log"><i class="fas fa-scroll-old"></i>Moderation Log</a>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue