epicyon/webapp_column_right.py

718 lines
27 KiB
Python
Raw Normal View History

2020-11-09 22:44:03 +00:00
__filename__ = "webapp_column_right.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
from datetime import datetime
from content import removeLongWords
from content import limitRepeatedWords
2021-12-17 12:01:54 +00:00
from utils import getFavFilenameFromUrl
from utils import getBaseContentFromPost
2020-11-18 22:31:38 +00:00
from utils import removeHtml
from utils import locatePost
from utils import loadJson
2020-11-09 22:44:03 +00:00
from utils import votesOnNewswireItem
from utils import getNicknameFromActor
2020-12-01 21:44:27 +00:00
from utils import isEditor
2021-01-11 19:46:21 +00:00
from utils import getConfigParam
2021-06-26 14:21:24 +00:00
from utils import removeDomainPort
2021-07-13 21:59:53 +00:00
from utils import acctDir
2020-11-09 22:44:03 +00:00
from posts import isModerator
2021-12-16 21:22:44 +00:00
from newswire import getNewswireFaviconUrl
2020-11-09 22:44:03 +00:00
from webapp_utils import getRightImageFile
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
from webapp_utils import htmlPostSeparator
from webapp_utils import headerButtonsFrontScreen
from webapp_utils import editTextField
2020-11-09 22:44:03 +00:00
def _votesIndicator(totalVotes: int, positiveVoting: bool) -> str:
2020-11-09 22:44:03 +00:00
"""Returns an indicator of the number of votes on a newswire item
"""
if totalVotes <= 0:
return ''
totalVotesStr = ' '
for v in range(totalVotes):
if positiveVoting:
totalVotesStr += ''
else:
totalVotesStr += ''
return totalVotesStr
2021-12-25 16:17:53 +00:00
def getRightColumnContent(base_dir: str, nickname: str, domainFull: str,
2021-12-25 17:09:22 +00:00
http_prefix: str, translate: {},
2020-12-09 13:31:54 +00:00
moderator: bool, editor: bool,
2020-11-09 22:44:03 +00:00
newswire: {}, positiveVoting: bool,
showBackButton: bool, timelinePath: str,
showPublishButton: bool,
showPublishAsIcon: bool,
2021-12-25 19:09:03 +00:00
rss_icon_at_top: bool,
2021-12-25 19:00:00 +00:00
publish_button_at_top: bool,
2020-11-09 22:44:03 +00:00
authorized: bool,
2020-12-20 17:26:38 +00:00
showHeaderImage: bool,
2021-02-05 11:35:25 +00:00
theme: str,
2021-04-23 19:06:34 +00:00
defaultTimeline: str,
accessKeys: {}) -> str:
2020-11-09 22:44:03 +00:00
"""Returns html content for the right column
"""
htmlStr = ''
domain = removeDomainPort(domainFull)
2020-11-09 22:44:03 +00:00
if authorized:
# only show the publish button if logged in, otherwise replace it with
# a login button
2021-02-05 11:35:25 +00:00
titleStr = translate['Publish a blog article']
if defaultTimeline == 'tlfeatures':
titleStr = translate['Publish a news article']
2020-11-09 22:44:03 +00:00
publishButtonStr = \
' <a href="' + \
'/users/' + nickname + '/newblog?nodropdown" ' + \
2021-04-23 19:06:34 +00:00
'title="' + titleStr + '" ' + \
'accesskey="' + accessKeys['menuNewPost'] + '">' + \
2020-11-09 22:44:03 +00:00
'<button class="publishbtn">' + \
translate['Publish'] + '</button></a>\n'
else:
# if not logged in then replace the publish button with
# a login button
publishButtonStr = \
' <a href="/login"><button class="publishbtn">' + \
translate['Login'] + '</button></a>\n'
# show publish button at the top if needed
2021-12-25 19:00:00 +00:00
if publish_button_at_top:
2020-11-09 22:44:03 +00:00
htmlStr += '<center>' + publishButtonStr + '</center>'
# show a column header image, eg. title of the theme or newswire banner
editImageClass = ''
if showHeaderImage:
rightImageFile, rightColumnImageFilename = \
2021-12-25 16:17:53 +00:00
getRightImageFile(base_dir, nickname, domain, theme)
2020-11-09 22:44:03 +00:00
# show the image at the top of the column
editImageClass = 'rightColEdit'
if os.path.isfile(rightColumnImageFilename):
editImageClass = 'rightColEditImage'
htmlStr += \
'\n <center>\n' + \
' <img class="rightColImg" ' + \
2021-02-01 19:48:46 +00:00
'alt="" loading="lazy" src="/users/' + \
2020-11-09 22:44:03 +00:00
nickname + '/' + rightImageFile + '" />\n' + \
' </center>\n'
2021-12-25 19:09:03 +00:00
if showPublishButton or editor or rss_icon_at_top:
if not showHeaderImage:
htmlStr += '<div class="columnIcons">'
2020-11-09 22:44:03 +00:00
if editImageClass == 'rightColEdit':
htmlStr += '\n <center>\n'
# whether to show a back icon
# This is probably going to be osolete soon
if showBackButton:
htmlStr += \
' <a href="' + timelinePath + '">' + \
'<button class="cancelbtn">' + \
translate['Go Back'] + '</button></a>\n'
2021-12-25 19:00:00 +00:00
if showPublishButton and not publish_button_at_top:
2020-11-09 22:44:03 +00:00
if not showPublishAsIcon:
htmlStr += publishButtonStr
# show the edit icon
if editor:
2021-12-25 16:17:53 +00:00
if os.path.isfile(base_dir + '/accounts/newswiremoderation.txt'):
2020-11-09 22:44:03 +00:00
# show the edit icon highlighted
htmlStr += \
' <a href="' + \
2021-04-23 19:06:34 +00:00
'/users/' + nickname + '/editnewswire" ' + \
'accesskey="' + accessKeys['menuEdit'] + '">' + \
2020-11-09 22:44:03 +00:00
'<img class="' + editImageClass + \
'" loading="lazy" alt="' + \
2021-02-01 19:28:07 +00:00
translate['Edit newswire'] + ' | " title="' + \
2020-11-09 22:44:03 +00:00
translate['Edit newswire'] + '" src="/' + \
2020-12-09 13:08:26 +00:00
'icons/edit_notify.png" /></a>\n'
2020-11-09 22:44:03 +00:00
else:
# show the edit icon
htmlStr += \
' <a href="' + \
2021-04-23 19:06:34 +00:00
'/users/' + nickname + '/editnewswire" ' + \
'accesskey="' + accessKeys['menuEdit'] + '">' + \
2020-11-09 22:44:03 +00:00
'<img class="' + editImageClass + \
'" loading="lazy" alt="' + \
2021-02-01 19:32:33 +00:00
translate['Edit newswire'] + ' | " title="' + \
2020-11-09 22:44:03 +00:00
translate['Edit newswire'] + '" src="/' + \
2020-12-09 13:08:26 +00:00
'icons/edit.png" /></a>\n'
2020-11-09 22:44:03 +00:00
2020-12-02 18:40:51 +00:00
# show the RSS icons
2020-11-09 22:44:03 +00:00
rssIconStr = \
2020-12-02 18:40:51 +00:00
' <a href="/categories.xml">' + \
'<img class="' + editImageClass + \
'" loading="lazy" alt="' + \
2021-02-01 19:28:07 +00:00
translate['Hashtag Categories RSS Feed'] + ' | " title="' + \
2020-12-02 18:40:51 +00:00
translate['Hashtag Categories RSS Feed'] + '" src="/' + \
2020-12-09 13:08:26 +00:00
'icons/categoriesrss.png" /></a>\n'
2020-12-02 18:40:51 +00:00
rssIconStr += \
2020-11-09 22:44:03 +00:00
' <a href="/newswire.xml">' + \
'<img class="' + editImageClass + \
'" loading="lazy" alt="' + \
2021-02-01 19:28:07 +00:00
translate['Newswire RSS Feed'] + ' | " title="' + \
2020-11-09 22:44:03 +00:00
translate['Newswire RSS Feed'] + '" src="/' + \
2020-12-09 13:08:26 +00:00
'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
# show publish icon at top
if showPublishButton:
if showPublishAsIcon:
2021-02-05 11:35:25 +00:00
titleStr = translate['Publish a blog article']
if defaultTimeline == 'tlfeatures':
titleStr = translate['Publish a news article']
2020-11-09 22:44:03 +00:00
htmlStr += \
' <a href="' + \
2021-04-23 19:13:10 +00:00
'/users/' + nickname + '/newblog?nodropdown" ' + \
'accesskey="' + accessKeys['menuNewPost'] + '">' + \
2020-11-09 22:44:03 +00:00
'<img class="' + editImageClass + \
'" loading="lazy" alt="' + \
2021-02-05 11:35:25 +00:00
titleStr + '" title="' + \
titleStr + '" src="/' + \
2020-12-09 13:08:26 +00:00
'icons/publish.png" /></a>\n'
2020-11-09 22:44:03 +00:00
if editImageClass == 'rightColEdit':
htmlStr += ' </center>\n'
else:
if showHeaderImage:
htmlStr += ' <br>\n'
2021-12-25 19:09:03 +00:00
if showPublishButton or editor or rss_icon_at_top:
if not showHeaderImage:
htmlStr += '</div><br>'
2020-11-09 22:44:03 +00:00
# show the newswire lines
newswireContentStr = \
2021-12-25 16:17:53 +00:00
_htmlNewswire(base_dir, newswire, nickname, moderator, translate,
2021-12-17 13:23:19 +00:00
positiveVoting)
2020-11-09 22:44:03 +00:00
htmlStr += newswireContentStr
# show the rss icon at the bottom, typically on the right hand side
2021-12-25 19:09:03 +00:00
if newswireContentStr and not rss_icon_at_top:
2020-11-09 22:44:03 +00:00
htmlStr += '<br><div class="columnIcons">' + rssIconStr + '</div>'
return htmlStr
2020-12-27 20:39:32 +00:00
def _getBrokenFavSubstitute() -> str:
2020-12-26 11:06:57 +00:00
"""Substitute link used if a favicon is not available
"""
2021-01-07 12:12:09 +00:00
return " onerror=\"this.onerror=null; this.src='/newswire_favicon.ico'\""
2020-12-26 11:06:57 +00:00
2021-12-25 16:17:53 +00:00
def _htmlNewswire(base_dir: str, newswire: {}, nickname: str, moderator: bool,
2021-12-17 13:23:19 +00:00
translate: {}, positiveVoting: bool) -> str:
2020-11-09 22:44:03 +00:00
"""Converts a newswire dict into html
"""
2021-12-25 16:17:53 +00:00
separatorStr = htmlPostSeparator(base_dir, 'right')
2020-11-09 22:44:03 +00:00
htmlStr = ''
for dateStr, item in newswire.items():
2020-11-18 22:31:38 +00:00
item[0] = removeHtml(item[0]).strip()
if not item[0]:
2020-11-18 22:15:32 +00:00
continue
2020-11-18 22:31:38 +00:00
# remove any CDATA
if 'CDATA[' in item[0]:
item[0] = item[0].split('CDATA[')[1]
if ']' in item[0]:
item[0] = item[0].split(']')[0]
2020-11-22 15:41:42 +00:00
try:
publishedDate = \
datetime.strptime(dateStr, "%Y-%m-%d %H:%M:%S%z")
except BaseException:
2021-10-29 18:48:15 +00:00
print('EX: _htmlNewswire bad date format ' + dateStr)
2020-11-22 15:41:42 +00:00
continue
2020-11-09 22:44:03 +00:00
dateShown = publishedDate.strftime("%Y-%m-%d %H:%M")
dateStrLink = dateStr.replace('T', ' ')
dateStrLink = dateStrLink.replace('Z', '')
2020-12-26 11:06:57 +00:00
url = item[1]
2021-12-16 21:22:44 +00:00
faviconUrl = getNewswireFaviconUrl(url)
2020-12-26 11:06:57 +00:00
faviconLink = ''
if faviconUrl:
2021-12-25 16:17:53 +00:00
cachedFaviconFilename = getFavFilenameFromUrl(base_dir, faviconUrl)
2021-12-16 21:27:50 +00:00
if os.path.isfile(cachedFaviconFilename):
2021-12-17 12:01:54 +00:00
faviconUrl = \
2021-12-25 16:17:53 +00:00
cachedFaviconFilename.replace(base_dir, '')
2021-12-17 10:36:22 +00:00
else:
2021-12-17 12:01:54 +00:00
extensions = ('png', 'jpg', 'gif', 'avif', 'svg', 'webp')
for ext in extensions:
cachedFaviconFilename = \
2021-12-25 16:17:53 +00:00
getFavFilenameFromUrl(base_dir, faviconUrl)
2021-12-17 12:01:54 +00:00
cachedFaviconFilename = \
cachedFaviconFilename.replace('.ico', '.' + ext)
if os.path.isfile(cachedFaviconFilename):
faviconUrl = \
2021-12-25 16:17:53 +00:00
cachedFaviconFilename.replace(base_dir, '')
2021-12-17 10:36:22 +00:00
2020-12-26 11:06:57 +00:00
faviconLink = \
'<img loading="lazy" src="' + faviconUrl + '" ' + \
2021-07-05 20:24:43 +00:00
'alt="" ' + _getBrokenFavSubstitute() + '/>'
2020-11-09 22:44:03 +00:00
moderatedItem = item[5]
htmlStr += separatorStr
if moderatedItem and 'vote:' + nickname in item[2]:
totalVotesStr = ''
totalVotes = 0
if moderator:
totalVotes = votesOnNewswireItem(item[2])
totalVotesStr = \
_votesIndicator(totalVotes, positiveVoting)
2020-11-09 22:44:03 +00:00
2020-11-18 22:15:32 +00:00
title = removeLongWords(item[0], 16, []).replace('\n', '<br>')
title = limitRepeatedWords(title, 6)
2020-11-09 22:44:03 +00:00
htmlStr += '<p class="newswireItemVotedOn">' + \
2020-12-26 11:06:57 +00:00
'<a href="' + url + '" target="_blank" ' + \
2020-12-11 10:14:58 +00:00
'rel="nofollow noopener noreferrer">' + \
2020-12-26 11:06:57 +00:00
'<span class="newswireItemVotedOn">' + \
2021-07-05 20:24:43 +00:00
faviconLink + title + '</span></a>' + totalVotesStr
2020-11-09 22:44:03 +00:00
if moderator:
htmlStr += \
' ' + dateShown + '<a href="/users/' + nickname + \
'/newswireunvote=' + dateStrLink + '" ' + \
'title="' + translate['Remove Vote'] + '">'
htmlStr += '<img loading="lazy" class="voteicon" src="/' + \
2021-02-01 18:58:24 +00:00
'alt="' + translate['Remove Vote'] + '" ' + \
2020-12-09 13:08:26 +00:00
'icons/vote.png" /></a></p>\n'
2020-11-09 22:44:03 +00:00
else:
htmlStr += ' <span class="newswireDateVotedOn">'
htmlStr += dateShown + '</span></p>\n'
else:
totalVotesStr = ''
totalVotes = 0
if moderator:
if moderatedItem:
totalVotes = votesOnNewswireItem(item[2])
# show a number of ticks or crosses for how many
# votes for or against
totalVotesStr = \
_votesIndicator(totalVotes, positiveVoting)
2020-11-09 22:44:03 +00:00
2020-11-18 22:15:32 +00:00
title = removeLongWords(item[0], 16, []).replace('\n', '<br>')
title = limitRepeatedWords(title, 6)
2020-11-09 22:44:03 +00:00
if moderator and moderatedItem:
htmlStr += '<p class="newswireItemModerated">' + \
2020-12-26 11:06:57 +00:00
'<a href="' + url + '" target="_blank" ' + \
2020-12-11 10:14:58 +00:00
'rel="nofollow noopener noreferrer">' + \
2020-12-26 11:06:57 +00:00
faviconLink + title + '</a>' + totalVotesStr
2020-11-09 22:44:03 +00:00
htmlStr += ' ' + dateShown
htmlStr += '<a href="/users/' + nickname + \
'/newswirevote=' + dateStrLink + '" ' + \
'title="' + translate['Vote'] + '">'
2021-02-01 18:58:24 +00:00
htmlStr += '<img class="voteicon" ' + \
'alt="' + translate['Vote'] + '" ' + \
'src="/icons/vote.png" /></a>'
2020-11-09 22:44:03 +00:00
htmlStr += '</p>\n'
else:
htmlStr += '<p class="newswireItem">' + \
2020-12-26 11:06:57 +00:00
'<a href="' + url + '" target="_blank" ' + \
2020-12-11 10:14:58 +00:00
'rel="nofollow noopener noreferrer">' + \
2021-07-05 20:24:43 +00:00
faviconLink + title + '</a>' + totalVotesStr
2020-11-09 22:44:03 +00:00
htmlStr += ' <span class="newswireDate">'
htmlStr += dateShown + '</span></p>\n'
2020-12-27 15:22:14 +00:00
if htmlStr:
htmlStr = '<nav>\n' + htmlStr + '</nav>\n'
2020-11-09 22:44:03 +00:00
return htmlStr
2021-12-25 16:17:53 +00:00
def htmlCitations(base_dir: str, nickname: str, domain: str,
2021-12-25 17:09:22 +00:00
http_prefix: str, defaultTimeline: str,
2020-11-09 22:44:03 +00:00
translate: {}, newswire: {}, cssCache: {},
blogTitle: str, blogContent: str,
blogImageFilename: str,
blogImageAttachmentMediaType: str,
2020-12-20 18:16:53 +00:00
blogImageDescription: str,
theme: str) -> str:
2020-11-09 22:44:03 +00:00
"""Show the citations screen when creating a blog
"""
htmlStr = ''
# create a list of dates for citations
# these can then be used to re-select checkboxes later
citationsFilename = \
2021-12-25 16:17:53 +00:00
acctDir(base_dir, nickname, domain) + '/.citations.txt'
2020-11-09 22:44:03 +00:00
citationsSelected = []
if os.path.isfile(citationsFilename):
citationsSeparator = '#####'
2021-07-13 14:40:49 +00:00
with open(citationsFilename, 'r') as f:
2020-11-09 22:44:03 +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
dateStr = sections[0]
citationsSelected.append(dateStr)
# 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
2021-01-11 19:46:21 +00:00
instanceTitle = \
2021-12-25 16:17:53 +00:00
getConfigParam(base_dir, 'instanceTitle')
htmlStr = htmlHeaderWithExternalStyle(cssFilename, instanceTitle, None)
2020-11-09 22:44:03 +00:00
# top banner
2020-12-20 18:16:53 +00:00
bannerFile, bannerFilename = \
2021-12-25 16:17:53 +00:00
getBannerFile(base_dir, nickname, domain, theme)
2020-11-09 22:44:03 +00:00
htmlStr += \
'<a href="/users/' + nickname + '/newblog" title="' + \
translate['Go Back'] + '" alt="' + \
translate['Go Back'] + '">\n'
2021-02-01 18:58:24 +00:00
htmlStr += '<img loading="lazy" class="timeline-banner" ' + \
2021-02-01 19:48:46 +00:00
'alt="" src="' + \
2020-11-09 22:44:03 +00:00
'/users/' + nickname + '/' + bannerFile + '" /></a>\n'
htmlStr += \
'<form enctype="multipart/form-data" method="POST" ' + \
'accept-charset="UTF-8" action="/users/' + nickname + \
'/citationsdata">\n'
htmlStr += ' <center>\n'
htmlStr += translate['Choose newswire items ' +
'referenced in your article'] + '<br>'
if blogTitle is None:
blogTitle = ''
htmlStr += \
' <input type="hidden" name="blogTitle" value="' + \
blogTitle + '">\n'
if blogContent is None:
blogContent = ''
htmlStr += \
' <input type="hidden" name="blogContent" value="' + \
blogContent + '">\n'
# submit button
htmlStr += \
' <input type="submit" name="submitCitations" value="' + \
translate['Submit'] + '">\n'
htmlStr += ' </center>\n'
citationsSeparator = '#####'
# list of newswire items
if newswire:
ctr = 0
for dateStr, item in newswire.items():
2020-11-18 22:31:38 +00:00
item[0] = removeHtml(item[0]).strip()
if not item[0]:
2020-11-18 22:15:32 +00:00
continue
2020-11-18 22:31:38 +00:00
# remove any CDATA
if 'CDATA[' in item[0]:
item[0] = item[0].split('CDATA[')[1]
if ']' in item[0]:
item[0] = item[0].split(']')[0]
2020-11-09 22:44:03 +00:00
# should this checkbox be selected?
selectedStr = ''
if dateStr in citationsSelected:
selectedStr = ' checked'
publishedDate = \
datetime.strptime(dateStr, "%Y-%m-%d %H:%M:%S%z")
dateShown = publishedDate.strftime("%Y-%m-%d %H:%M")
title = removeLongWords(item[0], 16, []).replace('\n', '<br>')
title = limitRepeatedWords(title, 6)
2020-11-09 22:44:03 +00:00
link = item[1]
citationValue = \
dateStr + citationsSeparator + \
title + citationsSeparator + \
link
htmlStr += \
'<input type="checkbox" name="newswire' + str(ctr) + \
'" value="' + citationValue + '"' + selectedStr + '/>' + \
'<a href="' + link + '"><cite>' + title + '</cite></a> '
htmlStr += '<span class="newswireDate">' + \
dateShown + '</span><br>\n'
ctr += 1
htmlStr += '</form>\n'
return htmlStr + htmlFooter()
2021-12-25 16:17:53 +00:00
def htmlNewswireMobile(cssCache: {}, base_dir: str, nickname: str,
2020-11-09 22:44:03 +00:00
domain: str, domainFull: str,
2021-12-25 17:09:22 +00:00
http_prefix: str, translate: {},
2020-11-09 22:44:03 +00:00
newswire: {},
positiveVoting: bool,
timelinePath: str,
showPublishAsIcon: bool,
authorized: bool,
2021-12-25 19:09:03 +00:00
rss_icon_at_top: bool,
2020-11-09 22:44:03 +00:00
iconsAsButtons: bool,
2020-12-20 17:26:38 +00:00
defaultTimeline: str,
2021-04-23 19:06:34 +00:00
theme: str,
accessKeys: {}) -> str:
2020-11-09 22:44:03 +00:00
"""Shows the mobile version of the newswire right column
"""
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
if nickname == 'news':
editor = False
moderator = False
else:
# is the user a moderator?
2021-12-25 16:17:53 +00:00
moderator = isModerator(base_dir, nickname)
2020-11-09 22:44:03 +00:00
# is the user a site editor?
2021-12-25 16:17:53 +00:00
editor = isEditor(base_dir, nickname)
2020-11-09 22:44:03 +00:00
showPublishButton = editor
2021-01-11 19:46:21 +00:00
instanceTitle = \
2021-12-25 16:17:53 +00:00
getConfigParam(base_dir, 'instanceTitle')
htmlStr = htmlHeaderWithExternalStyle(cssFilename, instanceTitle, None)
2020-11-09 22:44:03 +00:00
2020-12-20 18:16:53 +00:00
bannerFile, bannerFilename = \
2021-12-25 16:17:53 +00:00
getBannerFile(base_dir, nickname, domain, theme)
2020-11-09 22:44:03 +00:00
htmlStr += \
2021-04-23 19:06:34 +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 18:58:24 +00:00
'alt="' + translate['Timeline banner image'] + '" ' + \
2020-11-09 22:44:03 +00:00
'src="/users/' + nickname + '/' + bannerFile + '" /></a>\n'
htmlStr += '<div class="col-right-mobile">\n'
2020-11-09 22:44:03 +00:00
htmlStr += '<center>' + \
headerButtonsFrontScreen(translate, nickname,
'newswire', authorized,
2020-12-09 13:31:54 +00:00
iconsAsButtons) + '</center>'
2021-11-30 22:29:36 +00:00
htmlStr += \
2021-12-25 16:17:53 +00:00
getRightColumnContent(base_dir, nickname, domainFull,
2021-12-25 17:09:22 +00:00
http_prefix, translate,
2021-11-30 22:29:36 +00:00
moderator, editor,
newswire, positiveVoting,
False, timelinePath, showPublishButton,
2021-12-25 19:09:03 +00:00
showPublishAsIcon, rss_icon_at_top, False,
2021-11-30 22:29:36 +00:00
authorized, False, theme,
defaultTimeline, accessKeys)
if editor and not newswire:
htmlStr += '<br><br><br>\n'
htmlStr += '<center>\n '
htmlStr += translate['Select the edit icon to add RSS feeds']
htmlStr += '\n</center>\n'
# end of col-right-mobile
htmlStr += '</div\n>'
2020-11-09 22:44:03 +00:00
htmlStr += htmlFooter()
return htmlStr
2021-12-25 16:17:53 +00:00
def htmlEditNewswire(cssCache: {}, translate: {}, base_dir: str, path: str,
2021-12-25 17:09:22 +00:00
domain: str, port: int, http_prefix: str,
2021-04-23 19:23:29 +00:00
defaultTimeline: str, theme: str,
accessKeys: {}) -> str:
2020-11-09 22:44:03 +00:00
"""Shows the edit newswire 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
nickname = getNicknameFromActor(path)
if not nickname:
return ''
# is the user a moderator?
2021-12-25 16:17:53 +00:00
if not isModerator(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 18:16:53 +00:00
bannerFile, bannerFilename = \
2021-12-25 16:17:53 +00:00
getBannerFile(base_dir, nickname, domain, theme)
2020-11-09 22:44:03 +00:00
2021-01-11 19:46:21 +00:00
instanceTitle = \
2021-12-25 16:17:53 +00:00
getConfigParam(base_dir, 'instanceTitle')
editNewswireForm = \
htmlHeaderWithExternalStyle(cssFilename, instanceTitle, None)
2020-11-09 22:44:03 +00:00
# top banner
editNewswireForm += \
2020-12-27 16:57:15 +00:00
'<header>' + \
2020-11-09 22:44:03 +00:00
'<a href="/users/' + nickname + '/' + defaultTimeline + '" title="' + \
translate['Switch to timeline view'] + '" alt="' + \
2021-04-23 19:23:29 +00:00
translate['Switch to timeline view'] + '" ' + \
'accesskey="' + accessKeys['menuTimeline'] + '">\n'
2020-11-09 22:44:03 +00:00
editNewswireForm += '<img loading="lazy" class="timeline-banner" src="' + \
2021-02-01 18:58:24 +00:00
'/users/' + nickname + '/' + bannerFile + '" ' + \
'alt="" /></a>\n</header>'
2020-11-09 22:44:03 +00:00
editNewswireForm += \
'<form enctype="multipart/form-data" method="POST" ' + \
'accept-charset="UTF-8" action="' + path + '/newswiredata">\n'
editNewswireForm += \
' <div class="vertical-center">\n'
editNewswireForm += \
2020-11-21 09:44:33 +00:00
' <h1>' + translate['Edit newswire'] + '</h1>'
2020-11-09 22:44:03 +00:00
editNewswireForm += \
2020-12-21 16:20:17 +00:00
' <div class="containerSubmitNewPost">\n'
2020-11-09 22:44:03 +00:00
editNewswireForm += \
' <input type="submit" name="submitNewswire" value="' + \
2021-04-23 19:23:29 +00:00
translate['Submit'] + '" ' + \
'accesskey="' + accessKeys['submitButton'] + '">\n'
2020-11-09 22:44:03 +00:00
editNewswireForm += \
' </div>\n'
2021-12-25 16:17:53 +00:00
newswireFilename = base_dir + '/accounts/newswire.txt'
2020-11-09 22:44:03 +00:00
newswireStr = ''
if os.path.isfile(newswireFilename):
with open(newswireFilename, 'r') as fp:
newswireStr = fp.read()
2020-11-09 22:44:03 +00:00
editNewswireForm += \
'<div class="container">'
editNewswireForm += \
' ' + \
translate['Add RSS feed links below.'] + \
'<br>'
newFeedStr = translate['New feed URL']
editNewswireForm += editTextField(None, 'newNewswireFeed', '', newFeedStr)
2020-11-09 22:44:03 +00:00
editNewswireForm += \
' <textarea id="message" name="editedNewswire" ' + \
2021-02-28 14:26:04 +00:00
'style="height:80vh" spellcheck="false">' + \
newswireStr + '</textarea>'
2020-11-09 22:44:03 +00:00
filterStr = ''
filterFilename = \
2021-12-25 16:17:53 +00:00
base_dir + '/accounts/news@' + domain + '/filters.txt'
2020-11-09 22:44:03 +00:00
if os.path.isfile(filterFilename):
with open(filterFilename, 'r') as filterfile:
filterStr = filterfile.read()
2020-11-09 22:44:03 +00:00
editNewswireForm += \
' <br><b><label class="labels">' + \
translate['Filtered words'] + '</label></b>\n'
editNewswireForm += ' <br><label class="labels">' + \
translate['One per line'] + '</label>'
editNewswireForm += ' <textarea id="message" ' + \
2021-02-28 14:26:04 +00:00
'name="filteredWordsNewswire" style="height:50vh" ' + \
'spellcheck="true">' + filterStr + '</textarea>\n'
2020-11-09 22:44:03 +00:00
hashtagRulesStr = ''
hashtagRulesFilename = \
2021-12-25 16:17:53 +00:00
base_dir + '/accounts/hashtagrules.txt'
2020-11-09 22:44:03 +00:00
if os.path.isfile(hashtagRulesFilename):
with open(hashtagRulesFilename, 'r') as rulesfile:
hashtagRulesStr = rulesfile.read()
2020-11-09 22:44:03 +00:00
editNewswireForm += \
' <br><b><label class="labels">' + \
translate['News tagging rules'] + '</label></b>\n'
editNewswireForm += ' <br><label class="labels">' + \
translate['One per line'] + '.</label>\n'
editNewswireForm += \
' <a href="' + \
'https://gitlab.com/bashrc2/epicyon/-/raw/main/hashtagrules.txt' + \
'">' + translate['See instructions'] + '</a>\n'
editNewswireForm += ' <textarea id="message" ' + \
2021-02-28 14:26:04 +00:00
'name="hashtagRulesList" style="height:80vh" spellcheck="false">' + \
2020-11-09 22:44:03 +00:00
hashtagRulesStr + '</textarea>\n'
editNewswireForm += \
'</div>'
editNewswireForm += htmlFooter()
return editNewswireForm
2021-12-25 16:17:53 +00:00
def htmlEditNewsPost(cssCache: {}, translate: {}, base_dir: str, path: str,
domain: str, port: int,
2021-12-25 17:09:22 +00:00
http_prefix: str, postUrl: str,
systemLanguage: str) -> str:
"""Edits a news post on the news/features timeline
"""
if '/users/' not in path:
return ''
pathOriginal = path
nickname = getNicknameFromActor(path)
if not nickname:
return ''
# is the user an editor?
2021-12-25 16:17:53 +00:00
if not isEditor(base_dir, nickname):
return ''
postUrl = postUrl.replace('/', '#')
2021-12-25 16:17:53 +00:00
postFilename = locatePost(base_dir, nickname, domain, postUrl)
if not postFilename:
return ''
postJsonObject = loadJson(postFilename)
if not postJsonObject:
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'
2021-01-11 19:46:21 +00:00
instanceTitle = \
2021-12-25 16:17:53 +00:00
getConfigParam(base_dir, 'instanceTitle')
editNewsPostForm = \
htmlHeaderWithExternalStyle(cssFilename, instanceTitle, None)
editNewsPostForm += \
'<form enctype="multipart/form-data" method="POST" ' + \
'accept-charset="UTF-8" action="' + path + '/newseditdata">\n'
editNewsPostForm += \
' <div class="vertical-center">\n'
editNewsPostForm += \
2020-11-21 09:56:45 +00:00
' <h1>' + translate['Edit News Post'] + '</h1>'
editNewsPostForm += \
' <div class="container">\n'
editNewsPostForm += \
' <a href="' + pathOriginal + '/tlnews">' + \
'<button class="cancelbtn">' + translate['Go Back'] + '</button></a>\n'
editNewsPostForm += \
' <input type="submit" name="submitEditedNewsPost" value="' + \
translate['Submit'] + '">\n'
editNewsPostForm += \
' </div>\n'
editNewsPostForm += \
'<div class="container">'
editNewsPostForm += \
' <input type="hidden" name="newsPostUrl" value="' + \
postUrl + '">\n'
newsPostTitle = postJsonObject['object']['summary']
editNewsPostForm += \
' <input type="text" name="newsPostTitle" value="' + \
newsPostTitle + '"><br>\n'
newsPostContent = getBaseContentFromPost(postJsonObject, systemLanguage)
editNewsPostForm += \
' <textarea id="message" name="editedNewsPost" ' + \
2021-02-28 14:26:04 +00:00
'style="height:600px" spellcheck="true">' + \
newsPostContent + '</textarea>'
editNewsPostForm += \
'</div>'
editNewsPostForm += htmlFooter()
return editNewsPostForm