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

View File

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