epicyon/webapp_create_post.py

791 lines
33 KiB
Python
Raw Normal View History

2020-11-09 22:57:12 +00:00
__filename__ = "webapp_create_post.py"
__author__ = "Bob Mottram"
__license__ = "AGPL3+"
2021-01-26 10:07:42 +00:00
__version__ = "1.2.0"
2020-11-09 22:57:12 +00:00
__maintainer__ = "Bob Mottram"
2021-09-10 16:14:50 +00:00
__email__ = "bob@libreserver.org"
2020-11-09 22:57:12 +00:00
__status__ = "Production"
2021-06-15 15:08:12 +00:00
__module_group__ = "Web Interface"
2020-11-09 22:57:12 +00:00
import os
from utils import isPublicPostFromUrl
from utils import getNicknameFromActor
from utils import getDomainFromActor
2020-11-21 11:54:29 +00:00
from utils import getMediaFormats
2021-01-11 19:46:21 +00:00
from utils import getConfigParam
2021-07-13 21:59:53 +00:00
from utils import acctDir
2021-08-07 17:44:25 +00:00
from utils import getCurrencies
from utils import getCategoryTypes
2020-11-09 22:57:12 +00:00
from webapp_utils import getBannerFile
2020-11-10 16:10:47 +00:00
from webapp_utils import htmlHeaderWithExternalStyle
2020-11-09 22:57:12 +00:00
from webapp_utils import htmlFooter
2021-07-22 16:58:59 +00:00
from webapp_utils import editTextField
2021-07-24 11:47:51 +00:00
from webapp_utils import editNumberField
2021-07-24 22:08:11 +00:00
from webapp_utils import editCurrencyField
2020-11-09 22:57:12 +00:00
def _htmlFollowingDataList(baseDir: str, nickname: str,
domain: str, domainFull: str) -> str:
2020-11-09 22:57:12 +00:00
"""Returns a datalist of handles being followed
"""
listStr = '<datalist id="followingHandles">\n'
followingFilename = \
2021-07-13 21:59:53 +00:00
acctDir(baseDir, nickname, domain) + '/following.txt'
2021-07-05 20:24:43 +00:00
msg = None
2020-11-09 22:57:12 +00:00
if os.path.isfile(followingFilename):
with open(followingFilename, 'r') as followingFile:
msg = followingFile.read()
# add your own handle, so that you can send DMs
# to yourself as reminders
msg += nickname + '@' + domainFull + '\n'
2021-07-05 20:24:43 +00:00
if msg:
# include petnames
petnamesFilename = \
2021-07-13 21:59:53 +00:00
acctDir(baseDir, nickname, domain) + '/petnames.txt'
2021-07-05 20:24:43 +00:00
if os.path.isfile(petnamesFilename):
followingList = []
with open(petnamesFilename, 'r') as petnamesFile:
petStr = petnamesFile.read()
# extract each petname and append it
petnamesList = petStr.split('\n')
for pet in petnamesList:
followingList.append(pet.split(' ')[0])
# add the following.txt entries
followingList += msg.split('\n')
else:
# no petnames list exists - just use following.txt
followingList = msg.split('\n')
followingList.sort()
if followingList:
for followingAddress in followingList:
if followingAddress:
listStr += '<option>@' + followingAddress + '</option>\n'
2020-11-09 22:57:12 +00:00
listStr += '</datalist>\n'
return listStr
def _htmlNewPostDropDown(scopeIcon: str, scopeDescription: str,
replyStr: str,
translate: {},
showPublicOnDropdown: bool,
defaultTimeline: str,
pathBase: str,
dropdownNewPostSuffix: str,
dropdownNewBlogSuffix: str,
dropdownUnlistedSuffix: str,
dropdownFollowersSuffix: str,
dropdownDMSuffix: str,
dropdownReminderSuffix: str,
dropdownReportSuffix: str,
2021-04-23 17:23:12 +00:00
noDropDown: bool,
accessKeys: {}) -> str:
2020-11-09 22:57:12 +00:00
"""Returns the html for a drop down list of new post types
"""
2020-12-27 21:29:04 +00:00
dropDownContent = '<nav><div class="newPostDropdown">\n'
2021-02-05 12:22:23 +00:00
if not noDropDown:
dropDownContent += ' <input type="checkbox" ' + \
'id="my-newPostDropdown" value="" name="my-checkbox">\n'
2020-11-09 22:57:12 +00:00
dropDownContent += ' <label for="my-newPostDropdown"\n'
dropDownContent += ' data-toggle="newPostDropdown">\n'
dropDownContent += ' <img loading="lazy" alt="" title="" src="/' + \
2021-07-05 20:24:43 +00:00
'icons/' + scopeIcon + '"/><b>' + scopeDescription + '</b></label>\n'
2020-11-09 22:57:12 +00:00
if noDropDown:
dropDownContent += '</div></nav>\n'
return dropDownContent
dropDownContent += ' <ul>\n'
2020-11-09 22:57:12 +00:00
if showPublicOnDropdown:
dropDownContent += \
'<li><a href="' + pathBase + dropdownNewPostSuffix + \
2021-04-23 17:23:12 +00:00
'" accesskey="' + accessKeys['Public'] + '">' + \
'<img loading="lazy" alt="" title="" src="/' + \
2020-12-09 13:08:26 +00:00
'icons/scope_public.png"/><b>' + \
2020-11-09 22:57:12 +00:00
translate['Public'] + '</b><br>' + \
translate['Visible to anyone'] + '</a></li>\n'
2020-11-27 13:03:17 +00:00
if defaultTimeline == 'tlfeatures':
2020-11-09 22:57:12 +00:00
dropDownContent += \
'<li><a href="' + pathBase + dropdownNewBlogSuffix + \
2021-04-23 17:23:12 +00:00
'" accesskey="' + accessKeys['menuBlogs'] + '">' + \
'<img loading="lazy" alt="" title="" src="/' + \
2020-12-09 13:08:26 +00:00
'icons/scope_blog.png"/><b>' + \
2020-11-09 22:57:12 +00:00
translate['Article'] + '</b><br>' + \
translate['Create an article'] + '</a></li>\n'
else:
dropDownContent += \
'<li><a href="' + pathBase + dropdownNewBlogSuffix + \
2021-04-23 17:23:12 +00:00
'" accesskey="' + accessKeys['menuBlogs'] + '">' + \
'<img loading="lazy" alt="" title="" src="/' + \
2020-12-09 13:08:26 +00:00
'icons/scope_blog.png"/><b>' + \
2020-11-09 22:57:12 +00:00
translate['Blog'] + '</b><br>' + \
translate['Publicly visible post'] + '</a></li>\n'
dropDownContent += \
'<li><a href="' + pathBase + dropdownUnlistedSuffix + \
'"><img loading="lazy" alt="" title="" src="/' + \
2020-12-09 13:08:26 +00:00
'icons/scope_unlisted.png"/><b>' + \
2020-11-09 22:57:12 +00:00
translate['Unlisted'] + '</b><br>' + \
translate['Not on public timeline'] + '</a></li>\n'
dropDownContent += \
'<li><a href="' + pathBase + dropdownFollowersSuffix + \
2021-04-23 17:23:12 +00:00
'" accesskey="' + accessKeys['menuFollowers'] + '">' + \
'<img loading="lazy" alt="" title="" src="/' + \
2020-12-09 13:08:26 +00:00
'icons/scope_followers.png"/><b>' + \
2020-11-09 22:57:12 +00:00
translate['Followers'] + '</b><br>' + \
translate['Only to followers'] + '</a></li>\n'
dropDownContent += \
'<li><a href="' + pathBase + dropdownDMSuffix + \
2021-04-23 17:23:12 +00:00
'" accesskey="' + accessKeys['menuDM'] + '">' + \
'<img loading="lazy" alt="" title="" src="/' + \
2020-12-09 13:08:26 +00:00
'icons/scope_dm.png"/><b>' + \
2020-11-09 22:57:12 +00:00
translate['DM'] + '</b><br>' + \
translate['Only to mentioned people'] + '</a></li>\n'
dropDownContent += \
'<li><a href="' + pathBase + dropdownReminderSuffix + \
2021-04-23 17:23:12 +00:00
'" accesskey="' + accessKeys['Reminder'] + '">' + \
'<img loading="lazy" alt="" title="" src="/' + \
2020-12-09 13:08:26 +00:00
'icons/scope_reminder.png"/><b>' + \
2020-11-09 22:57:12 +00:00
translate['Reminder'] + '</b><br>' + \
translate['Scheduled note to yourself'] + '</a></li>\n'
dropDownContent += \
'<li><a href="' + pathBase + dropdownReportSuffix + \
2021-04-23 17:23:12 +00:00
'" accesskey="' + accessKeys['reportButton'] + '">' + \
'<img loading="lazy" alt="" title="" src="/' + \
2020-12-09 13:08:26 +00:00
'icons/scope_report.png"/><b>' + \
2020-11-09 22:57:12 +00:00
translate['Report'] + '</b><br>' + \
translate['Send to moderators'] + '</a></li>\n'
if not replyStr:
dropDownContent += \
'<li><a href="' + pathBase + \
2021-04-23 17:23:12 +00:00
'/newshare" accesskey="' + accessKeys['menuShares'] + '">' + \
'<img loading="lazy" alt="" title="" src="/' + \
2020-12-09 13:08:26 +00:00
'icons/scope_share.png"/><b>' + \
2020-11-09 22:57:12 +00:00
translate['Shares'] + '</b><br>' + \
translate['Describe a shared item'] + '</a></li>\n'
2021-08-09 18:41:05 +00:00
dropDownContent += \
'<li><a href="' + pathBase + \
'/newwanted" accesskey="' + accessKeys['menuWanted'] + '">' + \
'<img loading="lazy" alt="" title="" src="/' + \
'icons/scope_wanted.png"/><b>' + \
translate['Wanted'] + '</b><br>' + \
translate['Describe something wanted'] + '</a></li>\n'
2020-11-09 22:57:12 +00:00
dropDownContent += \
'<li><a href="' + pathBase + \
'/newquestion"><img loading="lazy" alt="" title="" src="/' + \
2020-12-09 13:08:26 +00:00
'icons/scope_question.png"/><b>' + \
2020-11-09 22:57:12 +00:00
translate['Question'] + '</b><br>' + \
translate['Ask a question'] + '</a></li>\n'
dropDownContent += ' </ul>\n'
2020-12-27 21:29:04 +00:00
dropDownContent += '</div></nav>\n'
2020-11-09 22:57:12 +00:00
return dropDownContent
def htmlNewPost(cssCache: {}, mediaInstance: bool, translate: {},
baseDir: str, httpPrefix: str,
path: str, inReplyTo: str,
mentions: [],
2020-12-07 10:39:45 +00:00
shareDescription: str,
2020-11-09 22:57:12 +00:00
reportUrl: str, pageNumber: int,
category: str,
2020-11-09 22:57:12 +00:00
nickname: str, domain: str,
domainFull: str,
2020-12-20 18:16:53 +00:00
defaultTimeline: str, newswire: {},
2021-04-23 17:04:37 +00:00
theme: str, noDropDown: bool,
2021-08-08 16:52:32 +00:00
accessKeys: {}, customSubmitText: str,
conversationId: str) -> str:
2020-11-09 22:57:12 +00:00
"""New post screen
"""
replyStr = ''
showPublicOnDropdown = True
messageBoxHeight = 400
# filename of the banner shown at the top
2020-12-20 18:16:53 +00:00
bannerFile, bannerFilename = \
getBannerFile(baseDir, nickname, domain, theme)
2020-11-09 22:57:12 +00:00
2021-08-09 18:41:05 +00:00
if not path.endswith('/newshare') and not path.endswith('/newwanted'):
2020-11-09 22:57:12 +00:00
if not path.endswith('/newreport'):
2020-12-07 10:56:17 +00:00
if not inReplyTo or path.endswith('/newreminder'):
newPostText = '<h1>' + \
2020-12-07 11:03:14 +00:00
translate['Write your post text below.'] + '</h1>\n'
2020-11-09 22:57:12 +00:00
else:
newPostText = ''
if category != 'accommodation':
newPostText = \
'<p class="new-post-text">' + \
translate['Write your reply to'] + \
' <a href="' + inReplyTo + \
'" rel="nofollow noopener noreferrer" ' + \
'target="_blank">' + \
translate['this post'] + '</a></p>\n'
2020-11-09 22:57:12 +00:00
replyStr = '<input type="hidden" ' + \
'name="replyTo" value="' + inReplyTo + '">\n'
# if replying to a non-public post then also make
# this post non-public
if not isPublicPostFromUrl(baseDir, nickname, domain,
inReplyTo):
newPostPath = path
if '?' in newPostPath:
newPostPath = newPostPath.split('?')[0]
if newPostPath.endswith('/newpost'):
path = path.replace('/newpost', '/newfollowers')
elif newPostPath.endswith('/newunlisted'):
path = path.replace('/newunlisted', '/newfollowers')
showPublicOnDropdown = False
else:
newPostText = \
2021-07-05 20:24:43 +00:00
'<h1>' + translate['Write your report below.'] + '</h1>\n'
2020-11-09 22:57:12 +00:00
# custom report header with any additional instructions
if os.path.isfile(baseDir + '/accounts/report.txt'):
with open(baseDir + '/accounts/report.txt', 'r') as file:
customReportText = file.read()
if '</p>' not in customReportText:
customReportText = \
'<p class="login-subtext">' + \
customReportText + '</p>\n'
repStr = '<p class="login-subtext">'
customReportText = \
customReportText.replace('<p>', repStr)
newPostText += customReportText
idx = 'This message only goes to moderators, even if it ' + \
'mentions other fediverse addresses.'
newPostText += \
'<p class="new-post-subtext">' + translate[idx] + '</p>\n' + \
'<p class="new-post-subtext">' + translate['Also see'] + \
' <a href="/terms">' + \
translate['Terms of Service'] + '</a></p>\n'
else:
2021-08-09 18:41:05 +00:00
if path.endswith('/newshare'):
newPostText = \
'<h1>' + \
translate['Enter the details for your shared item below.'] + \
'</h1>\n'
else:
newPostText = \
'<h1>' + \
translate['Enter the details for your wanted item below.'] + \
'</h1>\n'
2020-11-09 22:57:12 +00:00
if path.endswith('/newquestion'):
newPostText = \
2020-11-21 09:56:45 +00:00
'<h1>' + \
2020-11-09 22:57:12 +00:00
translate['Enter the choices for your question below.'] + \
2020-11-21 09:56:45 +00:00
'</h1>\n'
2020-11-09 22:57:12 +00:00
if os.path.isfile(baseDir + '/accounts/newpost.txt'):
with open(baseDir + '/accounts/newpost.txt', 'r') as file:
newPostText = \
2020-11-21 09:56:45 +00:00
'<p>' + file.read() + '</p>\n'
2020-11-09 22:57:12 +00:00
cssFilename = baseDir + '/epicyon-profile.css'
if os.path.isfile(baseDir + '/epicyon.css'):
cssFilename = baseDir + '/epicyon.css'
if '?' in path:
path = path.split('?')[0]
pathBase = path.replace('/newreport', '').replace('/newpost', '')
pathBase = pathBase.replace('/newblog', '').replace('/newshare', '')
2021-08-09 18:41:05 +00:00
pathBase = pathBase.replace('/newunlisted', '').replace('/newwanted', '')
2020-11-09 22:57:12 +00:00
pathBase = pathBase.replace('/newreminder', '')
pathBase = pathBase.replace('/newfollowers', '').replace('/newdm', '')
newPostImageSection = ' <div class="container">'
newPostImageSection += \
2021-07-22 16:58:59 +00:00
editTextField(translate['Image description'], 'imageDescription', '')
2020-11-09 22:57:12 +00:00
2021-07-24 10:13:40 +00:00
newPostImageSection += \
' <input type="file" id="attachpic" name="attachpic"'
formatsString = getMediaFormats()
# remove svg as a permitted format
formatsString = formatsString.replace(', .svg', '').replace('.svg, ', '')
2021-07-24 10:13:40 +00:00
newPostImageSection += \
' accept="' + formatsString + '">\n'
2020-11-09 22:57:12 +00:00
newPostImageSection += ' </div>\n'
scopeIcon = 'scope_public.png'
scopeDescription = translate['Public']
2020-12-07 11:03:14 +00:00
if shareDescription:
if category == 'accommodation':
placeholderSubject = translate['Request to stay']
else:
placeholderSubject = translate['Ask about a shared item.'] + '..'
2020-12-07 11:03:14 +00:00
else:
placeholderSubject = \
translate['Subject or Content Warning (optional)'] + '...'
2020-11-09 22:57:12 +00:00
placeholderMentions = ''
if inReplyTo:
placeholderMentions = \
translate['Replying to'] + '...'
placeholderMessage = ''
if category != 'accommodation':
placeholderMessage = translate['Write something'] + '...'
2021-09-19 17:32:22 +00:00
else:
idx = 'Introduce yourself and specify the date ' + \
'and time when you wish to stay'
placeholderMessage = translate[idx]
2020-11-09 22:57:12 +00:00
extraFields = ''
endpoint = 'newpost'
if path.endswith('/newblog'):
placeholderSubject = translate['Title']
scopeIcon = 'scope_blog.png'
2020-11-27 13:03:17 +00:00
if defaultTimeline != 'tlfeatures':
2020-11-09 22:57:12 +00:00
scopeDescription = translate['Blog']
else:
scopeDescription = translate['Article']
endpoint = 'newblog'
elif path.endswith('/newunlisted'):
scopeIcon = 'scope_unlisted.png'
scopeDescription = translate['Unlisted']
endpoint = 'newunlisted'
elif path.endswith('/newfollowers'):
scopeIcon = 'scope_followers.png'
scopeDescription = translate['Followers']
endpoint = 'newfollowers'
elif path.endswith('/newdm'):
scopeIcon = 'scope_dm.png'
scopeDescription = translate['DM']
endpoint = 'newdm'
elif path.endswith('/newreminder'):
scopeIcon = 'scope_reminder.png'
scopeDescription = translate['Reminder']
endpoint = 'newreminder'
elif path.endswith('/newreport'):
scopeIcon = 'scope_report.png'
scopeDescription = translate['Report']
endpoint = 'newreport'
elif path.endswith('/newquestion'):
scopeIcon = 'scope_question.png'
scopeDescription = translate['Question']
placeholderMessage = translate['Enter your question'] + '...'
endpoint = 'newquestion'
extraFields = '<div class="container">\n'
extraFields += ' <label class="labels">' + \
translate['Possible answers'] + ':</label><br>\n'
for questionCtr in range(8):
extraFields += \
' <input type="text" class="questionOption" placeholder="' + \
str(questionCtr + 1) + \
'" name="questionOption' + str(questionCtr) + '"><br>\n'
extraFields += \
' <label class="labels">' + \
translate['Duration of listing in days'] + \
':</label> <input type="number" name="duration" ' + \
'min="1" max="365" step="1" value="14"><br>\n'
extraFields += '</div>'
elif path.endswith('/newshare'):
scopeIcon = 'scope_share.png'
scopeDescription = translate['Shared Item']
placeholderSubject = translate['Name of the shared item'] + '...'
placeholderMessage = \
translate['Description of the item being shared'] + '...'
endpoint = 'newshare'
extraFields = '<div class="container">\n'
2021-07-24 11:47:51 +00:00
extraFields += \
editNumberField(translate['Quantity'],
'itemQty', 1, 1, 999999, 1)
2021-07-24 11:58:01 +00:00
extraFields += '<br>' + \
2021-07-22 16:58:59 +00:00
editTextField(translate['Type of shared item. eg. hat'] + ':',
2021-07-27 18:31:50 +00:00
'itemType', '', '', True)
2021-08-08 18:51:36 +00:00
categoryTypes = getCategoryTypes(baseDir)
2021-08-05 19:24:06 +00:00
catStr = translate['Category of shared item. eg. clothing']
extraFields += '<label class="labels">' + catStr + '</label><br>\n'
2021-08-07 17:44:25 +00:00
2021-08-05 19:17:32 +00:00
extraFields += ' <select id="themeDropdown" ' + \
2021-08-07 17:55:49 +00:00
'name="category" class="theme">\n'
2021-08-05 19:15:48 +00:00
for category in categoryTypes:
translatedCategory = "food"
if translate.get(category):
translatedCategory = translate[category]
2021-08-05 19:19:00 +00:00
extraFields += ' <option value="' + \
2021-08-05 19:25:31 +00:00
translatedCategory + '">' + \
2021-08-07 17:54:11 +00:00
translatedCategory + '</option>\n'
2021-08-07 17:44:25 +00:00
2021-08-07 17:54:11 +00:00
extraFields += ' </select><br>\n'
2020-11-09 22:57:12 +00:00
extraFields += \
2021-07-24 11:47:51 +00:00
editNumberField(translate['Duration of listing in days'],
'duration', 14, 1, 365, 1)
2020-11-09 22:57:12 +00:00
extraFields += '</div>\n'
extraFields += '<div class="container">\n'
2021-07-22 16:58:59 +00:00
cityOrLocStr = translate['City or location of the shared item']
extraFields += editTextField(cityOrLocStr + ':', 'location', '')
2020-11-09 22:57:12 +00:00
extraFields += '</div>\n'
2021-07-24 22:08:11 +00:00
extraFields += '<div class="container">\n'
extraFields += \
2021-07-27 18:56:51 +00:00
editCurrencyField(translate['Price'] + ':', 'itemPrice', '0.00',
'0.00', True)
2021-08-07 17:44:25 +00:00
extraFields += '<br>'
extraFields += \
'<label class="labels">' + translate['Currency'] + '</label><br>\n'
currencies = getCurrencies()
extraFields += ' <select id="themeDropdown" ' + \
2021-08-07 17:55:49 +00:00
'name="itemCurrency" class="theme">\n'
2021-08-07 17:48:13 +00:00
currencyList = []
2021-08-07 17:44:25 +00:00
for symbol, currName in currencies.items():
2021-08-07 17:48:13 +00:00
currencyList.append(currName + ' ' + symbol)
currencyList.sort()
2021-08-07 18:07:08 +00:00
defaultCurrency = getConfigParam(baseDir, 'defaultCurrency')
if not defaultCurrency:
defaultCurrency = "EUR"
2021-08-07 17:48:13 +00:00
for currName in currencyList:
2021-08-07 18:07:08 +00:00
if defaultCurrency not in currName:
extraFields += ' <option value="' + \
currName + '">' + currName + '</option>\n'
else:
extraFields += ' <option value="' + \
2021-08-07 18:13:20 +00:00
currName + '" selected="selected">' + \
currName + '</option>\n'
2021-08-07 17:50:17 +00:00
extraFields += ' </select>\n'
2021-08-07 17:44:25 +00:00
2021-08-09 18:41:05 +00:00
extraFields += '</div>\n'
elif path.endswith('/newwanted'):
scopeIcon = 'scope_wanted.png'
scopeDescription = translate['Wanted']
placeholderSubject = translate['Name of the wanted item'] + '...'
placeholderMessage = \
translate['Description of the item wanted'] + '...'
endpoint = 'newwanted'
extraFields = '<div class="container">\n'
extraFields += \
editNumberField(translate['Quantity'],
'itemQty', 1, 1, 999999, 1)
extraFields += '<br>' + \
editTextField(translate['Type of wanted item. eg. hat'] + ':',
'itemType', '', '', True)
categoryTypes = getCategoryTypes(baseDir)
catStr = translate['Category of wanted item. eg. clothes']
extraFields += '<label class="labels">' + catStr + '</label><br>\n'
extraFields += ' <select id="themeDropdown" ' + \
'name="category" class="theme">\n'
for category in categoryTypes:
translatedCategory = "food"
if translate.get(category):
translatedCategory = translate[category]
extraFields += ' <option value="' + \
translatedCategory + '">' + \
translatedCategory + '</option>\n'
extraFields += ' </select><br>\n'
extraFields += \
editNumberField(translate['Duration of listing in days'],
'duration', 14, 1, 365, 1)
extraFields += '</div>\n'
extraFields += '<div class="container">\n'
cityOrLocStr = translate['City or location of the wanted item']
extraFields += editTextField(cityOrLocStr + ':', 'location', '')
extraFields += '</div>\n'
extraFields += '<div class="container">\n'
extraFields += \
editCurrencyField(translate['Maximum Price'] + ':',
'itemPrice', '0.00', '0.00', True)
extraFields += '<br>'
extraFields += \
'<label class="labels">' + translate['Currency'] + '</label><br>\n'
currencies = getCurrencies()
extraFields += ' <select id="themeDropdown" ' + \
'name="itemCurrency" class="theme">\n'
currencyList = []
for symbol, currName in currencies.items():
currencyList.append(currName + ' ' + symbol)
currencyList.sort()
defaultCurrency = getConfigParam(baseDir, 'defaultCurrency')
if not defaultCurrency:
defaultCurrency = "EUR"
for currName in currencyList:
if defaultCurrency not in currName:
extraFields += ' <option value="' + \
currName + '">' + currName + '</option>\n'
else:
extraFields += ' <option value="' + \
currName + '" selected="selected">' + \
currName + '</option>\n'
extraFields += ' </select>\n'
2021-07-24 22:08:11 +00:00
extraFields += '</div>\n'
2020-11-09 22:57:12 +00:00
citationsStr = ''
if endpoint == 'newblog':
citationsFilename = \
2021-07-13 21:59:53 +00:00
acctDir(baseDir, nickname, domain) + '/.citations.txt'
2020-11-09 22:57:12 +00:00
if os.path.isfile(citationsFilename):
citationsStr = '<div class="container">\n'
citationsStr += '<p><label class="labels">' + \
translate['Citations'] + ':</label></p>\n'
citationsStr += ' <ul>\n'
citationsSeparator = '#####'
2021-07-13 14:40:49 +00:00
with open(citationsFilename, 'r') as f:
2020-11-09 22:57:12 +00:00
citations = f.readlines()
for line in citations:
if citationsSeparator not in line:
continue
sections = line.strip().split(citationsSeparator)
if len(sections) != 3:
continue
title = sections[1]
link = sections[2]
citationsStr += \
' <li><a href="' + link + '"><cite>' + \
title + '</cite></a></li>'
citationsStr += ' </ul>\n'
citationsStr += '</div>\n'
dateAndLocation = ''
if endpoint != 'newshare' and \
2021-08-09 18:41:05 +00:00
endpoint != 'newwanted' and \
2020-11-09 22:57:12 +00:00
endpoint != 'newreport' and \
endpoint != 'newquestion':
2021-09-19 16:57:17 +00:00
dateAndLocation = \
'<div class="container">\n'
if category != 'accommodation':
2021-09-19 16:57:17 +00:00
dateAndLocation += \
'<p><input type="checkbox" class="profilecheckbox" ' + \
'name="commentsEnabled" checked><label class="labels"> ' + \
translate['Allow replies.'] + '</label></p>\n'
else:
2021-09-19 16:57:17 +00:00
dateAndLocation += \
'<input type="hidden" name="commentsEnabled" value="true">\n'
2020-11-09 22:57:12 +00:00
2021-01-24 18:09:21 +00:00
if endpoint == 'newpost':
dateAndLocation += \
'<p><input type="checkbox" class="profilecheckbox" ' + \
2021-01-24 18:14:36 +00:00
'name="pinToProfile"><label class="labels"> ' + \
2021-01-24 18:09:21 +00:00
translate['Pin this post to your profile.'] + '</label></p>\n'
2021-07-24 10:13:40 +00:00
if not inReplyTo:
2020-11-09 22:57:12 +00:00
dateAndLocation += \
'<p><input type="checkbox" class="profilecheckbox" ' + \
'name="schedulePost"><label class="labels"> ' + \
translate['This is a scheduled post.'] + '</label></p>\n'
2021-07-24 10:13:40 +00:00
dateAndLocation += \
'<p><img loading="lazy" alt="" title="" ' + \
'class="emojicalendar" src="/' + \
'icons/calendar.png"/>\n'
# select a date and time for this post
dateAndLocation += '<label class="labels">' + \
translate['Date'] + ': </label>\n'
dateAndLocation += '<input type="date" name="eventDate">\n'
dateAndLocation += '<label class="labelsright">' + \
translate['Time'] + ':'
dateAndLocation += \
'<input type="time" name="eventTime"></label></p>\n'
2020-11-09 22:57:12 +00:00
dateAndLocation += '</div>\n'
dateAndLocation += '<div class="container">\n'
2021-07-22 16:58:59 +00:00
dateAndLocation += \
editTextField(translate['Location'], 'location', '')
2020-11-09 22:57:12 +00:00
dateAndLocation += '</div>\n'
2021-07-05 20:24:43 +00:00
instanceTitle = getConfigParam(baseDir, 'instanceTitle')
2021-01-11 19:46:21 +00:00
newPostForm = htmlHeaderWithExternalStyle(cssFilename, instanceTitle)
2020-11-09 22:57:12 +00:00
newPostForm += \
2020-12-27 16:57:15 +00:00
'<header>\n' + \
2020-11-09 22:57:12 +00:00
'<a href="/users/' + nickname + '/' + defaultTimeline + '" title="' + \
translate['Switch to timeline view'] + '" alt="' + \
2021-04-23 17:04:37 +00:00
translate['Switch to timeline view'] + '" ' + \
'accesskey="' + accessKeys['menuTimeline'] + '">\n'
2020-11-09 22:57:12 +00:00
newPostForm += '<img loading="lazy" class="timeline-banner" src="' + \
2021-02-01 20:41:59 +00:00
'/users/' + nickname + '/' + bannerFile + '" alt="" /></a>\n' + \
2020-12-27 16:57:15 +00:00
'</header>\n'
2020-11-09 22:57:12 +00:00
mentionsStr = ''
for m in mentions:
mentionNickname = getNicknameFromActor(m)
if not mentionNickname:
continue
mentionDomain, mentionPort = getDomainFromActor(m)
if not mentionDomain:
continue
if mentionPort:
mentionsHandle = \
'@' + mentionNickname + '@' + \
mentionDomain + ':' + str(mentionPort)
else:
mentionsHandle = '@' + mentionNickname + '@' + mentionDomain
if mentionsHandle not in mentionsStr:
mentionsStr += mentionsHandle + ' '
# build suffixes so that any replies or mentions are
# preserved when switching between scopes
dropdownNewPostSuffix = '/newpost'
dropdownNewBlogSuffix = '/newblog'
dropdownUnlistedSuffix = '/newunlisted'
dropdownFollowersSuffix = '/newfollowers'
dropdownDMSuffix = '/newdm'
dropdownReminderSuffix = '/newreminder'
dropdownReportSuffix = '/newreport'
if inReplyTo or mentions:
dropdownNewPostSuffix = ''
dropdownNewBlogSuffix = ''
dropdownUnlistedSuffix = ''
dropdownFollowersSuffix = ''
dropdownDMSuffix = ''
dropdownReminderSuffix = ''
dropdownReportSuffix = ''
if inReplyTo:
dropdownNewPostSuffix += '?replyto=' + inReplyTo
dropdownNewBlogSuffix += '?replyto=' + inReplyTo
dropdownUnlistedSuffix += '?replyto=' + inReplyTo
dropdownFollowersSuffix += '?replyfollowers=' + inReplyTo
dropdownDMSuffix += '?replydm=' + inReplyTo
for mentionedActor in mentions:
dropdownNewPostSuffix += '?mention=' + mentionedActor
dropdownNewBlogSuffix += '?mention=' + mentionedActor
dropdownUnlistedSuffix += '?mention=' + mentionedActor
dropdownFollowersSuffix += '?mention=' + mentionedActor
dropdownDMSuffix += '?mention=' + mentionedActor
dropdownReportSuffix += '?mention=' + mentionedActor
2021-08-08 16:52:32 +00:00
if conversationId and inReplyTo:
dropdownNewPostSuffix += '?conversationId=' + conversationId
dropdownNewBlogSuffix += '?conversationId=' + conversationId
dropdownUnlistedSuffix += '?conversationId=' + conversationId
dropdownFollowersSuffix += '?conversationId=' + conversationId
dropdownDMSuffix += '?conversationId=' + conversationId
2020-11-09 22:57:12 +00:00
dropDownContent = ''
2020-12-07 10:39:45 +00:00
if not reportUrl and not shareDescription:
2020-11-09 22:57:12 +00:00
dropDownContent = \
_htmlNewPostDropDown(scopeIcon, scopeDescription,
replyStr,
translate,
showPublicOnDropdown,
defaultTimeline,
pathBase,
dropdownNewPostSuffix,
dropdownNewBlogSuffix,
dropdownUnlistedSuffix,
dropdownFollowersSuffix,
dropdownDMSuffix,
dropdownReminderSuffix,
dropdownReportSuffix,
2021-04-23 17:23:12 +00:00
noDropDown, accessKeys)
2020-11-09 22:57:12 +00:00
else:
2020-12-07 10:39:45 +00:00
if not shareDescription:
# reporting a post to moderator
mentionsStr = 'Re: ' + reportUrl + '\n\n' + mentionsStr
2020-11-09 22:57:12 +00:00
newPostForm += \
'<form enctype="multipart/form-data" method="POST" ' + \
'accept-charset="UTF-8" action="' + \
path + '?' + endpoint + '?page=' + str(pageNumber) + '">\n'
2021-08-08 16:52:32 +00:00
if conversationId:
newPostForm += \
' <input type="hidden" name="conversationId" value="' + \
2021-08-08 17:00:15 +00:00
conversationId + '">\n'
2020-11-09 22:57:12 +00:00
newPostForm += ' <div class="vertical-center">\n'
newPostForm += \
' <label for="nickname"><b>' + newPostText + '</b></label>\n'
newPostForm += ' <div class="containerNewPost">\n'
2020-12-21 14:55:24 +00:00
newPostForm += ' <table style="width:100%" border="0">\n'
newPostForm += ' <colgroup>\n'
2020-12-21 15:04:21 +00:00
newPostForm += ' <col span="1" style="width:70%">\n'
2020-12-21 14:55:24 +00:00
newPostForm += ' <col span="1" style="width:10%">\n'
if newswire and path.endswith('/newblog'):
2020-12-21 15:04:21 +00:00
newPostForm += ' <col span="1" style="width:10%">\n'
newPostForm += ' <col span="1" style="width:10%">\n'
2020-12-21 14:55:24 +00:00
else:
2020-12-21 15:04:21 +00:00
newPostForm += ' <col span="1" style="width:20%">\n'
2020-12-21 14:55:24 +00:00
newPostForm += ' </colgroup>\n'
newPostForm += '<tr>\n'
2020-11-09 22:57:12 +00:00
newPostForm += '<td>' + dropDownContent + '</td>\n'
newPostForm += \
' <td><a href="' + pathBase + \
'/searchemoji"><img loading="lazy" class="emojisearch" ' + \
'src="/emoji/1F601.png" title="' + \
translate['Search for emoji'] + '" alt="' + \
translate['Search for emoji'] + '"/></a></td>\n'
2020-12-21 14:44:56 +00:00
# for a new blog if newswire items exist then add a citations button
if newswire and path.endswith('/newblog'):
newPostForm += \
' <td><input type="submit" name="submitCitations" value="' + \
translate['Citations'] + '"></td>\n'
2021-05-30 17:38:41 +00:00
submitText = translate['Submit']
if customSubmitText:
submitText = customSubmitText
2020-12-21 14:44:56 +00:00
newPostForm += \
' <td><input type="submit" name="submitPost" value="' + \
2021-05-30 17:38:41 +00:00
submitText + '" ' + \
2021-04-23 17:04:37 +00:00
'accesskey="' + accessKeys['submitButton'] + '"></td>\n'
2020-12-21 14:44:56 +00:00
2021-07-05 20:24:43 +00:00
newPostForm += ' </tr>\n</table>\n'
2020-11-09 22:57:12 +00:00
newPostForm += ' </div>\n'
newPostForm += ' <div class="containerSubmitNewPost"><center>\n'
newPostForm += ' </center></div>\n'
newPostForm += replyStr
if mediaInstance and not replyStr:
newPostForm += newPostImageSection
2020-12-07 10:39:45 +00:00
if not shareDescription:
shareDescription = ''
newPostForm += \
2021-07-22 16:58:59 +00:00
editTextField(placeholderSubject, 'subject', shareDescription)
2020-11-09 22:57:12 +00:00
newPostForm += ''
selectedStr = ' selected'
if inReplyTo or endpoint == 'newdm':
if inReplyTo:
newPostForm += \
' <label class="labels">' + placeholderMentions + \
'</label><br>\n'
else:
newPostForm += \
' <a href="/users/' + nickname + \
'/followingaccounts" title="' + \
translate['Show a list of addresses to send to'] + '">' \
'<label class="labels">' + \
translate['Send to'] + ':' + '</label> 📄</a><br>\n'
newPostForm += \
' <input type="text" name="mentions" ' + \
'list="followingHandles" value="' + mentionsStr + '" selected>\n'
newPostForm += \
_htmlFollowingDataList(baseDir, nickname, domain, domainFull)
2020-11-09 22:57:12 +00:00
newPostForm += ''
selectedStr = ''
newPostForm += \
' <br><label class="labels">' + placeholderMessage + '</label>'
if mediaInstance:
messageBoxHeight = 200
if endpoint == 'newquestion':
messageBoxHeight = 100
elif endpoint == 'newblog':
messageBoxHeight = 800
newPostForm += \
' <textarea id="message" name="message" style="height:' + \
2021-02-28 14:48:41 +00:00
str(messageBoxHeight) + 'px"' + selectedStr + \
' spellcheck="true" autocomplete="on">' + \
2021-02-28 13:44:16 +00:00
'</textarea>\n'
2020-11-09 22:57:12 +00:00
newPostForm += extraFields + citationsStr + dateAndLocation
if not mediaInstance or replyStr:
newPostForm += newPostImageSection
2021-05-30 14:06:28 +00:00
newPostForm += \
2021-07-05 20:24:43 +00:00
' <div class="container">\n' + \
' <input type="submit" name="submitPost" value="' + \
2021-07-05 20:24:43 +00:00
submitText + '">\n' + \
' </div>\n' + \
' </div>\n' + \
'</form>\n'
2020-11-09 22:57:12 +00:00
if not reportUrl:
newPostForm = \
newPostForm.replace('<body>', '<body onload="focusOnMessage()">')
newPostForm += htmlFooter()
return newPostForm