Show link to lap in text mode or privacy browsers rather than iframe

main
bashrc 2026-03-01 11:14:33 +00:00
parent ce77da201e
commit 1fbe5ad341
8 changed files with 81 additions and 3 deletions

View File

@ -17,6 +17,7 @@ from webapp_utils import get_post_attachments_as_html
from webapp_utils import edit_text_area
from webapp_media import add_embedded_elements
from timeFunctions import date_from_string_format
from utils import replace_embedded_map_with_link
from utils import replace_strings
from utils import data_dir
from utils import remove_link_tracking
@ -567,6 +568,8 @@ def _html_blog_remove_cw_button(blog_str: str, translate: {}) -> str:
blog_str = replace_strings(blog_str, replacements)
blog_str = blog_str.replace(translate['SHOW MORE'], '')
blog_str = blog_str.replace(translate['Show Map'], '')
blog_str = replace_embedded_map_with_link(blog_str, translate)
return blog_str

View File

@ -887,7 +887,8 @@ def html_open_street_map(url: str,
'&layer=mapnik" style="border: 1px solid black" ' + \
'sandbox="allow-scripts allow-same-origin">' + \
'</iframe><br/><small><a href="' + osm_url + \
'">' + translate['View Larger Map'] + '</a></small>\n'
'" target="_blank" rel="nofollow noopener noreferrer">' + \
translate['View Larger Map'] + '</a></small>\n'
return html_str

View File

@ -4295,3 +4295,47 @@ def get_event_categories() -> []:
'THEATRE',
'WORKSHOPS_SKILL_SHARING'
)
def replace_embedded_map_with_link(text: str, translate: {}) -> str:
"""Replaces an embedded OSM map with a link to the map location
"""
if '<details>' not in text:
return text
map_str_start = 'https://www.openstreetmap.org'
map_str = 'src="' + map_str_start
if map_str not in text:
return text
sections = text.split('<details>')
for section_str in sections:
if '</details>' not in section_str:
continue
section_str = \
'<details>' + section_str.split('</details>')[0] + '</details>'
if map_str not in section_str:
continue
# get the map url
map_url = map_str_start + section_str.split(map_str)[1]
if '"' not in map_url:
continue
map_url = map_url.split('"')[0]
show_map_str = 'Show Map'
if translate.get('Show Map'):
show_map_str = translate['Show Map']
map_link = \
'<a href="' + map_url + \
'" target="_blank" rel="nofollow noopener noreferrer">' + \
show_map_str + '</a>'
# replace the iframe with a link
text = text.replace(section_str, map_link)
return text
def is_private_browser(ua_str: str) -> bool:
"""Does the given user agent indicate that the browser is specialised
for privacy?
"""
ua_str_lower = ua_str.lower()
if 'privacy' in ua_str_lower or 'private' in ua_str_lower:
return True
return False

View File

@ -11,6 +11,8 @@ __module_group__ = "Timeline"
import os
from conversation import download_conversation_posts
from flags import is_public_post
from utils import is_private_browser
from utils import replace_embedded_map_with_link
from utils import get_mutuals_of_person
from utils import remove_id_ending
from utils import get_config_param
@ -190,6 +192,9 @@ def html_conversation_view(authorized: bool, post_id: str,
# Also replace MITM text with an eye icon
if text_mode_browser(ua_str):
conv_str = text_mode_removals(conv_str, translate)
conv_str = replace_embedded_map_with_link(conv_str, translate)
elif is_private_browser(ua_str):
conv_str = replace_embedded_map_with_link(conv_str, translate)
conv_str += text_mode_separator + html_footer()
return conv_str

View File

@ -42,6 +42,8 @@ from textmode import text_mode_removals
from quote import get_quote_toot_url
from timeFunctions import date_from_string_format
from timeFunctions import convert_published_to_local_timezone
from utils import is_private_browser
from utils import replace_embedded_map_with_link
from utils import get_mutuals_of_person
from utils import save_json
from utils import remove_header_tags
@ -508,6 +510,9 @@ def prepare_post_from_html_cache(nickname: str, post_html: str, box_name: str,
'audio')
# replace MITM text with an eye icon
post_html = text_mode_removals(post_html, translate)
post_html = replace_embedded_map_with_link(post_html, translate)
elif is_private_browser(ua_str):
post_html = replace_embedded_map_with_link(post_html, translate)
# if on the bookmarks timeline then remain there
if box_name in ('tlbookmarks', 'bookmarks'):

View File

@ -23,6 +23,8 @@ from textmode import text_mode_removals
from unicodetext import uninvert_text
from unicodetext import standardize_text
from occupation import get_occupation_name
from utils import is_private_browser
from utils import replace_embedded_map_with_link
from utils import is_yggdrasil_address
from utils import get_actor_type
from utils import get_mutuals_of_person
@ -703,6 +705,9 @@ def html_profile_after_search(authorized: bool,
if text_mode_browser(ua_str):
profile_str = text_mode_removals(profile_str, translate)
profile_str = replace_embedded_map_with_link(profile_str, translate)
elif is_private_browser(ua_str):
profile_str = replace_embedded_map_with_link(profile_str, translate)
instance_title = get_config_param(base_dir, 'instanceTitle')
preload_images: list[str] = []

View File

@ -14,6 +14,8 @@ from flags import is_editor
from flags import is_artist
from flags import is_float
from flags import is_moderator
from utils import is_private_browser
from utils import replace_embedded_map_with_link
from utils import get_mutuals_of_person
from utils import data_dir
from utils import dangerous_markup
@ -911,6 +913,9 @@ def html_timeline(default_timeline: str,
# Also replace MITM text with an eye icon
if is_text_browser:
tl_str = text_mode_removals(tl_str, translate)
tl_str = replace_embedded_map_with_link(tl_str, translate)
elif is_private_browser(ua_str):
tl_str = replace_embedded_map_with_link(tl_str, translate)
tl_str += \
_html_timeline_end(base_dir, nickname, domain_full,
@ -941,6 +946,9 @@ def html_timeline(default_timeline: str,
# Also replace MITM text with an eye icon
if is_text_browser:
tl_str = text_mode_removals(tl_str, translate)
tl_str = replace_embedded_map_with_link(tl_str, translate)
elif is_private_browser(ua_str):
tl_str = replace_embedded_map_with_link(tl_str, translate)
tl_str += \
_html_timeline_end(base_dir, nickname, domain_full,
@ -1185,6 +1193,9 @@ def html_timeline(default_timeline: str,
if is_text_browser:
tl_str = text_mode_removals(tl_str, translate)
tl_str = text_mode_replacements(tl_str, translate)
tl_str = replace_embedded_map_with_link(tl_str, translate)
elif is_private_browser(ua_str):
tl_str = replace_embedded_map_with_link(tl_str, translate)
tl_str += \
_html_timeline_end(base_dir, nickname, domain_full,

View File

@ -15,6 +15,7 @@ from session import get_json_valid
from flags import is_float
from flags import is_moderator
from formats import media_file_mime_type
from utils import replace_embedded_map_with_link
from utils import chatbot_nicknames
from utils import replace_strings
from utils import get_image_file
@ -279,19 +280,22 @@ def get_show_map_button(post_id: str, translate: {},
show_map_str = 'Show Map'
if translate.get('Show Map'):
show_map_str = translate['Show Map']
return ' <details><summary class="cw" tabindex="10">' + \
html_str = ' <details><summary class="cw" tabindex="10">' + \
show_map_str + '</summary>' + \
'<div id="' + post_id + '">' + map_content + \
'</div></details>\n'
return html_str
def open_content_warning(text: str, translate: {}) -> str:
"""Opens content warning when replying to a post with a cw
so that you can see what you are replying to
"""
text = replace_embedded_map_with_link(text, translate)
text = text.replace('<details>', '').replace('</details>', '')
text = text.replace(translate['Show Map'], '', 1)
return text.replace(translate['SHOW MORE'], '', 1)
text = text.replace(translate['SHOW MORE'], '', 1)
return text
def _set_actor_property_url(actor_json: {},