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-25 16:17:53 +00:00
|
|
|
linksFilename = base_dir + '/accounts/links.txt'
|
2020-11-29 11:31:16 +00:00
|
|
|
return os.path.isfile(linksFilename)
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
maxSharesInLeftColumn: int,
|
|
|
|
translate: {},
|
|
|
|
shared_items_federated_domains: []) -> []:
|
2020-12-06 22:26:39 +00:00
|
|
|
"""get any shares and turn them into the left column links format
|
|
|
|
"""
|
|
|
|
pageNumber = 1
|
2021-12-26 10:19:59 +00:00
|
|
|
actor = local_actor_url(http_prefix, nickname, domain_full)
|
2021-07-27 14:26:48 +00:00
|
|
|
# NOTE: this could potentially be slow if the number of federated
|
|
|
|
# shared items is large
|
2020-12-06 22:26:39 +00:00
|
|
|
sharesJson, lastPage = \
|
2021-12-29 21:55:09 +00:00
|
|
|
shares_timeline_json(actor, pageNumber, maxSharesInLeftColumn,
|
|
|
|
base_dir, domain, nickname, maxSharesInLeftColumn,
|
|
|
|
shared_items_federated_domains, 'shares')
|
2020-12-06 22:26:39 +00:00
|
|
|
if not sharesJson:
|
|
|
|
return []
|
|
|
|
|
|
|
|
linksList = []
|
|
|
|
ctr = 0
|
|
|
|
for published, item in sharesJson.items():
|
|
|
|
sharedesc = item['displayName']
|
2021-09-21 12:44:55 +00:00
|
|
|
if '<' in sharedesc or '?' in sharedesc:
|
2020-12-06 22:56:45 +00:00
|
|
|
continue
|
2021-07-28 19:00:22 +00:00
|
|
|
shareId = item['shareId']
|
2021-12-29 21:55:09 +00:00
|
|
|
# selecting this link calls html_show_share
|
2021-07-28 19:00:22 +00:00
|
|
|
shareLink = actor + '?showshare=' + shareId
|
2021-09-19 13:59:31 +00:00
|
|
|
if item.get('category'):
|
2021-09-21 12:44:55 +00:00
|
|
|
shareLink += '?category=' + item['category']
|
2021-12-29 21:55:09 +00:00
|
|
|
shareCategory = share_category_icon(item['category'])
|
2021-09-19 13:59:31 +00:00
|
|
|
|
|
|
|
linksList.append(shareCategory + sharedesc + ' ' + shareLink)
|
2020-12-06 22:26:39 +00:00
|
|
|
ctr += 1
|
|
|
|
if ctr >= maxSharesInLeftColumn:
|
|
|
|
break
|
|
|
|
|
|
|
|
if linksList:
|
|
|
|
linksList = ['* ' + translate['Shares']] + linksList
|
|
|
|
return linksList
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
maxSharesInLeftColumn: int,
|
|
|
|
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
|
|
|
|
"""
|
|
|
|
pageNumber = 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
|
|
|
|
sharesJson, lastPage = \
|
2021-12-29 21:55:09 +00:00
|
|
|
shares_timeline_json(actor, pageNumber, maxSharesInLeftColumn,
|
|
|
|
base_dir, domain, nickname, maxSharesInLeftColumn,
|
|
|
|
shared_items_federated_domains, 'wanted')
|
2021-08-09 19:16:19 +00:00
|
|
|
if not sharesJson:
|
|
|
|
return []
|
|
|
|
|
|
|
|
linksList = []
|
|
|
|
ctr = 0
|
|
|
|
for published, item in sharesJson.items():
|
|
|
|
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
|
|
|
|
shareId = item['shareId']
|
2021-12-29 21:55:09 +00:00
|
|
|
# selecting this link calls html_show_share
|
2021-08-09 19:16:19 +00:00
|
|
|
shareLink = actor + '?showwanted=' + shareId
|
|
|
|
linksList.append(sharedesc + ' ' + shareLink)
|
|
|
|
ctr += 1
|
|
|
|
if ctr >= maxSharesInLeftColumn:
|
|
|
|
break
|
|
|
|
|
|
|
|
if linksList:
|
|
|
|
linksList = ['* ' + translate['Wanted']] + linksList
|
|
|
|
return linksList
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
showBackButton: bool, timelinePath: str,
|
|
|
|
rss_icon_at_top: bool, showHeaderImage: bool,
|
|
|
|
frontPage: bool, theme: str,
|
|
|
|
accessKeys: {},
|
|
|
|
shared_items_federated_domains: []) -> str:
|
2020-11-09 22:44:03 +00:00
|
|
|
"""Returns html content for the left column
|
|
|
|
"""
|
|
|
|
htmlStr = ''
|
|
|
|
|
2021-12-29 21:55:09 +00:00
|
|
|
separatorStr = 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
|
|
|
|
|
|
|
editImageClass = ''
|
|
|
|
if showHeaderImage:
|
|
|
|
leftImageFile, leftColumnImageFilename = \
|
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
|
|
|
|
editImageClass = 'leftColEdit'
|
|
|
|
if os.path.isfile(leftColumnImageFilename):
|
|
|
|
editImageClass = 'leftColEditImage'
|
|
|
|
htmlStr += \
|
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/' + \
|
2020-11-09 22:44:03 +00:00
|
|
|
nickname + '/' + leftImageFile + '" />\n' + \
|
|
|
|
' </center>\n'
|
|
|
|
|
|
|
|
if showBackButton:
|
|
|
|
htmlStr += \
|
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'
|
|
|
|
|
2021-12-25 19:09:03 +00:00
|
|
|
if (editor or rss_icon_at_top) and not showHeaderImage:
|
2020-11-09 22:44:03 +00:00
|
|
|
htmlStr += '<div class="columnIcons">'
|
|
|
|
|
|
|
|
if editImageClass == 'leftColEdit':
|
|
|
|
htmlStr += '\n <center>\n'
|
|
|
|
|
|
|
|
htmlStr += ' <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
|
|
|
|
htmlStr += \
|
2021-07-05 19:46:55 +00:00
|
|
|
' <a href="/users/' + nickname + '/editlinks" ' + \
|
2021-04-23 17:49:09 +00:00
|
|
|
'accesskey="' + accessKeys['menuEdit'] + '">' + \
|
2021-07-05 19:46:55 +00:00
|
|
|
'<img class="' + editImageClass + '" 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
|
|
|
|
htmlStr += \
|
|
|
|
' <a href="/users/' + nickname + '/themedesigner" ' + \
|
|
|
|
'accesskey="' + accessKeys['menuThemeDesigner'] + '">' + \
|
|
|
|
'<img class="' + editImageClass + '" loading="lazy" alt="' + \
|
|
|
|
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
|
2021-12-26 10:00:46 +00:00
|
|
|
rssUrl = 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
|
2021-12-26 10:00:46 +00:00
|
|
|
rssUrl = http_prefix + '://' + domain_full + '/blog/rss.xml'
|
2020-11-09 22:44:03 +00:00
|
|
|
if not frontPage:
|
|
|
|
rssTitle = translate['RSS feed for your blog']
|
|
|
|
else:
|
|
|
|
rssTitle = translate['RSS feed for this site']
|
|
|
|
rssIconStr = \
|
2021-07-05 19:46:55 +00:00
|
|
|
' <a href="' + rssUrl + '"><img class="' + editImageClass + \
|
|
|
|
'" loading="lazy" alt="' + rssTitle + '" title="' + rssTitle + \
|
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:
|
2020-11-09 22:44:03 +00:00
|
|
|
htmlStr += rssIconStr
|
|
|
|
htmlStr += ' </div>\n'
|
|
|
|
|
|
|
|
if editImageClass == 'leftColEdit':
|
|
|
|
htmlStr += ' </center>\n'
|
|
|
|
|
2021-12-25 19:09:03 +00:00
|
|
|
if (editor or rss_icon_at_top) and not showHeaderImage:
|
2020-11-09 22:44:03 +00:00
|
|
|
htmlStr += '</div><br>'
|
|
|
|
|
|
|
|
# if showHeaderImage:
|
|
|
|
# htmlStr += '<br>'
|
|
|
|
|
2020-11-15 18:42:37 +00:00
|
|
|
# flag used not to show the first separator
|
|
|
|
firstSeparatorAdded = False
|
|
|
|
|
2021-12-25 16:17:53 +00:00
|
|
|
linksFilename = base_dir + '/accounts/links.txt'
|
2020-11-09 22:44:03 +00:00
|
|
|
linksFileContainsEntries = False
|
2020-12-06 22:26:39 +00:00
|
|
|
linksList = None
|
2020-11-09 22:44:03 +00:00
|
|
|
if os.path.isfile(linksFilename):
|
2021-07-13 14:40:49 +00:00
|
|
|
with open(linksFilename, 'r') as f:
|
2020-11-09 22:44:03 +00:00
|
|
|
linksList = f.readlines()
|
2020-12-06 22:26:39 +00:00
|
|
|
|
2020-12-06 22:29:03 +00:00
|
|
|
if not frontPage:
|
|
|
|
# show a number of shares
|
|
|
|
maxSharesInLeftColumn = 3
|
|
|
|
sharesList = \
|
2021-12-29 21:55:09 +00:00
|
|
|
_get_left_column_shares(base_dir,
|
|
|
|
http_prefix, domain, domain_full, nickname,
|
|
|
|
maxSharesInLeftColumn, translate,
|
|
|
|
shared_items_federated_domains)
|
2020-12-06 22:29:03 +00:00
|
|
|
if linksList and sharesList:
|
2020-12-06 22:35:25 +00:00
|
|
|
linksList = sharesList + linksList
|
2020-12-06 22:26:39 +00:00
|
|
|
|
2021-08-09 19:16:19 +00:00
|
|
|
wantedList = \
|
2021-12-29 21:55:09 +00:00
|
|
|
_get_left_column_wanted(base_dir,
|
|
|
|
http_prefix, domain, domain_full, nickname,
|
|
|
|
maxSharesInLeftColumn, translate,
|
|
|
|
shared_items_federated_domains)
|
2021-08-09 19:16:19 +00:00
|
|
|
if linksList and wantedList:
|
|
|
|
linksList = wantedList + linksList
|
|
|
|
|
2021-07-28 19:16:42 +00:00
|
|
|
newTabStr = ' target="_blank" rel="nofollow noopener noreferrer"'
|
2020-12-06 22:26:39 +00:00
|
|
|
if linksList:
|
2020-12-27 15:22:14 +00:00
|
|
|
htmlStr += '<nav>\n'
|
2020-12-06 22:26:39 +00:00
|
|
|
for lineStr in linksList:
|
|
|
|
if ' ' not in lineStr:
|
|
|
|
if '#' not in lineStr:
|
|
|
|
if '*' not in lineStr:
|
2021-02-24 14:41:46 +00:00
|
|
|
if not lineStr.startswith('['):
|
|
|
|
if not lineStr.startswith('=> '):
|
|
|
|
continue
|
2020-12-06 22:26:39 +00:00
|
|
|
lineStr = lineStr.strip()
|
|
|
|
linkStr = None
|
2021-02-24 14:41:46 +00:00
|
|
|
if not lineStr.startswith('['):
|
|
|
|
words = lineStr.split(' ')
|
|
|
|
# get the link
|
|
|
|
for word in words:
|
|
|
|
if word == '#':
|
|
|
|
continue
|
|
|
|
if word == '*':
|
|
|
|
continue
|
|
|
|
if word == '=>':
|
|
|
|
continue
|
|
|
|
if '://' in word:
|
|
|
|
linkStr = word
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
# markdown link
|
|
|
|
if ']' not in lineStr:
|
2020-12-06 22:26:39 +00:00
|
|
|
continue
|
2021-02-24 14:41:46 +00:00
|
|
|
if '(' not in lineStr:
|
2020-12-06 22:26:39 +00:00
|
|
|
continue
|
2021-02-24 14:41:46 +00:00
|
|
|
if ')' not in lineStr:
|
2021-02-24 14:31:04 +00:00
|
|
|
continue
|
2021-02-24 14:41:46 +00:00
|
|
|
linkStr = lineStr.split('(')[1]
|
|
|
|
if ')' not in linkStr:
|
|
|
|
continue
|
|
|
|
linkStr = linkStr.split(')')[0]
|
|
|
|
if '://' not in linkStr:
|
|
|
|
continue
|
|
|
|
lineStr = lineStr.split('[')[1]
|
|
|
|
if ']' not in lineStr:
|
|
|
|
continue
|
|
|
|
lineStr = lineStr.split(']')[0]
|
2020-12-06 22:26:39 +00:00
|
|
|
if linkStr:
|
|
|
|
lineStr = lineStr.replace(linkStr, '').strip()
|
|
|
|
# avoid any dubious scripts being added
|
|
|
|
if '<' not in lineStr:
|
|
|
|
# remove trailing comma if present
|
|
|
|
if lineStr.endswith(','):
|
|
|
|
lineStr = lineStr[:len(lineStr)-1]
|
|
|
|
# add link to the returned html
|
2021-08-09 19:16:19 +00:00
|
|
|
if '?showshare=' not in linkStr and \
|
|
|
|
'?showwarning=' not in linkStr:
|
2021-07-28 19:16:42 +00:00
|
|
|
htmlStr += \
|
|
|
|
' <p><a href="' + linkStr + \
|
|
|
|
'"' + newTabStr + '>' + \
|
|
|
|
lineStr + '</a></p>\n'
|
|
|
|
else:
|
|
|
|
htmlStr += \
|
|
|
|
' <p><a href="' + linkStr + \
|
|
|
|
'">' + lineStr + '</a></p>\n'
|
2020-11-09 22:44:03 +00:00
|
|
|
linksFileContainsEntries = True
|
2021-02-24 14:31:04 +00:00
|
|
|
elif lineStr.startswith('=> '):
|
|
|
|
# gemini style link
|
|
|
|
lineStr = lineStr.replace('=> ', '')
|
|
|
|
lineStr = lineStr.replace(linkStr, '')
|
|
|
|
# add link to the returned html
|
2021-08-09 19:16:19 +00:00
|
|
|
if '?showshare=' not in linkStr and \
|
|
|
|
'?showwarning=' not in linkStr:
|
2021-07-28 19:16:42 +00:00
|
|
|
htmlStr += \
|
|
|
|
' <p><a href="' + linkStr + \
|
|
|
|
'"' + newTabStr + '>' + \
|
|
|
|
lineStr.strip() + '</a></p>\n'
|
|
|
|
else:
|
|
|
|
htmlStr += \
|
|
|
|
' <p><a href="' + linkStr + \
|
|
|
|
'">' + lineStr.strip() + '</a></p>\n'
|
2021-02-24 14:31:04 +00:00
|
|
|
linksFileContainsEntries = True
|
2020-12-06 22:26:39 +00:00
|
|
|
else:
|
|
|
|
if lineStr.startswith('#') or lineStr.startswith('*'):
|
|
|
|
lineStr = lineStr[1:].strip()
|
|
|
|
if firstSeparatorAdded:
|
|
|
|
htmlStr += separatorStr
|
|
|
|
firstSeparatorAdded = True
|
|
|
|
htmlStr += \
|
|
|
|
' <h3 class="linksHeader">' + \
|
|
|
|
lineStr + '</h3>\n'
|
|
|
|
else:
|
|
|
|
htmlStr += \
|
|
|
|
' <p>' + lineStr + '</p>\n'
|
|
|
|
linksFileContainsEntries = True
|
2020-12-27 15:22:14 +00:00
|
|
|
htmlStr += '</nav>\n'
|
2020-11-09 22:44:03 +00:00
|
|
|
|
2020-11-15 18:42:37 +00:00
|
|
|
if firstSeparatorAdded:
|
|
|
|
htmlStr += separatorStr
|
2021-07-27 21:28:20 +00:00
|
|
|
htmlStr += \
|
|
|
|
'<p class="login-text"><a href="/users/' + nickname + \
|
|
|
|
'/catalog.csv">' + translate['Shares Catalog'] + '</a></p>'
|
2021-04-23 16:07:26 +00:00
|
|
|
htmlStr += \
|
|
|
|
'<p class="login-text"><a href="/users/' + \
|
2021-04-23 16:45:46 +00:00
|
|
|
nickname + '/accesskeys" accesskey="' + \
|
2021-04-23 16:29:03 +00:00
|
|
|
accessKeys['menuKeys'] + '">' + \
|
2021-04-23 16:07:26 +00:00
|
|
|
translate['Key Shortcuts'] + '</a></p>'
|
2020-11-15 16:48:55 +00:00
|
|
|
htmlStr += \
|
|
|
|
'<p class="login-text"><a href="/about">' + \
|
|
|
|
translate['About this Instance'] + '</a></p>'
|
|
|
|
htmlStr += \
|
|
|
|
'<p class="login-text"><a href="/terms">' + \
|
|
|
|
translate['Terms of Service'] + '</a></p>'
|
|
|
|
|
2021-12-25 19:09:03 +00:00
|
|
|
if linksFileContainsEntries and not rss_icon_at_top:
|
2020-11-09 22:44:03 +00:00
|
|
|
htmlStr += '<br><div class="columnIcons">' + rssIconStr + '</div>'
|
2020-11-15 16:48:55 +00:00
|
|
|
|
2020-11-09 22:44:03 +00:00
|
|
|
return htmlStr
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
defaultTimeline: str,
|
|
|
|
theme: str, accessKeys: {},
|
|
|
|
shared_items_federated_domains: []) -> str:
|
2020-11-09 22:44:03 +00:00
|
|
|
"""Show the left column links within mobile view
|
|
|
|
"""
|
|
|
|
htmlStr = ''
|
|
|
|
|
|
|
|
# the css filename
|
2021-12-25 16:17:53 +00:00
|
|
|
cssFilename = base_dir + '/epicyon-profile.css'
|
|
|
|
if os.path.isfile(base_dir + '/epicyon.css'):
|
|
|
|
cssFilename = 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-01-11 19:46:21 +00:00
|
|
|
instanceTitle = \
|
2021-12-26 14:08:58 +00:00
|
|
|
get_config_param(base_dir, 'instanceTitle')
|
2021-12-29 21:55:09 +00:00
|
|
|
htmlStr = html_header_with_external_style(cssFilename, instanceTitle, None)
|
2020-12-20 17:26:38 +00:00
|
|
|
bannerFile, bannerFilename = \
|
2021-12-29 21:55:09 +00:00
|
|
|
get_banner_file(base_dir, nickname, domain, theme)
|
2020-11-09 22:44:03 +00:00
|
|
|
htmlStr += \
|
2021-04-23 17:46:57 +00:00
|
|
|
'<a href="/users/' + nickname + '/' + defaultTimeline + '" ' + \
|
|
|
|
'accesskey="' + accessKeys['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'] + '" ' + \
|
2020-11-09 22:44:03 +00:00
|
|
|
'src="/users/' + nickname + '/' + bannerFile + '" /></a>\n'
|
|
|
|
|
2020-11-19 21:57:26 +00:00
|
|
|
htmlStr += '<div class="col-left-mobile">\n'
|
2020-11-09 22:44:03 +00:00
|
|
|
htmlStr += '<center>' + \
|
2021-12-29 21:55:09 +00:00
|
|
|
header_buttons_front_screen(translate, nickname,
|
|
|
|
'links', authorized,
|
|
|
|
icons_as_buttons) + '</center>'
|
2021-11-30 22:28:00 +00:00
|
|
|
htmlStr += \
|
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,
|
|
|
|
theme, accessKeys,
|
|
|
|
shared_items_federated_domains)
|
|
|
|
if editor and not _links_exist(base_dir):
|
2021-11-30 22:28:00 +00:00
|
|
|
htmlStr += '<br><br><br>\n<center>\n '
|
|
|
|
htmlStr += translate['Select the edit icon to add web links']
|
|
|
|
htmlStr += '\n</center>\n'
|
2020-11-19 21:57:26 +00:00
|
|
|
|
|
|
|
# end of col-left-mobile
|
|
|
|
htmlStr += '</div>\n'
|
|
|
|
|
2021-12-29 21:55:09 +00:00
|
|
|
htmlStr += '</div>\n' + html_footer()
|
2020-11-09 22:44:03 +00:00
|
|
|
return htmlStr
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
defaultTimeline: str, theme: str,
|
|
|
|
accessKeys: {}) -> 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-25 16:17:53 +00:00
|
|
|
cssFilename = base_dir + '/epicyon-links.css'
|
|
|
|
if os.path.isfile(base_dir + '/links.css'):
|
|
|
|
cssFilename = base_dir + '/links.css'
|
2020-11-09 22:44:03 +00:00
|
|
|
|
|
|
|
# filename of the banner shown at the top
|
2020-12-20 17:26:38 +00:00
|
|
|
bannerFile, bannerFilename = \
|
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-01-11 19:46:21 +00:00
|
|
|
instanceTitle = \
|
2021-12-26 14:08:58 +00:00
|
|
|
get_config_param(base_dir, 'instanceTitle')
|
2021-11-07 10:38:11 +00:00
|
|
|
editLinksForm = \
|
2021-12-29 21:55:09 +00:00
|
|
|
html_header_with_external_style(cssFilename, instanceTitle, None)
|
2020-11-09 22:44:03 +00:00
|
|
|
|
|
|
|
# top banner
|
|
|
|
editLinksForm += \
|
2020-12-27 16:57:15 +00:00
|
|
|
'<header>\n' + \
|
2020-11-09 22:44:03 +00:00
|
|
|
'<a href="/users/' + nickname + '/' + defaultTimeline + '" title="' + \
|
|
|
|
translate['Switch to timeline view'] + '" alt="' + \
|
2021-04-23 18:00:11 +00:00
|
|
|
translate['Switch to timeline view'] + '" ' + \
|
|
|
|
'accesskey="' + accessKeys['menuTimeline'] + '">\n'
|
2021-07-05 19:46:55 +00:00
|
|
|
editLinksForm += \
|
|
|
|
'<img loading="lazy" class="timeline-banner" ' + \
|
2021-02-01 19:48:46 +00:00
|
|
|
'alt = "" src="' + \
|
2020-12-27 16:57:15 +00:00
|
|
|
'/users/' + nickname + '/' + bannerFile + '" /></a>\n' + \
|
|
|
|
'</header>\n'
|
2020-11-09 22:44:03 +00:00
|
|
|
|
|
|
|
editLinksForm += \
|
|
|
|
'<form enctype="multipart/form-data" method="POST" ' + \
|
|
|
|
'accept-charset="UTF-8" action="' + path + '/linksdata">\n'
|
|
|
|
editLinksForm += \
|
|
|
|
' <div class="vertical-center">\n'
|
|
|
|
editLinksForm += \
|
2020-12-21 16:07:51 +00:00
|
|
|
' <div class="containerSubmitNewPost">\n'
|
2020-11-09 22:44:03 +00:00
|
|
|
editLinksForm += \
|
2020-12-21 16:24:13 +00:00
|
|
|
' <h1>' + translate['Edit Links'] + '</h1>'
|
2020-12-21 16:01:05 +00:00
|
|
|
editLinksForm += \
|
2020-12-21 16:24:13 +00:00
|
|
|
' <input type="submit" name="submitLinks" value="' + \
|
2021-04-23 18:00:11 +00:00
|
|
|
translate['Submit'] + '" ' + \
|
|
|
|
'accesskey="' + accessKeys['submitButton'] + '">\n'
|
2020-11-09 22:44:03 +00:00
|
|
|
editLinksForm += \
|
|
|
|
' </div>\n'
|
|
|
|
|
2021-12-25 16:17:53 +00:00
|
|
|
linksFilename = base_dir + '/accounts/links.txt'
|
2020-11-09 22:44:03 +00:00
|
|
|
linksStr = ''
|
|
|
|
if os.path.isfile(linksFilename):
|
2021-06-21 22:52:04 +00:00
|
|
|
with open(linksFilename, 'r') as fp:
|
|
|
|
linksStr = fp.read()
|
2020-11-09 22:44:03 +00:00
|
|
|
|
|
|
|
editLinksForm += \
|
|
|
|
'<div class="container">'
|
|
|
|
editLinksForm += \
|
|
|
|
' ' + \
|
|
|
|
translate['One link per line. Description followed by the link.'] + \
|
|
|
|
'<br>'
|
2021-11-30 11:05:54 +00:00
|
|
|
newColLinkStr = translate['New link title and URL']
|
2021-12-29 21:55:09 +00:00
|
|
|
editLinksForm += edit_text_field(None, 'newColLink', '', newColLinkStr)
|
2020-11-09 22:44:03 +00:00
|
|
|
editLinksForm += \
|
2021-02-28 14:26:04 +00:00
|
|
|
' <textarea id="message" name="editedLinks" ' + \
|
2021-07-05 19:46:55 +00:00
|
|
|
'style="height:80vh" spellcheck="false">' + linksStr + '</textarea>'
|
2020-11-09 22:44:03 +00:00
|
|
|
editLinksForm += \
|
|
|
|
'</div>'
|
|
|
|
|
2020-11-10 12:20:46 +00:00
|
|
|
# the admin can edit terms of service and about text
|
2021-12-26 14:08:58 +00:00
|
|
|
adminNickname = get_config_param(base_dir, 'admin')
|
2020-11-10 12:20:46 +00:00
|
|
|
if adminNickname:
|
|
|
|
if nickname == adminNickname:
|
2021-12-25 16:17:53 +00:00
|
|
|
aboutFilename = base_dir + '/accounts/about.md'
|
2020-11-10 12:20:46 +00:00
|
|
|
aboutStr = ''
|
|
|
|
if os.path.isfile(aboutFilename):
|
2021-06-21 22:52:04 +00:00
|
|
|
with open(aboutFilename, 'r') as fp:
|
|
|
|
aboutStr = fp.read()
|
2020-11-10 12:20:46 +00:00
|
|
|
|
|
|
|
editLinksForm += \
|
|
|
|
'<div class="container">'
|
|
|
|
editLinksForm += \
|
|
|
|
' ' + \
|
|
|
|
translate['About this Instance'] + \
|
|
|
|
'<br>'
|
|
|
|
editLinksForm += \
|
|
|
|
' <textarea id="message" name="editedAbout" ' + \
|
2021-02-28 14:48:41 +00:00
|
|
|
'style="height:100vh" spellcheck="true" autocomplete="on">' + \
|
2021-02-28 14:26:04 +00:00
|
|
|
aboutStr + '</textarea>'
|
2020-11-10 12:20:46 +00:00
|
|
|
editLinksForm += \
|
|
|
|
'</div>'
|
|
|
|
|
2021-12-25 16:17:53 +00:00
|
|
|
TOSFilename = base_dir + '/accounts/tos.md'
|
2020-11-10 12:20:46 +00:00
|
|
|
TOSStr = ''
|
|
|
|
if os.path.isfile(TOSFilename):
|
2021-06-21 22:52:04 +00:00
|
|
|
with open(TOSFilename, 'r') as fp:
|
|
|
|
TOSStr = fp.read()
|
2020-11-10 12:20:46 +00:00
|
|
|
|
|
|
|
editLinksForm += \
|
|
|
|
'<div class="container">'
|
|
|
|
editLinksForm += \
|
|
|
|
' ' + \
|
|
|
|
translate['Terms of Service'] + \
|
|
|
|
'<br>'
|
|
|
|
editLinksForm += \
|
|
|
|
' <textarea id="message" name="editedTOS" ' + \
|
2021-02-28 14:48:41 +00:00
|
|
|
'style="height:100vh" spellcheck="true" autocomplete="on">' + \
|
2021-02-28 14:26:04 +00:00
|
|
|
TOSStr + '</textarea>'
|
2020-11-10 12:20:46 +00:00
|
|
|
editLinksForm += \
|
|
|
|
'</div>'
|
|
|
|
|
2021-12-29 21:55:09 +00:00
|
|
|
editLinksForm += html_footer()
|
2020-11-09 22:44:03 +00:00
|
|
|
return editLinksForm
|