Show blog address from actor tags

main
Bob Mottram 2020-05-04 12:28:43 +01:00
parent 6203ba3426
commit fc141708a1
3 changed files with 124 additions and 2 deletions

84
blog.py
View File

@ -690,3 +690,87 @@ def htmlEditBlog(mediaInstance: bool, translate: {},
editBlogForm += htmlFooter() editBlogForm += htmlFooter()
return editBlogForm return editBlogForm
def getBlogAddress(actorJson: {}) -> str:
"""Returns blog address for the given actor
"""
if not actorJson.get('attachment'):
return ''
for propertyValue in actorJson['attachment']:
if not propertyValue.get('name'):
continue
if not propertyValue['name'].lower().startswith('Blog'):
continue
if not propertyValue.get('type'):
continue
if not propertyValue.get('value'):
continue
if propertyValue['type'] != 'PropertyValue':
continue
propertyValue['value'] = propertyValue['value'].strip()
if not (propertyValue['value'].startswith('https://') or
propertyValue['value'].startswith('http://') or
propertyValue['value'].startswith('dat://') or
propertyValue['value'].startswith('i2p://')):
continue
if '.' not in propertyValue['value']:
continue
if ' ' in propertyValue['value']:
continue
if ',' in propertyValue['value']:
continue
return propertyValue['value']
return ''
def setBlogAddress(actorJson: {}, blogAddress: str) -> None:
"""Sets an blog address for the given actor
"""
if not actorJson.get('attachment'):
actorJson['attachment'] = []
# remove any existing value
propertyFound = None
for propertyValue in actorJson['attachment']:
if not propertyValue.get('name'):
continue
if not propertyValue.get('type'):
continue
if not propertyValue['name'].lower().startswith('Blog'):
continue
propertyFound = propertyValue
break
if propertyFound:
actorJson['attachment'].remove(propertyFound)
if not (blogAddress.startswith('https://') or
blogAddress.startswith('http://') or
blogAddress.startswith('dat://') or
blogAddress.startswith('i2p://')):
return
if '.' not in blogAddress:
return
if ' ' in blogAddress:
return
if ',' in blogAddress:
return
for propertyValue in actorJson['attachment']:
if not propertyValue.get('name'):
continue
if not propertyValue.get('type'):
continue
if not propertyValue['name'].lower().startswith('blog'):
continue
if propertyValue['type'] != 'PropertyValue':
continue
propertyValue['value'] = blogAddress
return
newBlogAddress = {
"name": "Blog",
"type": "PropertyValue",
"value": blogAddress
}
actorJson['attachment'].append(newBlogAddress)

View File

@ -97,6 +97,8 @@ from blog import htmlBlogView
from blog import htmlBlogPage from blog import htmlBlogPage
from blog import htmlBlogPost from blog import htmlBlogPost
from blog import htmlEditBlog from blog import htmlEditBlog
from blog import getBlogAddress
from blog import setBlogAddress
from webinterface import htmlCalendarDeleteConfirm from webinterface import htmlCalendarDeleteConfirm
from webinterface import htmlDeletePost from webinterface import htmlDeletePost
from webinterface import htmlAbout from webinterface import htmlAbout
@ -1249,6 +1251,7 @@ class PubServer(BaseHTTPRequestHandler):
xmppAddress = getXmppAddress(actorJson) xmppAddress = getXmppAddress(actorJson)
matrixAddress = getMatrixAddress(actorJson) matrixAddress = getMatrixAddress(actorJson)
ssbAddress = getSSBAddress(actorJson) ssbAddress = getSSBAddress(actorJson)
blogAddress = getBlogAddress(actorJson)
toxAddress = getToxAddress(actorJson) toxAddress = getToxAddress(actorJson)
emailAddress = getEmailAddress(actorJson) emailAddress = getEmailAddress(actorJson)
PGPpubKey = getPGPpubKey(actorJson) PGPpubKey = getPGPpubKey(actorJson)
@ -1261,8 +1264,9 @@ class PubServer(BaseHTTPRequestHandler):
optionsLink, optionsLink,
pageNumber, donateUrl, pageNumber, donateUrl,
xmppAddress, matrixAddress, xmppAddress, matrixAddress,
ssbAddress, toxAddress, ssbAddress, blogAddress,
PGPpubKey, emailAddress).encode() toxAddress, PGPpubKey,
emailAddress).encode()
self._set_headers('text/html', len(msg), self._set_headers('text/html', len(msg),
cookie, callingDomain) cookie, callingDomain)
self._write(msg) self._write(msg)
@ -5370,6 +5374,7 @@ class PubServer(BaseHTTPRequestHandler):
setTheme(self.server.baseDir, setTheme(self.server.baseDir,
fields['themeDropdown']) fields['themeDropdown'])
# self.server.iconsCache={} # self.server.iconsCache={}
currentEmailAddress = getEmailAddress(actorJson) currentEmailAddress = getEmailAddress(actorJson)
if fields.get('email'): if fields.get('email'):
if fields['email'] != currentEmailAddress: if fields['email'] != currentEmailAddress:
@ -5379,6 +5384,7 @@ class PubServer(BaseHTTPRequestHandler):
if currentEmailAddress: if currentEmailAddress:
setEmailAddress(actorJson, '') setEmailAddress(actorJson, '')
actorChanged = True actorChanged = True
currentXmppAddress = getXmppAddress(actorJson) currentXmppAddress = getXmppAddress(actorJson)
if fields.get('xmppAddress'): if fields.get('xmppAddress'):
if fields['xmppAddress'] != currentXmppAddress: if fields['xmppAddress'] != currentXmppAddress:
@ -5389,6 +5395,7 @@ class PubServer(BaseHTTPRequestHandler):
if currentXmppAddress: if currentXmppAddress:
setXmppAddress(actorJson, '') setXmppAddress(actorJson, '')
actorChanged = True actorChanged = True
currentMatrixAddress = getMatrixAddress(actorJson) currentMatrixAddress = getMatrixAddress(actorJson)
if fields.get('matrixAddress'): if fields.get('matrixAddress'):
if fields['matrixAddress'] != currentMatrixAddress: if fields['matrixAddress'] != currentMatrixAddress:
@ -5399,6 +5406,7 @@ class PubServer(BaseHTTPRequestHandler):
if currentMatrixAddress: if currentMatrixAddress:
setMatrixAddress(actorJson, '') setMatrixAddress(actorJson, '')
actorChanged = True actorChanged = True
currentSSBAddress = getSSBAddress(actorJson) currentSSBAddress = getSSBAddress(actorJson)
if fields.get('ssbAddress'): if fields.get('ssbAddress'):
if fields['ssbAddress'] != currentSSBAddress: if fields['ssbAddress'] != currentSSBAddress:
@ -5409,6 +5417,18 @@ class PubServer(BaseHTTPRequestHandler):
if currentSSBAddress: if currentSSBAddress:
setSSBAddress(actorJson, '') setSSBAddress(actorJson, '')
actorChanged = True actorChanged = True
currentBlogAddress = getBlogAddress(actorJson)
if fields.get('blogAddress'):
if fields['blogAddress'] != currentBlogAddress:
setBlogAddress(actorJson,
fields['blogAddress'])
actorChanged = True
else:
if currentBlogAddress:
setBlogAddress(actorJson, '')
actorChanged = True
currentToxAddress = getToxAddress(actorJson) currentToxAddress = getToxAddress(actorJson)
if fields.get('toxAddress'): if fields.get('toxAddress'):
if fields['toxAddress'] != currentToxAddress: if fields['toxAddress'] != currentToxAddress:
@ -5419,6 +5439,7 @@ class PubServer(BaseHTTPRequestHandler):
if currentToxAddress: if currentToxAddress:
setToxAddress(actorJson, '') setToxAddress(actorJson, '')
actorChanged = True actorChanged = True
currentPGPpubKey = getPGPpubKey(actorJson) currentPGPpubKey = getPGPpubKey(actorJson)
if fields.get('pgp'): if fields.get('pgp'):
if fields['pgp'] != currentPGPpubKey: if fields['pgp'] != currentPGPpubKey:
@ -5429,6 +5450,7 @@ class PubServer(BaseHTTPRequestHandler):
if currentPGPpubKey: if currentPGPpubKey:
setPGPpubKey(actorJson, '') setPGPpubKey(actorJson, '')
actorChanged = True actorChanged = True
currentDonateUrl = getDonationUrl(actorJson) currentDonateUrl = getDonationUrl(actorJson)
if fields.get('donateUrl'): if fields.get('donateUrl'):
if fields['donateUrl'] != currentDonateUrl: if fields['donateUrl'] != currentDonateUrl:
@ -5439,6 +5461,7 @@ class PubServer(BaseHTTPRequestHandler):
if currentDonateUrl: if currentDonateUrl:
setDonationUrl(actorJson, '') setDonationUrl(actorJson, '')
actorChanged = True actorChanged = True
if fields.get('instanceTitle'): if fields.get('instanceTitle'):
currInstanceTitle = \ currInstanceTitle = \
getConfigParam(self.server.baseDir, getConfigParam(self.server.baseDir,

View File

@ -21,6 +21,7 @@ from pgp import getEmailAddress
from pgp import getPGPpubKey from pgp import getPGPpubKey
from xmpp import getXmppAddress from xmpp import getXmppAddress
from ssb import getSSBAddress from ssb import getSSBAddress
from blog import getBlogAddress
from tox import getToxAddress from tox import getToxAddress
from matrix import getMatrixAddress from matrix import getMatrixAddress
from donate import getDonationUrl from donate import getDonationUrl
@ -881,6 +882,7 @@ def htmlEditProfile(translate: {}, baseDir: str, path: str,
xmppAddress = '' xmppAddress = ''
matrixAddress = '' matrixAddress = ''
ssbAddress = '' ssbAddress = ''
blogAddress = ''
toxAddress = '' toxAddress = ''
manuallyApprovesFollowers = '' manuallyApprovesFollowers = ''
actorJson = loadJson(actorFilename) actorJson = loadJson(actorFilename)
@ -889,6 +891,7 @@ def htmlEditProfile(translate: {}, baseDir: str, path: str,
xmppAddress = getXmppAddress(actorJson) xmppAddress = getXmppAddress(actorJson)
matrixAddress = getMatrixAddress(actorJson) matrixAddress = getMatrixAddress(actorJson)
ssbAddress = getSSBAddress(actorJson) ssbAddress = getSSBAddress(actorJson)
blogAddress = getBlogAddress(actorJson)
toxAddress = getToxAddress(actorJson) toxAddress = getToxAddress(actorJson)
emailAddress = getEmailAddress(actorJson) emailAddress = getEmailAddress(actorJson)
PGPpubKey = getPGPpubKey(actorJson) PGPpubKey = getPGPpubKey(actorJson)
@ -1120,10 +1123,17 @@ def htmlEditProfile(translate: {}, baseDir: str, path: str,
editProfileForm += \ editProfileForm += \
' <input type="text" name="matrixAddress" value="' + \ ' <input type="text" name="matrixAddress" value="' + \
matrixAddress+'">' matrixAddress+'">'
editProfileForm += '<label class="labels">SSB</label><br>' editProfileForm += '<label class="labels">SSB</label><br>'
editProfileForm += \ editProfileForm += \
' <input type="text" name="ssbAddress" value="' + \ ' <input type="text" name="ssbAddress" value="' + \
ssbAddress + '">' ssbAddress + '">'
editProfileForm += '<label class="labels">Blog</label><br>'
editProfileForm += \
' <input type="text" name="blogAddress" value="' + \
blogAddress + '">'
editProfileForm += '<label class="labels">Tox</label><br>' editProfileForm += '<label class="labels">Tox</label><br>'
editProfileForm += \ editProfileForm += \
' <input type="text" name="toxAddress" value="' + \ ' <input type="text" name="toxAddress" value="' + \
@ -5055,6 +5065,7 @@ def htmlPersonOptions(translate: {}, baseDir: str,
xmppAddress: str, xmppAddress: str,
matrixAddress: str, matrixAddress: str,
ssbAddress: str, ssbAddress: str,
blogAddress: str,
toxAddress: str, toxAddress: str,
PGPpubKey: str, PGPpubKey: str,
emailAddress) -> str: emailAddress) -> str:
@ -5139,6 +5150,10 @@ def htmlPersonOptions(translate: {}, baseDir: str,
if ssbAddress: if ssbAddress:
optionsStr += \ optionsStr += \
'<p class="imText">SSB: ' + ssbAddress + '</p>' '<p class="imText">SSB: ' + ssbAddress + '</p>'
if blogAddress:
optionsStr += \
'<p class="imText">Blog: <a href="' + blogAddress + '">' + \
blogAddress + '</a></p>'
if toxAddress: if toxAddress:
optionsStr += \ optionsStr += \
'<p class="imText">Tox: ' + toxAddress + '</p>' '<p class="imText">Tox: ' + toxAddress + '</p>'