epicyon/webapp_column_left.py

546 lines
21 KiB
Python
Raw Normal View History

2020-11-09 22:44:03 +00:00
__filename__ = "webapp_column_left.py"
__author__ = "Bob Mottram"
__license__ = "AGPL3+"
2021-01-26 10:07:42 +00:00
__version__ = "1.2.0"
2020-11-09 22:44:03 +00:00
__maintainer__ = "Bob Mottram"
2021-09-10 16:14:50 +00:00
__email__ = "bob@libreserver.org"
2020-11-09 22:44:03 +00:00
__status__ = "Production"
2021-06-26 11:27:14 +00:00
__module_group__ = "Web Interface Columns"
2020-11-09 22:44:03 +00:00
import os
2021-12-26 14:08:58 +00:00
from utils import get_config_param
2021-12-27 22:19:18 +00:00
from utils import get_nickname_from_actor
2021-12-26 13:27:57 +00:00
from utils import is_editor
2021-12-26 14:17:13 +00:00
from utils import is_artist
2021-12-26 18:17:37 +00:00
from utils import remove_domain_port
2021-12-26 10:19:59 +00:00
from utils import local_actor_url
2021-12-29 21:55:09 +00:00
from webapp_utils import shares_timeline_json
from webapp_utils import html_post_separator
from webapp_utils import get_left_image_file
from webapp_utils import header_buttons_front_screen
from webapp_utils import html_header_with_external_style
from webapp_utils import html_footer
from webapp_utils import get_banner_file
from webapp_utils import edit_text_field
from shares import share_category_icon
def _links_exist(base_dir: str) -> bool:
2020-11-29 11:31:16 +00:00
"""Returns true if links have been created
"""
2021-12-31 21:18:12 +00:00
links_filename = base_dir + '/accounts/links.txt'
return os.path.isfile(links_filename)
2020-11-29 11:31:16 +00:00
2021-12-29 21:55:09 +00:00
def _get_left_column_shares(base_dir: str,
http_prefix: str, domain: str, domain_full: str,
nickname: str,
2021-12-31 21:18:12 +00:00
max_shares_in_left_column: int,
2021-12-29 21:55:09 +00:00
translate: {},
shared_items_federated_domains: []) -> []:
"""get any shares and turn them into the left column links format
"""
2021-12-31 21:18:12 +00:00
page_number = 1
2021-12-26 10:19:59 +00:00
actor = local_actor_url(http_prefix, nickname, domain_full)
# NOTE: this could potentially be slow if the number of federated
# shared items is large
2022-01-03 22:11:35 +00:00
shares_json, _ = \
2021-12-31 21:18:12 +00:00
shares_timeline_json(actor, page_number, max_shares_in_left_column,
base_dir, domain, nickname,
max_shares_in_left_column,
2021-12-29 21:55:09 +00:00
shared_items_federated_domains, 'shares')
2021-12-31 21:18:12 +00:00
if not shares_json:
return []
2021-12-31 21:18:12 +00:00
links_list = []
ctr = 0
2022-01-03 22:11:35 +00:00
for _, item in shares_json.items():
sharedesc = item['displayName']
2021-09-21 12:44:55 +00:00
if '<' in sharedesc or '?' in sharedesc:
continue
2021-12-31 21:18:12 +00:00
share_id = item['shareId']
2021-12-29 21:55:09 +00:00
# selecting this link calls html_show_share
2021-12-31 21:18:12 +00:00
share_link = actor + '?showshare=' + share_id
2021-09-19 13:59:31 +00:00
if item.get('category'):
2021-12-31 21:18:12 +00:00
share_link += '?category=' + item['category']
2022-01-03 22:11:35 +00:00
share_category = share_category_icon(item['category'])
2021-09-19 13:59:31 +00:00
2022-01-03 22:11:35 +00:00
links_list.append(share_category + sharedesc + ' ' + share_link)
ctr += 1
2021-12-31 21:18:12 +00:00
if ctr >= max_shares_in_left_column:
break
2021-12-31 21:18:12 +00:00
if links_list:
links_list = ['* ' + translate['Shares']] + links_list
return links_list
2021-12-29 21:55:09 +00:00
def _get_left_column_wanted(base_dir: str,
http_prefix: str, domain: str, domain_full: str,
nickname: str,
2021-12-31 21:18:12 +00:00
max_shares_in_left_column: int,
2021-12-29 21:55:09 +00:00
translate: {},
shared_items_federated_domains: []) -> []:
2021-08-09 19:16:19 +00:00
"""get any wanted items and turn them into the left column links format
"""
2021-12-31 21:18:12 +00:00
page_number = 1
2021-12-26 10:19:59 +00:00
actor = local_actor_url(http_prefix, nickname, domain_full)
2021-08-09 19:16:19 +00:00
# NOTE: this could potentially be slow if the number of federated
# wanted items is large
2022-01-03 22:11:35 +00:00
shares_json, _ = \
2021-12-31 21:18:12 +00:00
shares_timeline_json(actor, page_number, max_shares_in_left_column,
base_dir, domain, nickname,
max_shares_in_left_column,
2021-12-29 21:55:09 +00:00
shared_items_federated_domains, 'wanted')
2021-12-31 21:18:12 +00:00
if not shares_json:
2021-08-09 19:16:19 +00:00
return []
2021-12-31 21:18:12 +00:00
links_list = []
2021-08-09 19:16:19 +00:00
ctr = 0
2022-01-03 22:11:35 +00:00
for _, item in shares_json.items():
2021-08-09 19:16:19 +00:00
sharedesc = item['displayName']
2021-09-19 16:20:12 +00:00
if '<' in sharedesc or ';' in sharedesc:
2021-08-09 19:16:19 +00:00
continue
2021-12-31 21:18:12 +00:00
share_id = item['shareId']
2021-12-29 21:55:09 +00:00
# selecting this link calls html_show_share
2021-12-31 21:18:12 +00:00
share_link = actor + '?showwanted=' + share_id
links_list.append(sharedesc + ' ' + share_link)
2021-08-09 19:16:19 +00:00
ctr += 1
2021-12-31 21:18:12 +00:00
if ctr >= max_shares_in_left_column:
2021-08-09 19:16:19 +00:00
break
2021-12-31 21:18:12 +00:00
if links_list:
links_list = ['* ' + translate['Wanted']] + links_list
return links_list
2021-08-09 19:16:19 +00:00
2021-12-29 21:55:09 +00:00
def get_left_column_content(base_dir: str, nickname: str, domain_full: str,
http_prefix: str, translate: {},
editor: bool, artist: bool,
2022-01-03 22:11:35 +00:00
show_back_button: bool, timelinePath: str,
rss_icon_at_top: bool, show_header_image: bool,
front_page: bool, theme: str,
2021-12-31 21:18:12 +00:00
access_keys: {},
2021-12-29 21:55:09 +00:00
shared_items_federated_domains: []) -> str:
2020-11-09 22:44:03 +00:00
"""Returns html content for the left column
"""
2021-12-31 21:18:12 +00:00
html_str = ''
2020-11-09 22:44:03 +00:00
2021-12-31 21:18:12 +00:00
separator_str = html_post_separator(base_dir, 'left')
2021-12-26 18:17:37 +00:00
domain = remove_domain_port(domain_full)
2020-11-09 22:44:03 +00:00
2022-01-03 22:11:35 +00:00
edit_image_class = ''
if show_header_image:
left_image_file, left_column_image_filename = \
2021-12-29 21:55:09 +00:00
get_left_image_file(base_dir, nickname, domain, theme)
2020-11-09 22:44:03 +00:00
# show the image at the top of the column
2022-01-03 22:11:35 +00:00
edit_image_class = 'leftColEdit'
if os.path.isfile(left_column_image_filename):
edit_image_class = 'leftColEditImage'
2021-12-31 21:18:12 +00:00
html_str += \
2021-07-05 19:46:55 +00:00
'\n <center>\n <img class="leftColImg" ' + \
2021-02-01 19:48:46 +00:00
'alt="" loading="lazy" src="/users/' + \
2022-01-03 22:11:35 +00:00
nickname + '/' + left_image_file + '" />\n' + \
2020-11-09 22:44:03 +00:00
' </center>\n'
2022-01-03 22:11:35 +00:00
if show_back_button:
2021-12-31 21:18:12 +00:00
html_str += \
2021-07-05 19:46:55 +00:00
' <div> <a href="' + timelinePath + '">' + \
2020-11-09 22:44:03 +00:00
'<button class="cancelbtn">' + \
translate['Go Back'] + '</button></a>\n'
2022-01-03 22:11:35 +00:00
if (editor or rss_icon_at_top) and not show_header_image:
2021-12-31 21:18:12 +00:00
html_str += '<div class="columnIcons">'
2020-11-09 22:44:03 +00:00
2022-01-03 22:11:35 +00:00
if edit_image_class == 'leftColEdit':
2021-12-31 21:18:12 +00:00
html_str += '\n <center>\n'
2020-11-09 22:44:03 +00:00
2021-12-31 21:18:12 +00:00
html_str += ' <div class="leftColIcons">\n'
2021-12-04 16:59:50 +00:00
2020-11-09 22:44:03 +00:00
if editor:
# show the edit icon
2021-12-31 21:18:12 +00:00
html_str += \
2021-07-05 19:46:55 +00:00
' <a href="/users/' + nickname + '/editlinks" ' + \
2021-12-31 21:18:12 +00:00
'accesskey="' + access_keys['menuEdit'] + '">' + \
2022-01-03 22:11:35 +00:00
'<img class="' + edit_image_class + '" loading="lazy" alt="' + \
2021-02-01 19:28:07 +00:00
translate['Edit Links'] + ' | " title="' + \
2021-07-05 19:46:55 +00:00
translate['Edit Links'] + '" src="/icons/edit.png" /></a>\n'
2020-11-09 22:44:03 +00:00
2021-12-04 16:59:50 +00:00
if artist:
# show the theme designer icon
2021-12-31 21:18:12 +00:00
html_str += \
2021-12-04 16:59:50 +00:00
' <a href="/users/' + nickname + '/themedesigner" ' + \
2021-12-31 21:18:12 +00:00
'accesskey="' + access_keys['menuThemeDesigner'] + '">' + \
2022-01-03 22:11:35 +00:00
'<img class="' + edit_image_class + '" loading="lazy" alt="' + \
2021-12-04 16:59:50 +00:00
translate['Theme Designer'] + ' | " title="' + \
translate['Theme Designer'] + '" src="/icons/theme.png" /></a>\n'
2020-11-09 22:44:03 +00:00
# RSS icon
if nickname != 'news':
# rss feed for this account
2022-01-03 22:11:35 +00:00
rss_url = http_prefix + '://' + domain_full + \
2020-11-09 22:44:03 +00:00
'/blog/' + nickname + '/rss.xml'
else:
# rss feed for all accounts on the instance
2022-01-03 22:11:35 +00:00
rss_url = http_prefix + '://' + domain_full + '/blog/rss.xml'
if not front_page:
rss_title = translate['RSS feed for your blog']
2020-11-09 22:44:03 +00:00
else:
2022-01-03 22:11:35 +00:00
rss_title = translate['RSS feed for this site']
rss_icon_str = \
' <a href="' + rss_url + '"><img class="' + edit_image_class + \
'" loading="lazy" alt="' + rss_title + '" title="' + rss_title + \
2020-12-09 13:08:26 +00:00
'" src="/icons/logorss.png" /></a>\n'
2021-12-25 19:09:03 +00:00
if rss_icon_at_top:
2022-01-03 22:11:35 +00:00
html_str += rss_icon_str
2021-12-31 21:18:12 +00:00
html_str += ' </div>\n'
2020-11-09 22:44:03 +00:00
2022-01-03 22:11:35 +00:00
if edit_image_class == 'leftColEdit':
2021-12-31 21:18:12 +00:00
html_str += ' </center>\n'
2020-11-09 22:44:03 +00:00
2022-01-03 22:11:35 +00:00
if (editor or rss_icon_at_top) and not show_header_image:
2021-12-31 21:18:12 +00:00
html_str += '</div><br>'
2020-11-09 22:44:03 +00:00
2022-01-03 22:11:35 +00:00
# if show_header_image:
2021-12-31 21:18:12 +00:00
# html_str += '<br>'
2020-11-09 22:44:03 +00:00
# flag used not to show the first separator
2021-12-31 21:18:12 +00:00
first_separator_added = False
2021-12-31 21:18:12 +00:00
links_filename = base_dir + '/accounts/links.txt'
2022-01-03 22:11:35 +00:00
links_file_contains_entries = False
2021-12-31 21:18:12 +00:00
links_list = None
if os.path.isfile(links_filename):
2022-01-03 22:11:35 +00:00
with open(links_filename, 'r') as fp_links:
links_list = fp_links.readlines()
2022-01-03 22:11:35 +00:00
if not front_page:
2020-12-06 22:29:03 +00:00
# show a number of shares
2021-12-31 21:18:12 +00:00
max_shares_in_left_column = 3
2022-01-03 22:11:35 +00:00
shares_list = \
2021-12-29 21:55:09 +00:00
_get_left_column_shares(base_dir,
http_prefix, domain, domain_full, nickname,
2021-12-31 21:18:12 +00:00
max_shares_in_left_column, translate,
2021-12-29 21:55:09 +00:00
shared_items_federated_domains)
2022-01-03 22:11:35 +00:00
if links_list and shares_list:
links_list = shares_list + links_list
2022-01-03 22:11:35 +00:00
wanted_list = \
2021-12-29 21:55:09 +00:00
_get_left_column_wanted(base_dir,
http_prefix, domain, domain_full, nickname,
2021-12-31 21:18:12 +00:00
max_shares_in_left_column, translate,
2021-12-29 21:55:09 +00:00
shared_items_federated_domains)
2022-01-03 22:11:35 +00:00
if links_list and wanted_list:
links_list = wanted_list + links_list
2021-08-09 19:16:19 +00:00
2022-01-03 22:11:35 +00:00
new_tab_str = ' target="_blank" rel="nofollow noopener noreferrer"'
2021-12-31 21:18:12 +00:00
if links_list:
html_str += '<nav>\n'
2022-01-03 22:11:35 +00:00
for line_str in links_list:
if ' ' not in line_str:
if '#' not in line_str:
if '*' not in line_str:
if not line_str.startswith('['):
if not line_str.startswith('=> '):
2021-02-24 14:41:46 +00:00
continue
2022-01-03 22:11:35 +00:00
line_str = line_str.strip()
link_str = None
if not line_str.startswith('['):
words = line_str.split(' ')
2021-02-24 14:41:46 +00:00
# get the link
for word in words:
if word == '#':
continue
if word == '*':
continue
if word == '=>':
continue
if '://' in word:
2022-01-03 22:11:35 +00:00
link_str = word
2021-02-24 14:41:46 +00:00
break
else:
# markdown link
2022-01-03 22:11:35 +00:00
if ']' not in line_str:
continue
2022-01-03 22:11:35 +00:00
if '(' not in line_str:
continue
2022-01-03 22:11:35 +00:00
if ')' not in line_str:
2021-02-24 14:31:04 +00:00
continue
2022-01-03 22:11:35 +00:00
link_str = line_str.split('(')[1]
if ')' not in link_str:
2021-02-24 14:41:46 +00:00
continue
2022-01-03 22:11:35 +00:00
link_str = link_str.split(')')[0]
if '://' not in link_str:
2021-02-24 14:41:46 +00:00
continue
2022-01-03 22:11:35 +00:00
line_str = line_str.split('[')[1]
if ']' not in line_str:
2021-02-24 14:41:46 +00:00
continue
2022-01-03 22:11:35 +00:00
line_str = line_str.split(']')[0]
if link_str:
line_str = line_str.replace(link_str, '').strip()
# avoid any dubious scripts being added
2022-01-03 22:11:35 +00:00
if '<' not in line_str:
# remove trailing comma if present
2022-01-03 22:11:35 +00:00
if line_str.endswith(','):
line_str = line_str[:len(line_str)-1]
# add link to the returned html
2022-01-03 22:11:35 +00:00
if '?showshare=' not in link_str and \
'?showwarning=' not in link_str:
2021-12-31 21:18:12 +00:00
html_str += \
2022-01-03 22:11:35 +00:00
' <p><a href="' + link_str + \
'"' + new_tab_str + '>' + \
line_str + '</a></p>\n'
else:
2021-12-31 21:18:12 +00:00
html_str += \
2022-01-03 22:11:35 +00:00
' <p><a href="' + link_str + \
'">' + line_str + '</a></p>\n'
links_file_contains_entries = True
elif line_str.startswith('=> '):
2021-02-24 14:31:04 +00:00
# gemini style link
2022-01-03 22:11:35 +00:00
line_str = line_str.replace('=> ', '')
line_str = line_str.replace(link_str, '')
2021-02-24 14:31:04 +00:00
# add link to the returned html
2022-01-03 22:11:35 +00:00
if '?showshare=' not in link_str and \
'?showwarning=' not in link_str:
2021-12-31 21:18:12 +00:00
html_str += \
2022-01-03 22:11:35 +00:00
' <p><a href="' + link_str + \
'"' + new_tab_str + '>' + \
line_str.strip() + '</a></p>\n'
else:
2021-12-31 21:18:12 +00:00
html_str += \
2022-01-03 22:11:35 +00:00
' <p><a href="' + link_str + \
'">' + line_str.strip() + '</a></p>\n'
links_file_contains_entries = True
else:
2022-01-03 22:11:35 +00:00
if line_str.startswith('#') or line_str.startswith('*'):
line_str = line_str[1:].strip()
2021-12-31 21:18:12 +00:00
if first_separator_added:
html_str += separator_str
first_separator_added = True
html_str += \
' <h3 class="linksHeader">' + \
2022-01-03 22:11:35 +00:00
line_str + '</h3>\n'
else:
2021-12-31 21:18:12 +00:00
html_str += \
2022-01-03 22:11:35 +00:00
' <p>' + line_str + '</p>\n'
links_file_contains_entries = True
2021-12-31 21:18:12 +00:00
html_str += '</nav>\n'
2020-11-09 22:44:03 +00:00
2021-12-31 21:18:12 +00:00
if first_separator_added:
html_str += separator_str
html_str += \
2021-07-27 21:28:20 +00:00
'<p class="login-text"><a href="/users/' + nickname + \
'/catalog.csv">' + translate['Shares Catalog'] + '</a></p>'
2021-12-31 21:18:12 +00:00
html_str += \
2021-04-23 16:07:26 +00:00
'<p class="login-text"><a href="/users/' + \
2021-04-23 16:45:46 +00:00
nickname + '/accesskeys" accesskey="' + \
2021-12-31 21:18:12 +00:00
access_keys['menuKeys'] + '">' + \
2021-04-23 16:07:26 +00:00
translate['Key Shortcuts'] + '</a></p>'
2021-12-31 21:18:12 +00:00
html_str += \
2020-11-15 16:48:55 +00:00
'<p class="login-text"><a href="/about">' + \
translate['About this Instance'] + '</a></p>'
2021-12-31 21:18:12 +00:00
html_str += \
2020-11-15 16:48:55 +00:00
'<p class="login-text"><a href="/terms">' + \
translate['Terms of Service'] + '</a></p>'
2022-01-03 22:11:35 +00:00
if links_file_contains_entries and not rss_icon_at_top:
html_str += '<br><div class="columnIcons">' + rss_icon_str + '</div>'
2020-11-15 16:48:55 +00:00
2021-12-31 21:18:12 +00:00
return html_str
2020-11-09 22:44:03 +00:00
2021-12-29 21:55:09 +00:00
def html_links_mobile(css_cache: {}, base_dir: str,
nickname: str, domain_full: str,
http_prefix: str, translate,
timelinePath: str, authorized: bool,
rss_icon_at_top: bool,
icons_as_buttons: bool,
2021-12-31 23:50:29 +00:00
default_timeline: str,
2021-12-31 21:18:12 +00:00
theme: str, access_keys: {},
2021-12-29 21:55:09 +00:00
shared_items_federated_domains: []) -> str:
2020-11-09 22:44:03 +00:00
"""Show the left column links within mobile view
"""
2021-12-31 21:18:12 +00:00
html_str = ''
2020-11-09 22:44:03 +00:00
# the css filename
2021-12-31 21:18:12 +00:00
css_filename = base_dir + '/epicyon-profile.css'
2021-12-25 16:17:53 +00:00
if os.path.isfile(base_dir + '/epicyon.css'):
2021-12-31 21:18:12 +00:00
css_filename = base_dir + '/epicyon.css'
2020-11-09 22:44:03 +00:00
# is the user a site editor?
if nickname == 'news':
editor = False
2021-12-04 16:59:50 +00:00
artist = False
2020-11-09 22:44:03 +00:00
else:
2021-12-26 13:27:57 +00:00
editor = is_editor(base_dir, nickname)
2021-12-26 14:17:13 +00:00
artist = is_artist(base_dir, nickname)
2020-11-09 22:44:03 +00:00
2021-12-26 18:17:37 +00:00
domain = remove_domain_port(domain_full)
2020-11-09 22:44:03 +00:00
2021-12-31 21:18:12 +00:00
instance_title = \
2021-12-26 14:08:58 +00:00
get_config_param(base_dir, 'instanceTitle')
2021-12-31 21:18:12 +00:00
html_str = \
html_header_with_external_style(css_filename, instance_title, None)
2022-01-03 22:11:35 +00:00
banner_file, _ = \
2021-12-29 21:55:09 +00:00
get_banner_file(base_dir, nickname, domain, theme)
2021-12-31 21:18:12 +00:00
html_str += \
2021-12-31 23:50:29 +00:00
'<a href="/users/' + nickname + '/' + default_timeline + '" ' + \
2021-12-31 21:18:12 +00:00
'accesskey="' + access_keys['menuTimeline'] + '">' + \
2020-11-09 22:44:03 +00:00
'<img loading="lazy" class="timeline-banner" ' + \
2021-02-01 19:48:46 +00:00
'alt="' + translate['Switch to timeline view'] + '" ' + \
2021-12-31 21:18:12 +00:00
'src="/users/' + nickname + '/' + banner_file + '" /></a>\n'
2020-11-09 22:44:03 +00:00
2021-12-31 21:18:12 +00:00
html_str += '<div class="col-left-mobile">\n'
html_str += '<center>' + \
2021-12-29 21:55:09 +00:00
header_buttons_front_screen(translate, nickname,
'links', authorized,
icons_as_buttons) + '</center>'
2021-12-31 21:18:12 +00:00
html_str += \
2021-12-29 21:55:09 +00:00
get_left_column_content(base_dir, nickname, domain_full,
http_prefix, translate,
editor, artist,
False, timelinePath,
rss_icon_at_top, False, False,
2021-12-31 21:18:12 +00:00
theme, access_keys,
2021-12-29 21:55:09 +00:00
shared_items_federated_domains)
if editor and not _links_exist(base_dir):
2021-12-31 21:18:12 +00:00
html_str += '<br><br><br>\n<center>\n '
html_str += translate['Select the edit icon to add web links']
html_str += '\n</center>\n'
# end of col-left-mobile
2021-12-31 21:18:12 +00:00
html_str += '</div>\n'
2021-12-31 21:18:12 +00:00
html_str += '</div>\n' + html_footer()
return html_str
2020-11-09 22:44:03 +00:00
2021-12-29 21:55:09 +00:00
def html_edit_links(css_cache: {}, translate: {}, base_dir: str, path: str,
domain: str, port: int, http_prefix: str,
2021-12-31 23:50:29 +00:00
default_timeline: str, theme: str,
2021-12-31 21:18:12 +00:00
access_keys: {}) -> str:
2020-11-09 22:44:03 +00:00
"""Shows the edit links screen
"""
if '/users/' not in path:
return ''
path = path.replace('/inbox', '').replace('/outbox', '')
2021-08-09 19:37:18 +00:00
path = path.replace('/shares', '').replace('/wanted', '')
2020-11-09 22:44:03 +00:00
2021-12-27 22:19:18 +00:00
nickname = get_nickname_from_actor(path)
2020-11-09 22:44:03 +00:00
if not nickname:
return ''
# is the user a moderator?
2021-12-26 13:27:57 +00:00
if not is_editor(base_dir, nickname):
2020-11-09 22:44:03 +00:00
return ''
2021-12-31 21:18:12 +00:00
css_filename = base_dir + '/epicyon-links.css'
2021-12-25 16:17:53 +00:00
if os.path.isfile(base_dir + '/links.css'):
2021-12-31 21:18:12 +00:00
css_filename = base_dir + '/links.css'
2020-11-09 22:44:03 +00:00
# filename of the banner shown at the top
2021-12-31 21:18:12 +00:00
banner_file, _ = \
2021-12-29 21:55:09 +00:00
get_banner_file(base_dir, nickname, domain, theme)
2020-11-09 22:44:03 +00:00
2021-12-31 21:18:12 +00:00
instance_title = \
2021-12-26 14:08:58 +00:00
get_config_param(base_dir, 'instanceTitle')
2021-12-31 21:18:12 +00:00
edit_links_form = \
html_header_with_external_style(css_filename, instance_title, None)
2020-11-09 22:44:03 +00:00
# top banner
2021-12-31 21:18:12 +00:00
edit_links_form += \
2020-12-27 16:57:15 +00:00
'<header>\n' + \
2021-12-31 23:50:29 +00:00
'<a href="/users/' + nickname + '/' + default_timeline + \
'" title="' + \
2020-11-09 22:44:03 +00:00
translate['Switch to timeline view'] + '" alt="' + \
2021-04-23 18:00:11 +00:00
translate['Switch to timeline view'] + '" ' + \
2021-12-31 21:18:12 +00:00
'accesskey="' + access_keys['menuTimeline'] + '">\n'
edit_links_form += \
2021-07-05 19:46:55 +00:00
'<img loading="lazy" class="timeline-banner" ' + \
2021-02-01 19:48:46 +00:00
'alt = "" src="' + \
2021-12-31 21:18:12 +00:00
'/users/' + nickname + '/' + banner_file + '" /></a>\n' + \
2020-12-27 16:57:15 +00:00
'</header>\n'
2020-11-09 22:44:03 +00:00
2021-12-31 21:18:12 +00:00
edit_links_form += \
2020-11-09 22:44:03 +00:00
'<form enctype="multipart/form-data" method="POST" ' + \
'accept-charset="UTF-8" action="' + path + '/linksdata">\n'
2021-12-31 21:18:12 +00:00
edit_links_form += \
2020-11-09 22:44:03 +00:00
' <div class="vertical-center">\n'
2021-12-31 21:18:12 +00:00
edit_links_form += \
2020-12-21 16:07:51 +00:00
' <div class="containerSubmitNewPost">\n'
2021-12-31 21:18:12 +00:00
edit_links_form += \
2020-12-21 16:24:13 +00:00
' <h1>' + translate['Edit Links'] + '</h1>'
2021-12-31 21:18:12 +00:00
edit_links_form += \
2020-12-21 16:24:13 +00:00
' <input type="submit" name="submitLinks" value="' + \
2021-04-23 18:00:11 +00:00
translate['Submit'] + '" ' + \
2021-12-31 21:18:12 +00:00
'accesskey="' + access_keys['submitButton'] + '">\n'
edit_links_form += \
2020-11-09 22:44:03 +00:00
' </div>\n'
2021-12-31 21:18:12 +00:00
links_filename = base_dir + '/accounts/links.txt'
links_str = ''
if os.path.isfile(links_filename):
with open(links_filename, 'r') as fp_links:
links_str = fp_links.read()
2020-11-09 22:44:03 +00:00
2021-12-31 21:18:12 +00:00
edit_links_form += \
2020-11-09 22:44:03 +00:00
'<div class="container">'
2021-12-31 21:18:12 +00:00
edit_links_form += \
2020-11-09 22:44:03 +00:00
' ' + \
translate['One link per line. Description followed by the link.'] + \
'<br>'
2021-12-31 21:18:12 +00:00
new_col_link_str = translate['New link title and URL']
edit_links_form += \
edit_text_field(None, 'newColLink', '', new_col_link_str)
edit_links_form += \
2021-02-28 14:26:04 +00:00
' <textarea id="message" name="editedLinks" ' + \
2021-12-31 21:18:12 +00:00
'style="height:80vh" spellcheck="false">' + links_str + '</textarea>'
edit_links_form += \
2020-11-09 22:44:03 +00:00
'</div>'
# the admin can edit terms of service and about text
2021-12-31 21:18:12 +00:00
admin_nickname = get_config_param(base_dir, 'admin')
if admin_nickname:
if nickname == admin_nickname:
about_filename = base_dir + '/accounts/about.md'
about_str = ''
if os.path.isfile(about_filename):
with open(about_filename, 'r') as fp_about:
about_str = fp_about.read()
edit_links_form += \
'<div class="container">'
2021-12-31 21:18:12 +00:00
edit_links_form += \
' ' + \
translate['About this Instance'] + \
'<br>'
2021-12-31 21:18:12 +00:00
edit_links_form += \
' <textarea id="message" name="editedAbout" ' + \
2021-02-28 14:48:41 +00:00
'style="height:100vh" spellcheck="true" autocomplete="on">' + \
2021-12-31 21:18:12 +00:00
about_str + '</textarea>'
edit_links_form += \
'</div>'
2021-12-31 21:18:12 +00:00
tos_filename = base_dir + '/accounts/tos.md'
tos_str = ''
if os.path.isfile(tos_filename):
2022-01-03 22:11:35 +00:00
with open(tos_filename, 'r') as fp_tos:
tos_str = fp_tos.read()
2021-12-31 21:18:12 +00:00
edit_links_form += \
'<div class="container">'
2021-12-31 21:18:12 +00:00
edit_links_form += \
' ' + \
translate['Terms of Service'] + \
'<br>'
2021-12-31 21:18:12 +00:00
edit_links_form += \
' <textarea id="message" name="editedTOS" ' + \
2021-02-28 14:48:41 +00:00
'style="height:100vh" spellcheck="true" autocomplete="on">' + \
2021-12-31 21:18:12 +00:00
tos_str + '</textarea>'
edit_links_form += \
'</div>'
2021-12-31 21:18:12 +00:00
edit_links_form += html_footer()
return edit_links_form