2020-11-09 22:44:03 +00:00
|
|
|
__filename__ = "webapp_column_left.py"
|
|
|
|
__author__ = "Bob Mottram"
|
|
|
|
__license__ = "AGPL3+"
|
|
|
|
__version__ = "1.1.0"
|
|
|
|
__maintainer__ = "Bob Mottram"
|
|
|
|
__email__ = "bob@freedombone.net"
|
|
|
|
__status__ = "Production"
|
|
|
|
|
|
|
|
import os
|
|
|
|
from utils import getConfigParam
|
|
|
|
from utils import getNicknameFromActor
|
2020-12-01 21:44:27 +00:00
|
|
|
from utils import isEditor
|
2020-12-06 22:26:39 +00:00
|
|
|
from webapp_utils import sharesTimelineJson
|
2020-11-09 22:44:03 +00:00
|
|
|
from webapp_utils import htmlPostSeparator
|
|
|
|
from webapp_utils import getLeftImageFile
|
|
|
|
from webapp_utils import headerButtonsFrontScreen
|
2020-11-10 16:54:35 +00:00
|
|
|
from webapp_utils import htmlHeaderWithExternalStyle
|
2020-11-09 22:44:03 +00:00
|
|
|
from webapp_utils import htmlFooter
|
|
|
|
from webapp_utils import getBannerFile
|
|
|
|
|
|
|
|
|
2020-11-29 11:31:16 +00:00
|
|
|
def linksExist(baseDir: str) -> bool:
|
|
|
|
"""Returns true if links have been created
|
|
|
|
"""
|
|
|
|
linksFilename = baseDir + '/accounts/links.txt'
|
|
|
|
return os.path.isfile(linksFilename)
|
|
|
|
|
|
|
|
|
2020-12-06 22:26:39 +00:00
|
|
|
def getLeftColumnShares(baseDir: str,
|
|
|
|
httpPrefix: str, domainFull: str,
|
|
|
|
nickname: str,
|
|
|
|
maxSharesInLeftColumn: int,
|
|
|
|
translate: {}) -> []:
|
|
|
|
"""get any shares and turn them into the left column links format
|
|
|
|
"""
|
|
|
|
pageNumber = 1
|
|
|
|
actor = httpPrefix + '://' + domainFull + '/users/' + nickname
|
|
|
|
sharesJson, lastPage = \
|
|
|
|
sharesTimelineJson(actor, pageNumber,
|
|
|
|
maxSharesInLeftColumn,
|
|
|
|
baseDir, maxSharesInLeftColumn)
|
|
|
|
if not sharesJson:
|
|
|
|
return []
|
|
|
|
|
|
|
|
linksList = []
|
|
|
|
ctr = 0
|
|
|
|
for published, item in sharesJson.items():
|
|
|
|
sharedesc = item['displayName']
|
2020-12-06 22:56:45 +00:00
|
|
|
if '<' in sharedesc or '?' in sharedesc:
|
|
|
|
continue
|
2020-12-06 22:26:39 +00:00
|
|
|
contactActor = item['actor']
|
|
|
|
shareLink = actor + \
|
2020-12-06 22:56:45 +00:00
|
|
|
'?replydm=sharedesc:' + \
|
|
|
|
sharedesc.replace(' ', '_') + \
|
2020-12-06 22:26:39 +00:00
|
|
|
'?mention=' + contactActor
|
|
|
|
linksList.append(sharedesc + ' ' + shareLink)
|
|
|
|
ctr += 1
|
|
|
|
if ctr >= maxSharesInLeftColumn:
|
|
|
|
break
|
|
|
|
|
|
|
|
if linksList:
|
|
|
|
linksList = ['* ' + translate['Shares']] + linksList
|
|
|
|
return linksList
|
|
|
|
|
|
|
|
|
2020-11-09 22:44:03 +00:00
|
|
|
def getLeftColumnContent(baseDir: str, nickname: str, domainFull: str,
|
|
|
|
httpPrefix: str, translate: {},
|
2020-12-09 13:31:54 +00:00
|
|
|
editor: bool,
|
2020-11-09 22:44:03 +00:00
|
|
|
showBackButton: bool, timelinePath: str,
|
|
|
|
rssIconAtTop: bool, showHeaderImage: bool,
|
2020-12-20 17:26:38 +00:00
|
|
|
frontPage: bool, theme: str) -> str:
|
2020-11-09 22:44:03 +00:00
|
|
|
"""Returns html content for the left column
|
|
|
|
"""
|
|
|
|
htmlStr = ''
|
|
|
|
|
|
|
|
separatorStr = htmlPostSeparator(baseDir, 'left')
|
|
|
|
domain = domainFull
|
|
|
|
if ':' in domain:
|
|
|
|
domain = domain.split(':')
|
|
|
|
|
|
|
|
editImageClass = ''
|
|
|
|
if showHeaderImage:
|
|
|
|
leftImageFile, leftColumnImageFilename = \
|
2020-12-20 17:26:38 +00:00
|
|
|
getLeftImageFile(baseDir, 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 += \
|
|
|
|
'\n <center>\n' + \
|
|
|
|
' <img class="leftColImg" ' + \
|
|
|
|
'loading="lazy" src="/users/' + \
|
|
|
|
nickname + '/' + leftImageFile + '" />\n' + \
|
|
|
|
' </center>\n'
|
|
|
|
|
|
|
|
if showBackButton:
|
|
|
|
htmlStr += \
|
|
|
|
' <div>' + \
|
|
|
|
' <a href="' + timelinePath + '">' + \
|
|
|
|
'<button class="cancelbtn">' + \
|
|
|
|
translate['Go Back'] + '</button></a>\n'
|
|
|
|
|
|
|
|
if (editor or rssIconAtTop) and not showHeaderImage:
|
|
|
|
htmlStr += '<div class="columnIcons">'
|
|
|
|
|
|
|
|
if editImageClass == 'leftColEdit':
|
|
|
|
htmlStr += '\n <center>\n'
|
|
|
|
|
|
|
|
htmlStr += ' <div class="leftColIcons">\n'
|
|
|
|
if editor:
|
|
|
|
# show the edit icon
|
|
|
|
htmlStr += \
|
|
|
|
' <a href="' + \
|
|
|
|
'/users/' + nickname + '/editlinks">' + \
|
|
|
|
'<img class="' + editImageClass + \
|
|
|
|
'" loading="lazy" alt="' + \
|
|
|
|
translate['Edit Links'] + '" title="' + \
|
|
|
|
translate['Edit Links'] + '" src="/' + \
|
2020-12-09 13:08:26 +00:00
|
|
|
'icons/edit.png" /></a>\n'
|
2020-11-09 22:44:03 +00:00
|
|
|
|
|
|
|
# RSS icon
|
|
|
|
if nickname != 'news':
|
|
|
|
# rss feed for this account
|
|
|
|
rssUrl = httpPrefix + '://' + domainFull + \
|
|
|
|
'/blog/' + nickname + '/rss.xml'
|
|
|
|
else:
|
|
|
|
# rss feed for all accounts on the instance
|
|
|
|
rssUrl = httpPrefix + '://' + domainFull + '/blog/rss.xml'
|
|
|
|
if not frontPage:
|
|
|
|
rssTitle = translate['RSS feed for your blog']
|
|
|
|
else:
|
|
|
|
rssTitle = translate['RSS feed for this site']
|
|
|
|
rssIconStr = \
|
|
|
|
' <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'
|
2020-11-09 22:44:03 +00:00
|
|
|
if rssIconAtTop:
|
|
|
|
htmlStr += rssIconStr
|
|
|
|
htmlStr += ' </div>\n'
|
|
|
|
|
|
|
|
if editImageClass == 'leftColEdit':
|
|
|
|
htmlStr += ' </center>\n'
|
|
|
|
|
|
|
|
if (editor or rssIconAtTop) and not showHeaderImage:
|
|
|
|
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
|
|
|
|
|
2020-11-09 22:44:03 +00:00
|
|
|
linksFilename = baseDir + '/accounts/links.txt'
|
|
|
|
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):
|
|
|
|
with open(linksFilename, "r") as f:
|
|
|
|
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 = \
|
|
|
|
getLeftColumnShares(baseDir,
|
|
|
|
httpPrefix, domainFull, nickname,
|
|
|
|
maxSharesInLeftColumn, translate)
|
|
|
|
if linksList and sharesList:
|
2020-12-06 22:35:25 +00:00
|
|
|
linksList = sharesList + linksList
|
2020-12-06 22:26:39 +00:00
|
|
|
|
|
|
|
if linksList:
|
|
|
|
for lineStr in linksList:
|
|
|
|
if ' ' not in lineStr:
|
|
|
|
if '#' not in lineStr:
|
|
|
|
if '*' not in lineStr:
|
2020-11-09 22:44:03 +00:00
|
|
|
continue
|
2020-12-06 22:26:39 +00:00
|
|
|
lineStr = lineStr.strip()
|
|
|
|
words = lineStr.split(' ')
|
|
|
|
# get the link
|
|
|
|
linkStr = None
|
|
|
|
for word in words:
|
|
|
|
if word == '#':
|
|
|
|
continue
|
|
|
|
if word == '*':
|
|
|
|
continue
|
|
|
|
if '://' in word:
|
|
|
|
linkStr = word
|
|
|
|
break
|
|
|
|
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
|
|
|
|
htmlStr += \
|
2020-12-10 12:06:39 +00:00
|
|
|
' <p><a href="' + linkStr + \
|
2020-12-11 10:14:58 +00:00
|
|
|
'" target="_blank" ' + \
|
|
|
|
'rel="nofollow noopener noreferrer">' + \
|
2020-12-06 22:26:39 +00:00
|
|
|
lineStr + '</a></p>\n'
|
2020-11-09 22:44:03 +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-11-09 22:44:03 +00:00
|
|
|
|
2020-11-15 18:42:37 +00:00
|
|
|
if firstSeparatorAdded:
|
|
|
|
htmlStr += separatorStr
|
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>'
|
|
|
|
|
2020-11-09 22:44:03 +00:00
|
|
|
if linksFileContainsEntries and not rssIconAtTop:
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
def htmlLinksMobile(cssCache: {}, baseDir: str,
|
|
|
|
nickname: str, domainFull: str,
|
|
|
|
httpPrefix: str, translate,
|
|
|
|
timelinePath: str, authorized: bool,
|
|
|
|
rssIconAtTop: bool,
|
|
|
|
iconsAsButtons: bool,
|
2020-12-20 17:26:38 +00:00
|
|
|
defaultTimeline: str,
|
|
|
|
theme: str) -> str:
|
2020-11-09 22:44:03 +00:00
|
|
|
"""Show the left column links within mobile view
|
|
|
|
"""
|
|
|
|
htmlStr = ''
|
|
|
|
|
|
|
|
# the css filename
|
|
|
|
cssFilename = baseDir + '/epicyon-profile.css'
|
|
|
|
if os.path.isfile(baseDir + '/epicyon.css'):
|
|
|
|
cssFilename = baseDir + '/epicyon.css'
|
|
|
|
|
|
|
|
# is the user a site editor?
|
|
|
|
if nickname == 'news':
|
|
|
|
editor = False
|
|
|
|
else:
|
|
|
|
editor = isEditor(baseDir, nickname)
|
|
|
|
|
|
|
|
domain = domainFull
|
|
|
|
if ':' in domain:
|
|
|
|
domain = domain.split(':')[0]
|
|
|
|
|
2020-11-12 15:55:08 +00:00
|
|
|
htmlStr = htmlHeaderWithExternalStyle(cssFilename)
|
2020-12-20 17:26:38 +00:00
|
|
|
bannerFile, bannerFilename = \
|
|
|
|
getBannerFile(baseDir, nickname, domain, theme)
|
2020-11-09 22:44:03 +00:00
|
|
|
htmlStr += \
|
|
|
|
'<a href="/users/' + nickname + '/' + defaultTimeline + '">' + \
|
|
|
|
'<img loading="lazy" class="timeline-banner" ' + \
|
|
|
|
'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>' + \
|
|
|
|
headerButtonsFrontScreen(translate, nickname,
|
|
|
|
'links', authorized,
|
2020-12-09 13:31:54 +00:00
|
|
|
iconsAsButtons) + '</center>'
|
2020-11-29 11:31:16 +00:00
|
|
|
if linksExist(baseDir):
|
|
|
|
htmlStr += \
|
|
|
|
getLeftColumnContent(baseDir, nickname, domainFull,
|
|
|
|
httpPrefix, translate,
|
2020-12-09 13:31:54 +00:00
|
|
|
editor,
|
2020-11-29 11:31:16 +00:00
|
|
|
False, timelinePath,
|
2020-12-20 17:26:38 +00:00
|
|
|
rssIconAtTop, False, False,
|
|
|
|
theme)
|
2020-11-29 11:31:16 +00:00
|
|
|
else:
|
|
|
|
if editor:
|
|
|
|
htmlStr += '<br><br><br>\n'
|
|
|
|
htmlStr += '<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'
|
|
|
|
|
2020-11-09 22:44:03 +00:00
|
|
|
htmlStr += '</div>\n' + htmlFooter()
|
|
|
|
return htmlStr
|
|
|
|
|
|
|
|
|
|
|
|
def htmlEditLinks(cssCache: {}, translate: {}, baseDir: str, path: str,
|
|
|
|
domain: str, port: int, httpPrefix: str,
|
2020-12-20 17:26:38 +00:00
|
|
|
defaultTimeline: str, theme: str) -> 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', '')
|
|
|
|
path = path.replace('/shares', '')
|
|
|
|
|
|
|
|
nickname = getNicknameFromActor(path)
|
|
|
|
if not nickname:
|
|
|
|
return ''
|
|
|
|
|
|
|
|
# is the user a moderator?
|
|
|
|
if not isEditor(baseDir, nickname):
|
|
|
|
return ''
|
|
|
|
|
|
|
|
cssFilename = baseDir + '/epicyon-links.css'
|
|
|
|
if os.path.isfile(baseDir + '/links.css'):
|
|
|
|
cssFilename = baseDir + '/links.css'
|
|
|
|
|
|
|
|
# filename of the banner shown at the top
|
2020-12-20 17:26:38 +00:00
|
|
|
bannerFile, bannerFilename = \
|
|
|
|
getBannerFile(baseDir, nickname, domain, theme)
|
2020-11-09 22:44:03 +00:00
|
|
|
|
2020-11-12 15:55:08 +00:00
|
|
|
editLinksForm = htmlHeaderWithExternalStyle(cssFilename)
|
2020-11-09 22:44:03 +00:00
|
|
|
|
|
|
|
# top banner
|
|
|
|
editLinksForm += \
|
|
|
|
'<a href="/users/' + nickname + '/' + defaultTimeline + '" title="' + \
|
|
|
|
translate['Switch to timeline view'] + '" alt="' + \
|
|
|
|
translate['Switch to timeline view'] + '">\n'
|
|
|
|
editLinksForm += '<img loading="lazy" class="timeline-banner" src="' + \
|
|
|
|
'/users/' + nickname + '/' + bannerFile + '" /></a>\n'
|
|
|
|
|
|
|
|
editLinksForm += \
|
|
|
|
'<form enctype="multipart/form-data" method="POST" ' + \
|
|
|
|
'accept-charset="UTF-8" action="' + path + '/linksdata">\n'
|
|
|
|
editLinksForm += \
|
|
|
|
' <div class="vertical-center">\n'
|
|
|
|
editLinksForm += \
|
2020-11-21 09:44:33 +00:00
|
|
|
' <h1>' + translate['Edit Links'] + '</h1>'
|
2020-11-09 22:44:03 +00:00
|
|
|
editLinksForm += \
|
2020-12-21 16:01:05 +00:00
|
|
|
' <div class="containerNewPost">\n'
|
2020-11-09 22:44:03 +00:00
|
|
|
editLinksForm += \
|
2020-12-21 16:01:05 +00:00
|
|
|
' <table style="width:100%" border="0">\n'
|
|
|
|
editLinksForm += \
|
|
|
|
' <colgroup>\n'
|
|
|
|
editLinksForm += \
|
|
|
|
' <col span="1" style="width:100%">\n'
|
|
|
|
editLinksForm += \
|
|
|
|
' </colgroup>\n'
|
|
|
|
editLinksForm += \
|
|
|
|
' <tr><td>\n'
|
|
|
|
editLinksForm += \
|
|
|
|
' <input type="submit" name="submitLinks" value="' + \
|
2020-12-21 15:09:29 +00:00
|
|
|
translate['Submit'] + '">\n'
|
2020-12-21 16:01:05 +00:00
|
|
|
editLinksForm += \
|
|
|
|
' </td></tr>\n'
|
|
|
|
editLinksForm += \
|
|
|
|
' </table>\n'
|
2020-11-09 22:44:03 +00:00
|
|
|
editLinksForm += \
|
|
|
|
' </div>\n'
|
|
|
|
|
|
|
|
linksFilename = baseDir + '/accounts/links.txt'
|
|
|
|
linksStr = ''
|
|
|
|
if os.path.isfile(linksFilename):
|
|
|
|
with open(linksFilename, 'r') as fp:
|
|
|
|
linksStr = fp.read()
|
|
|
|
|
|
|
|
editLinksForm += \
|
|
|
|
'<div class="container">'
|
|
|
|
editLinksForm += \
|
|
|
|
' ' + \
|
|
|
|
translate['One link per line. Description followed by the link.'] + \
|
|
|
|
'<br>'
|
|
|
|
editLinksForm += \
|
|
|
|
' <textarea id="message" name="editedLinks" style="height:80vh">' + \
|
|
|
|
linksStr + '</textarea>'
|
|
|
|
editLinksForm += \
|
|
|
|
'</div>'
|
|
|
|
|
2020-11-10 12:20:46 +00:00
|
|
|
# the admin can edit terms of service and about text
|
|
|
|
adminNickname = getConfigParam(baseDir, 'admin')
|
|
|
|
if adminNickname:
|
|
|
|
if nickname == adminNickname:
|
|
|
|
aboutFilename = baseDir + '/accounts/about.txt'
|
|
|
|
aboutStr = ''
|
|
|
|
if os.path.isfile(aboutFilename):
|
|
|
|
with open(aboutFilename, 'r') as fp:
|
|
|
|
aboutStr = fp.read()
|
|
|
|
|
|
|
|
editLinksForm += \
|
|
|
|
'<div class="container">'
|
|
|
|
editLinksForm += \
|
|
|
|
' ' + \
|
|
|
|
translate['About this Instance'] + \
|
|
|
|
'<br>'
|
|
|
|
editLinksForm += \
|
|
|
|
' <textarea id="message" name="editedAbout" ' + \
|
|
|
|
'style="height:100vh">' + aboutStr + '</textarea>'
|
|
|
|
editLinksForm += \
|
|
|
|
'</div>'
|
|
|
|
|
|
|
|
TOSFilename = baseDir + '/accounts/tos.txt'
|
|
|
|
TOSStr = ''
|
|
|
|
if os.path.isfile(TOSFilename):
|
|
|
|
with open(TOSFilename, 'r') as fp:
|
|
|
|
TOSStr = fp.read()
|
|
|
|
|
|
|
|
editLinksForm += \
|
|
|
|
'<div class="container">'
|
|
|
|
editLinksForm += \
|
|
|
|
' ' + \
|
|
|
|
translate['Terms of Service'] + \
|
|
|
|
'<br>'
|
|
|
|
editLinksForm += \
|
|
|
|
' <textarea id="message" name="editedTOS" ' + \
|
|
|
|
'style="height:100vh">' + TOSStr + '</textarea>'
|
|
|
|
editLinksForm += \
|
|
|
|
'</div>'
|
|
|
|
|
2020-11-09 22:44:03 +00:00
|
|
|
editLinksForm += htmlFooter()
|
|
|
|
return editLinksForm
|