mirror of https://gitlab.com/bashrc2/epicyon
flake8 style
parent
032b168d03
commit
0f1e754913
320
blog.py
320
blog.py
|
@ -6,16 +6,8 @@ __maintainer__="Bob Mottram"
|
||||||
__email__ = "bob@freedombone.net"
|
__email__ = "bob@freedombone.net"
|
||||||
__status__ = "Production"
|
__status__ = "Production"
|
||||||
|
|
||||||
import json
|
|
||||||
import time
|
|
||||||
import os
|
import os
|
||||||
from collections import OrderedDict
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from datetime import date
|
|
||||||
from dateutil.parser import parse
|
|
||||||
from shutil import copyfile
|
|
||||||
from shutil import copyfileobj
|
|
||||||
from pprint import pprint
|
|
||||||
|
|
||||||
from content import replaceEmojiFromTags
|
from content import replaceEmojiFromTags
|
||||||
from webinterface import contentWarningScriptOpen
|
from webinterface import contentWarningScriptOpen
|
||||||
|
@ -31,8 +23,8 @@ from utils import loadJson
|
||||||
from posts import createBlogsTimeline
|
from posts import createBlogsTimeline
|
||||||
|
|
||||||
|
|
||||||
def noOfBlogReplies(baseDir: str,httpPrefix: str,translate: {}, \
|
def noOfBlogReplies(baseDir: str, httpPrefix: str, translate: {},
|
||||||
nickname: str,domain: str,domainFull: str, \
|
nickname: str, domain: str, domainFull: str,
|
||||||
postId: str, depth=0) -> int:
|
postId: str, depth=0) -> int:
|
||||||
"""Returns the number of replies on the post
|
"""Returns the number of replies on the post
|
||||||
This is recursive, so can handle replies to replies
|
This is recursive, so can handle replies to replies
|
||||||
|
@ -45,8 +37,8 @@ def noOfBlogReplies(baseDir: str,httpPrefix: str,translate: {}, \
|
||||||
tryPostBox = ('tlblogs', 'inbox', 'outbox')
|
tryPostBox = ('tlblogs', 'inbox', 'outbox')
|
||||||
boxFound = False
|
boxFound = False
|
||||||
for postBox in tryPostBox:
|
for postBox in tryPostBox:
|
||||||
postFilename= \
|
postFilename = baseDir + '/accounts/' + \
|
||||||
baseDir+'/accounts/'+nickname+'@'+domain+'/'+postBox+'/'+ \
|
nickname + '@' + domain + '/' + postBox + '/' + \
|
||||||
postId.replace('/', '#') + '.replies'
|
postId.replace('/', '#') + '.replies'
|
||||||
if os.path.isfile(postFilename):
|
if os.path.isfile(postFilename):
|
||||||
boxFound = True
|
boxFound = True
|
||||||
|
@ -54,8 +46,8 @@ def noOfBlogReplies(baseDir: str,httpPrefix: str,translate: {}, \
|
||||||
if not boxFound:
|
if not boxFound:
|
||||||
# post may exist but has no replies
|
# post may exist but has no replies
|
||||||
for postBox in tryPostBox:
|
for postBox in tryPostBox:
|
||||||
postFilename= \
|
postFilename = baseDir + '/accounts/' + \
|
||||||
baseDir+'/accounts/'+nickname+'@'+domain+'/'+postBox+'/'+ \
|
nickname + '@' + domain + '/' + postBox + '/' + \
|
||||||
postId.replace('/', '#')
|
postId.replace('/', '#')
|
||||||
if os.path.isfile(postFilename):
|
if os.path.isfile(postFilename):
|
||||||
return 1
|
return 1
|
||||||
|
@ -65,18 +57,16 @@ def noOfBlogReplies(baseDir: str,httpPrefix: str,translate: {}, \
|
||||||
with open(postFilename, "r") as f:
|
with open(postFilename, "r") as f:
|
||||||
lines = f.readlines()
|
lines = f.readlines()
|
||||||
for replyPostId in lines:
|
for replyPostId in lines:
|
||||||
replyPostId= \
|
replyPostId = replyPostId.replace('\n', '').replace('.json', '')
|
||||||
replyPostId.replace('\n','').replace('.json','').replace('.replies','')
|
replyPostId = replyPostId.replace('.replies', '')
|
||||||
replies+= \
|
replies += 1 + noOfBlogReplies(baseDir, httpPrefix, translate,
|
||||||
1+ \
|
nickname, domain, domainFull,
|
||||||
noOfBlogReplies(baseDir,httpPrefix,translate, \
|
|
||||||
nickname,domain,domainFull, \
|
|
||||||
replyPostId, depth+1)
|
replyPostId, depth+1)
|
||||||
return replies
|
return replies
|
||||||
|
|
||||||
|
|
||||||
def getBlogReplies(baseDir: str,httpPrefix: str,translate: {}, \
|
def getBlogReplies(baseDir: str, httpPrefix: str, translate: {},
|
||||||
nickname: str,domain: str,domainFull: str, \
|
nickname: str, domain: str, domainFull: str,
|
||||||
postId: str, depth=0) -> str:
|
postId: str, depth=0) -> str:
|
||||||
"""Returns the number of replies on the post
|
"""Returns the number of replies on the post
|
||||||
"""
|
"""
|
||||||
|
@ -88,8 +78,8 @@ def getBlogReplies(baseDir: str,httpPrefix: str,translate: {}, \
|
||||||
tryPostBox = ('tlblogs', 'inbox', 'outbox')
|
tryPostBox = ('tlblogs', 'inbox', 'outbox')
|
||||||
boxFound = False
|
boxFound = False
|
||||||
for postBox in tryPostBox:
|
for postBox in tryPostBox:
|
||||||
postFilename= \
|
postFilename = baseDir + '/accounts/' + \
|
||||||
baseDir+'/accounts/'+nickname+'@'+domain+'/'+postBox+'/'+ \
|
nickname + '@' + domain + '/' + postBox + '/' + \
|
||||||
postId.replace('/', '#') + '.replies'
|
postId.replace('/', '#') + '.replies'
|
||||||
if os.path.isfile(postFilename):
|
if os.path.isfile(postFilename):
|
||||||
boxFound = True
|
boxFound = True
|
||||||
|
@ -97,12 +87,12 @@ def getBlogReplies(baseDir: str,httpPrefix: str,translate: {}, \
|
||||||
if not boxFound:
|
if not boxFound:
|
||||||
# post may exist but has no replies
|
# post may exist but has no replies
|
||||||
for postBox in tryPostBox:
|
for postBox in tryPostBox:
|
||||||
postFilename= \
|
postFilename = baseDir + '/accounts/' + \
|
||||||
baseDir+'/accounts/'+nickname+'@'+domain+'/'+postBox+'/'+ \
|
nickname + '@' + domain + '/' + postBox + '/' + \
|
||||||
postId.replace('/', '#')
|
postId.replace('/', '#')
|
||||||
if os.path.isfile(postFilename):
|
if os.path.isfile(postFilename):
|
||||||
postFilename= \
|
postFilename = baseDir + '/accounts/' + \
|
||||||
baseDir+'/accounts/'+nickname+'@'+domain+ \
|
nickname + '@' + domain + \
|
||||||
'/postcache/' + \
|
'/postcache/' + \
|
||||||
postId.replace('/', '#') + '.html'
|
postId.replace('/', '#') + '.html'
|
||||||
if os.path.isfile(postFilename):
|
if os.path.isfile(postFilename):
|
||||||
|
@ -114,19 +104,18 @@ def getBlogReplies(baseDir: str,httpPrefix: str,translate: {}, \
|
||||||
lines = f.readlines()
|
lines = f.readlines()
|
||||||
repliesStr = ''
|
repliesStr = ''
|
||||||
for replyPostId in lines:
|
for replyPostId in lines:
|
||||||
replyPostId= \
|
replyPostId = replyPostId.replace('\n', '').replace('.json', '')
|
||||||
replyPostId.replace('\n','').replace('.json','').replace('.replies','')
|
replyPostId = replyPostId.replace('.replies', '')
|
||||||
postFilename= \
|
postFilename = baseDir + '/accounts/' + \
|
||||||
baseDir+'/accounts/'+nickname+'@'+domain+ \
|
nickname + '@' + domain + \
|
||||||
'/postcache/' + \
|
'/postcache/' + \
|
||||||
replyPostId.replace('\n', '').replace('/', '#') + '.html'
|
replyPostId.replace('\n', '').replace('/', '#') + '.html'
|
||||||
if not os.path.isfile(postFilename):
|
if not os.path.isfile(postFilename):
|
||||||
continue
|
continue
|
||||||
with open(postFilename, "r") as postFile:
|
with open(postFilename, "r") as postFile:
|
||||||
repliesStr += postFile.read() + '\n'
|
repliesStr += postFile.read() + '\n'
|
||||||
repliesStr+= \
|
repliesStr += getBlogReplies(baseDir, httpPrefix, translate,
|
||||||
getBlogReplies(baseDir,httpPrefix,translate, \
|
nickname, domain, domainFull,
|
||||||
nickname,domain,domainFull, \
|
|
||||||
replyPostId, depth+1)
|
replyPostId, depth+1)
|
||||||
|
|
||||||
# indicate the reply indentation level
|
# indicate the reply indentation level
|
||||||
|
@ -134,14 +123,15 @@ def getBlogReplies(baseDir: str,httpPrefix: str,translate: {}, \
|
||||||
for indentLevel in range(depth):
|
for indentLevel in range(depth):
|
||||||
indentStr += ' >'
|
indentStr += ' >'
|
||||||
|
|
||||||
return repliesStr.replace(translate['SHOW MORE'],indentStr).replace('?tl=outbox','?tl=tlblogs')
|
repliesStr = repliesStr.replace(translate['SHOW MORE'], indentStr)
|
||||||
|
return repliesStr.replace('?tl=outbox', '?tl=tlblogs')
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
|
||||||
def htmlBlogPostContent(authorized: bool, \
|
def htmlBlogPostContent(authorized: bool,
|
||||||
baseDir: str,httpPrefix: str,translate: {}, \
|
baseDir: str, httpPrefix: str, translate: {},
|
||||||
nickname: str,domain: str,domainFull: str, \
|
nickname: str, domain: str, domainFull: str,
|
||||||
postJsonObject: {}, \
|
postJsonObject: {},
|
||||||
handle: str, restrictToDomain: bool) -> str:
|
handle: str, restrictToDomain: bool) -> str:
|
||||||
"""Returns the content for a single blog post
|
"""Returns the content for a single blog post
|
||||||
"""
|
"""
|
||||||
|
@ -154,7 +144,8 @@ def htmlBlogPostContent(authorized: bool, \
|
||||||
titleStr = ''
|
titleStr = ''
|
||||||
if postJsonObject['object'].get('summary'):
|
if postJsonObject['object'].get('summary'):
|
||||||
titleStr = postJsonObject['object']['summary']
|
titleStr = postJsonObject['object']['summary']
|
||||||
blogStr+='<h1><a href="'+messageLink+'">'+titleStr+'</a></h1>\n'
|
blogStr += '<h1><a href="' + messageLink + '">' + \
|
||||||
|
titleStr + '</a></h1>\n'
|
||||||
|
|
||||||
# get the handle of the author
|
# get the handle of the author
|
||||||
if postJsonObject['object'].get('attributedTo'):
|
if postJsonObject['object'].get('attributedTo'):
|
||||||
|
@ -174,17 +165,18 @@ def htmlBlogPostContent(authorized: bool, \
|
||||||
|
|
||||||
if postJsonObject['object'].get('published'):
|
if postJsonObject['object'].get('published'):
|
||||||
if 'T' in postJsonObject['object']['published']:
|
if 'T' in postJsonObject['object']['published']:
|
||||||
blogStr+='<h3>'+postJsonObject['object']['published'].split('T')[0]
|
blogStr += '<h3>' + \
|
||||||
|
postJsonObject['object']['published'].split('T')[0]
|
||||||
if handle:
|
if handle:
|
||||||
if handle.startswith(nickname + '@' + domain):
|
if handle.startswith(nickname + '@' + domain):
|
||||||
blogStr+= \
|
blogStr += ' <a href="' + httpPrefix + '://' + \
|
||||||
' <a href="'+httpPrefix+'://'+domainFull+ \
|
domainFull + \
|
||||||
'/users/' + nickname + '">' + handle + '</a>'
|
'/users/' + nickname + '">' + handle + '</a>'
|
||||||
linkedAuthor = True
|
linkedAuthor = True
|
||||||
else:
|
else:
|
||||||
if author:
|
if actor:
|
||||||
blogStr+= \
|
blogStr += ' <a href="' + actor + '">' + \
|
||||||
' <a href="'+author+'">'+handle+'</a>'
|
handle + '</a>'
|
||||||
linkedAuthor = True
|
linkedAuthor = True
|
||||||
else:
|
else:
|
||||||
blogStr += ' ' + handle
|
blogStr += ' ' + handle
|
||||||
|
@ -198,62 +190,59 @@ def htmlBlogPostContent(authorized: bool, \
|
||||||
deleteStr = ''
|
deleteStr = ''
|
||||||
muteStr = ''
|
muteStr = ''
|
||||||
isMuted = False
|
isMuted = False
|
||||||
attachmentStr,galleryStr= \
|
attachmentStr, galleryStr = getPostAttachmentsAsHtml(postJsonObject,
|
||||||
getPostAttachmentsAsHtml(postJsonObject,'tlblogs',translate, \
|
'tlblogs', translate,
|
||||||
isMuted,avatarLink, \
|
isMuted, avatarLink,
|
||||||
replyStr,announceStr,likeStr, \
|
replyStr, announceStr,
|
||||||
bookmarkStr,deleteStr,muteStr)
|
likeStr, bookmarkStr,
|
||||||
|
deleteStr, muteStr)
|
||||||
if attachmentStr:
|
if attachmentStr:
|
||||||
blogStr += '<br><center>' + attachmentStr + '</center>'
|
blogStr += '<br><center>' + attachmentStr + '</center>'
|
||||||
|
|
||||||
if postJsonObject['object'].get('content'):
|
if postJsonObject['object'].get('content'):
|
||||||
contentStr= \
|
contentStr = addEmbeddedElements(translate,
|
||||||
addEmbeddedElements(translate, \
|
|
||||||
postJsonObject['object']['content'])
|
postJsonObject['object']['content'])
|
||||||
if postJsonObject['object'].get('tag'):
|
if postJsonObject['object'].get('tag'):
|
||||||
contentStr= \
|
contentStr = replaceEmojiFromTags(contentStr,
|
||||||
replaceEmojiFromTags(contentStr, \
|
postJsonObject['object']['tag'],
|
||||||
postJsonObject['object']['tag'],'content')
|
'content')
|
||||||
blogStr += '<br>' + contentStr + '\n'
|
blogStr += '<br>' + contentStr + '\n'
|
||||||
|
|
||||||
blogStr += '<br><hr>\n'
|
blogStr += '<br><hr>\n'
|
||||||
|
|
||||||
if not linkedAuthor:
|
if not linkedAuthor:
|
||||||
blogStr+= \
|
blogStr += '<p class="about"><a class="about" href="' + \
|
||||||
'<p class="about"><a class="about" href="'+ \
|
|
||||||
httpPrefix + '://' + domainFull + \
|
httpPrefix + '://' + domainFull + \
|
||||||
'/users/'+nickname+'">'+translate['About the author']+'</a></p>\n'
|
'/users/' + nickname + '">' + translate['About the author'] + \
|
||||||
|
'</a></p>\n'
|
||||||
|
|
||||||
replies= \
|
replies = noOfBlogReplies(baseDir, httpPrefix, translate,
|
||||||
noOfBlogReplies(baseDir,httpPrefix,translate, \
|
nickname, domain, domainFull,
|
||||||
nickname,domain,domainFull, \
|
|
||||||
postJsonObject['object']['id'])
|
postJsonObject['object']['id'])
|
||||||
if replies > 0:
|
if replies > 0:
|
||||||
if not authorized:
|
if not authorized:
|
||||||
blogStr+= \
|
blogStr += '<p class="blogreplies">' + \
|
||||||
'<p class="blogreplies">'+ \
|
|
||||||
translate['Replies'].lower() + ': ' + str(replies) + '</p>\n'
|
translate['Replies'].lower() + ': ' + str(replies) + '</p>\n'
|
||||||
else:
|
else:
|
||||||
blogStr += '<h1>' + translate['Replies'] + '</h1>\n'
|
blogStr += '<h1>' + translate['Replies'] + '</h1>\n'
|
||||||
blogStr += '<script>' + contentWarningScriptOpen() + '</script>\n'
|
blogStr += '<script>' + contentWarningScriptOpen() + '</script>\n'
|
||||||
if not titleStr:
|
if not titleStr:
|
||||||
blogStr+= \
|
blogStr += getBlogReplies(baseDir, httpPrefix, translate,
|
||||||
getBlogReplies(baseDir,httpPrefix,translate, \
|
nickname, domain, domainFull,
|
||||||
nickname,domain,domainFull, \
|
|
||||||
postJsonObject['object']['id'])
|
postJsonObject['object']['id'])
|
||||||
else:
|
else:
|
||||||
blogStr+= \
|
blogRepliesStr = getBlogReplies(baseDir, httpPrefix, translate,
|
||||||
getBlogReplies(baseDir,httpPrefix,translate, \
|
nickname, domain, domainFull,
|
||||||
nickname,domain,domainFull, \
|
postJsonObject['object']['id'])
|
||||||
postJsonObject['object']['id']).replace('>'+titleStr+'<','')
|
blogStr += blogRepliesStr.replace('>' + titleStr + '<', '')
|
||||||
blogStr += '<br><hr>\n'
|
blogStr += '<br><hr>\n'
|
||||||
return blogStr
|
return blogStr
|
||||||
|
|
||||||
|
|
||||||
def htmlBlogPostRSS(authorized: bool, \
|
def htmlBlogPostRSS(authorized: bool,
|
||||||
baseDir: str,httpPrefix: str,translate: {}, \
|
baseDir: str, httpPrefix: str, translate: {},
|
||||||
nickname: str,domain: str,domainFull: str, \
|
nickname: str, domain: str, domainFull: str,
|
||||||
postJsonObject: {}, \
|
postJsonObject: {},
|
||||||
handle: str, restrictToDomain: bool) -> str:
|
handle: str, restrictToDomain: bool) -> str:
|
||||||
"""Returns the RSS feed for a single blog post
|
"""Returns the RSS feed for a single blog post
|
||||||
"""
|
"""
|
||||||
|
@ -266,17 +255,18 @@ def htmlBlogPostRSS(authorized: bool, \
|
||||||
published = postJsonObject['object']['published']
|
published = postJsonObject['object']['published']
|
||||||
pubDate = datetime.strptime(published, "%Y-%m-%dT%H:%M:%SZ")
|
pubDate = datetime.strptime(published, "%Y-%m-%dT%H:%M:%SZ")
|
||||||
titleStr = postJsonObject['object']['summary']
|
titleStr = postJsonObject['object']['summary']
|
||||||
|
rssDateStr = pubDate.strftime("%a, %d %b %Y %H:%M:%S UT")
|
||||||
rssStr = ' <item>'
|
rssStr = ' <item>'
|
||||||
rssStr += ' <title>' + titleStr + '</title>'
|
rssStr += ' <title>' + titleStr + '</title>'
|
||||||
rssStr += ' <link>' + messageLink + '</link>'
|
rssStr += ' <link>' + messageLink + '</link>'
|
||||||
rssStr+=' <pubDate>'+pubDate.strftime("%a, %d %b %Y %H:%M:%S UT")+'</pubDate>'
|
rssStr += ' <pubDate>' + rssDateStr + '</pubDate>'
|
||||||
rssStr += ' </item>'
|
rssStr += ' </item>'
|
||||||
return rssStr
|
return rssStr
|
||||||
|
|
||||||
|
|
||||||
def htmlBlogPost(authorized: bool, \
|
def htmlBlogPost(authorized: bool,
|
||||||
baseDir: str,httpPrefix: str,translate: {}, \
|
baseDir: str, httpPrefix: str, translate: {},
|
||||||
nickname: str,domain: str,domainFull: str, \
|
nickname: str, domain: str, domainFull: str,
|
||||||
postJsonObject: {}) -> str:
|
postJsonObject: {}) -> str:
|
||||||
"""Returns a html blog post
|
"""Returns a html blog post
|
||||||
"""
|
"""
|
||||||
|
@ -290,24 +280,28 @@ def htmlBlogPost(authorized: bool, \
|
||||||
blogStr = htmlHeader(cssFilename, blogCSS)
|
blogStr = htmlHeader(cssFilename, blogCSS)
|
||||||
blogStr = blogStr.replace('.cwText', '.cwTextInactive')
|
blogStr = blogStr.replace('.cwText', '.cwTextInactive')
|
||||||
|
|
||||||
blogStr+= \
|
blogStr += htmlBlogPostContent(authorized, baseDir,
|
||||||
htmlBlogPostContent(authorized,baseDir,httpPrefix,translate, \
|
httpPrefix, translate,
|
||||||
nickname,domain,domainFull,postJsonObject, \
|
nickname, domain,
|
||||||
|
domainFull, postJsonObject,
|
||||||
None, False)
|
None, False)
|
||||||
|
|
||||||
# show rss link
|
# show rss link
|
||||||
iconsDir = getIconsDir(baseDir)
|
iconsDir = getIconsDir(baseDir)
|
||||||
blogStr += '<p class="rssfeed">'
|
blogStr += '<p class="rssfeed">'
|
||||||
blogStr+='<a href="'+httpPrefix+'://'+domainFull+'/blog/'+nickname+'/rss.xml">'
|
blogStr += '<a href="' + httpPrefix + '://' + \
|
||||||
blogStr+='<img loading="lazy" alt="RSS" title="RSS" src="/'+iconsDir+'/rss.png" />'
|
domainFull + '/blog/' + nickname + '/rss.xml">'
|
||||||
|
blogStr += '<img loading="lazy" alt="RSS" title="RSS" src="/' + \
|
||||||
|
iconsDir + '/rss.png" />'
|
||||||
blogStr += '</a></p>'
|
blogStr += '</a></p>'
|
||||||
|
|
||||||
return blogStr + htmlFooter()
|
return blogStr + htmlFooter()
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def htmlBlogPage(authorized: bool, session, \
|
|
||||||
baseDir: str,httpPrefix: str,translate: {}, \
|
def htmlBlogPage(authorized: bool, session,
|
||||||
nickname: str,domain: str,port: int, \
|
baseDir: str, httpPrefix: str, translate: {},
|
||||||
|
nickname: str, domain: str, port: int,
|
||||||
noOfItems: int, pageNumber: int) -> str:
|
noOfItems: int, pageNumber: int) -> str:
|
||||||
"""Returns a html blog page containing posts
|
"""Returns a html blog page containing posts
|
||||||
"""
|
"""
|
||||||
|
@ -323,15 +317,16 @@ def htmlBlogPage(authorized: bool, session, \
|
||||||
blogStr = htmlHeader(cssFilename, blogCSS)
|
blogStr = htmlHeader(cssFilename, blogCSS)
|
||||||
blogStr = blogStr.replace('.cwText', '.cwTextInactive')
|
blogStr = blogStr.replace('.cwText', '.cwTextInactive')
|
||||||
|
|
||||||
blogsIndex= \
|
blogsIndex = baseDir + '/accounts/' + \
|
||||||
baseDir+'/accounts/'+nickname+'@'+domain+'/tlblogs.index'
|
nickname + '@' + domain + '/tlblogs.index'
|
||||||
if not os.path.isfile(blogsIndex):
|
if not os.path.isfile(blogsIndex):
|
||||||
return blogStr + htmlFooter()
|
return blogStr + htmlFooter()
|
||||||
|
|
||||||
timelineJson= \
|
timelineJson = createBlogsTimeline(session, baseDir,
|
||||||
createBlogsTimeline(session,baseDir, \
|
nickname, domain, port,
|
||||||
nickname,domain,port,httpPrefix, \
|
httpPrefix,
|
||||||
noOfItems,False,False,pageNumber)
|
noOfItems, False, False,
|
||||||
|
pageNumber)
|
||||||
|
|
||||||
if not timelineJson:
|
if not timelineJson:
|
||||||
return blogStr + htmlFooter()
|
return blogStr + htmlFooter()
|
||||||
|
@ -342,21 +337,21 @@ def htmlBlogPage(authorized: bool, session, \
|
||||||
domainFull = domain + ':' + str(port)
|
domainFull = domain + ':' + str(port)
|
||||||
|
|
||||||
# show previous and next buttons
|
# show previous and next buttons
|
||||||
if pageNumber!=None:
|
if pageNumber is not None:
|
||||||
iconsDir = getIconsDir(baseDir)
|
iconsDir = getIconsDir(baseDir)
|
||||||
navigateStr = '<p>'
|
navigateStr = '<p>'
|
||||||
if pageNumber > 1:
|
if pageNumber > 1:
|
||||||
# show previous button
|
# show previous button
|
||||||
navigateStr+= \
|
navigateStr += '<a href="' + httpPrefix + '://' + \
|
||||||
'<a href="'+httpPrefix+'://'+domainFull+'/blog/'+ \
|
domainFull + '/blog/' + \
|
||||||
nickname + '?page=' + str(pageNumber-1) + '">' + \
|
nickname + '?page=' + str(pageNumber-1) + '">' + \
|
||||||
'<img loading="lazy" alt="<" title="<" ' + \
|
'<img loading="lazy" alt="<" title="<" ' + \
|
||||||
'src="/' + iconsDir + \
|
'src="/' + iconsDir + \
|
||||||
'/prev.png" class="buttonprev"/></a>\n'
|
'/prev.png" class="buttonprev"/></a>\n'
|
||||||
if len(timelineJson['orderedItems']) >= noOfItems:
|
if len(timelineJson['orderedItems']) >= noOfItems:
|
||||||
# show next button
|
# show next button
|
||||||
navigateStr+= \
|
navigateStr += '<a href="' + httpPrefix + '://' + \
|
||||||
'<a href="'+httpPrefix+'://'+domainFull+'/blog/'+nickname+ \
|
domainFull + '/blog/' + nickname + \
|
||||||
'?page=' + str(pageNumber + 1) + '">' + \
|
'?page=' + str(pageNumber + 1) + '">' + \
|
||||||
'<img loading="lazy" alt=">" title=">" ' + \
|
'<img loading="lazy" alt=">" title=">" ' + \
|
||||||
'src="/' + iconsDir + \
|
'src="/' + iconsDir + \
|
||||||
|
@ -368,9 +363,10 @@ def htmlBlogPage(authorized: bool, session, \
|
||||||
if item['type'] != 'Create':
|
if item['type'] != 'Create':
|
||||||
continue
|
continue
|
||||||
|
|
||||||
blogStr+= \
|
blogStr += htmlBlogPostContent(authorized, baseDir,
|
||||||
htmlBlogPostContent(authorized,baseDir,httpPrefix,translate, \
|
httpPrefix, translate,
|
||||||
nickname,domain,domainFull,item, \
|
nickname, domain,
|
||||||
|
domainFull, item,
|
||||||
None, True)
|
None, True)
|
||||||
|
|
||||||
if len(timelineJson['orderedItems']) >= noOfItems:
|
if len(timelineJson['orderedItems']) >= noOfItems:
|
||||||
|
@ -378,29 +374,36 @@ def htmlBlogPage(authorized: bool, session, \
|
||||||
|
|
||||||
# show rss link
|
# show rss link
|
||||||
blogStr += '<p class="rssfeed">'
|
blogStr += '<p class="rssfeed">'
|
||||||
blogStr+='<a href="'+httpPrefix+'://'+domainFull+'/blog/'+nickname+'/rss.xml">'
|
blogStr += '<a href="' + httpPrefix + '://' + \
|
||||||
blogStr+='<img loading="lazy" alt="RSS" title="RSS" src="/'+iconsDir+'/rss.png" />'
|
domainFull + '/blog/' + nickname + '/rss.xml">'
|
||||||
|
blogStr += '<img loading="lazy" alt="RSS" title="RSS" src="/' + \
|
||||||
|
iconsDir + '/rss.png" />'
|
||||||
blogStr += '</a></p>'
|
blogStr += '</a></p>'
|
||||||
|
|
||||||
return blogStr + htmlFooter()
|
return blogStr + htmlFooter()
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def rssHeader(httpPrefix: str,nickname: str,domainFull: str,translate: {}) -> str:
|
|
||||||
|
def rssHeader(httpPrefix: str,
|
||||||
|
nickname: str, domainFull: str, translate: {}) -> str:
|
||||||
rssStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"
|
rssStr = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"
|
||||||
rssStr += "<rss version=\"2.0\">"
|
rssStr += "<rss version=\"2.0\">"
|
||||||
rssStr += '<channel>'
|
rssStr += '<channel>'
|
||||||
rssStr += ' <title>' + translate['Blog'] + '</title>'
|
rssStr += ' <title>' + translate['Blog'] + '</title>'
|
||||||
rssStr+=' <link>'+httpPrefix+'://'+domainFull+'/users/'+nickname+'/rss.xml'+'</link>'
|
rssStr += ' <link>' + httpPrefix + '://' + domainFull + \
|
||||||
|
'/users/' + nickname + '/rss.xml' + '</link>'
|
||||||
return rssStr
|
return rssStr
|
||||||
|
|
||||||
|
|
||||||
def rssFooter() -> str:
|
def rssFooter() -> str:
|
||||||
rssStr = '</channel>'
|
rssStr = '</channel>'
|
||||||
rssStr += '</rss>'
|
rssStr += '</rss>'
|
||||||
return rssStr
|
return rssStr
|
||||||
|
|
||||||
def htmlBlogPageRSS(authorized: bool, session, \
|
|
||||||
baseDir: str,httpPrefix: str,translate: {}, \
|
def htmlBlogPageRSS(authorized: bool, session,
|
||||||
nickname: str,domain: str,port: int, \
|
baseDir: str, httpPrefix: str, translate: {},
|
||||||
|
nickname: str, domain: str, port: int,
|
||||||
noOfItems: int, pageNumber: int) -> str:
|
noOfItems: int, pageNumber: int) -> str:
|
||||||
"""Returns an rss feed containing posts
|
"""Returns an rss feed containing posts
|
||||||
"""
|
"""
|
||||||
|
@ -414,27 +417,29 @@ def htmlBlogPageRSS(authorized: bool, session, \
|
||||||
|
|
||||||
blogRSS = rssHeader(httpPrefix, nickname, domainFull, translate)
|
blogRSS = rssHeader(httpPrefix, nickname, domainFull, translate)
|
||||||
|
|
||||||
blogsIndex= \
|
blogsIndex = baseDir + '/accounts/' + \
|
||||||
baseDir+'/accounts/'+nickname+'@'+domain+'/tlblogs.index'
|
nickname + '@' + domain + '/tlblogs.index'
|
||||||
if not os.path.isfile(blogsIndex):
|
if not os.path.isfile(blogsIndex):
|
||||||
return blogRSS + rssFooter()
|
return blogRSS + rssFooter()
|
||||||
|
|
||||||
timelineJson= \
|
timelineJson = createBlogsTimeline(session, baseDir,
|
||||||
createBlogsTimeline(session,baseDir, \
|
nickname, domain, port,
|
||||||
nickname,domain,port,httpPrefix, \
|
httpPrefix,
|
||||||
noOfItems,False,False,pageNumber)
|
noOfItems, False, False,
|
||||||
|
pageNumber)
|
||||||
|
|
||||||
if not timelineJson:
|
if not timelineJson:
|
||||||
return blogRSS + rssFooter()
|
return blogRSS + rssFooter()
|
||||||
|
|
||||||
if pageNumber!=None:
|
if pageNumber is not None:
|
||||||
for item in timelineJson['orderedItems']:
|
for item in timelineJson['orderedItems']:
|
||||||
if item['type'] != 'Create':
|
if item['type'] != 'Create':
|
||||||
continue
|
continue
|
||||||
|
|
||||||
blogRSS+= \
|
blogRSS += htmlBlogPostRSS(authorized, baseDir,
|
||||||
htmlBlogPostRSS(authorized,baseDir,httpPrefix,translate, \
|
httpPrefix, translate,
|
||||||
nickname,domain,domainFull,item, \
|
nickname, domain,
|
||||||
|
domainFull, item,
|
||||||
None, True)
|
None, True)
|
||||||
|
|
||||||
return blogRSS + rssFooter()
|
return blogRSS + rssFooter()
|
||||||
|
@ -457,6 +462,7 @@ def getBlogIndexesForAccounts(baseDir: str) -> {}:
|
||||||
blogIndexes[acct] = blogsIndex
|
blogIndexes[acct] = blogsIndex
|
||||||
return blogIndexes
|
return blogIndexes
|
||||||
|
|
||||||
|
|
||||||
def noOfBlogAccounts(baseDir: str) -> int:
|
def noOfBlogAccounts(baseDir: str) -> int:
|
||||||
"""Returns the number of blog accounts
|
"""Returns the number of blog accounts
|
||||||
"""
|
"""
|
||||||
|
@ -473,6 +479,7 @@ def noOfBlogAccounts(baseDir: str) -> int:
|
||||||
ctr += 1
|
ctr += 1
|
||||||
return ctr
|
return ctr
|
||||||
|
|
||||||
|
|
||||||
def singleBlogAccountNickname(baseDir: str) -> str:
|
def singleBlogAccountNickname(baseDir: str) -> str:
|
||||||
"""Returns the nickname of a single blog account
|
"""Returns the nickname of a single blog account
|
||||||
"""
|
"""
|
||||||
|
@ -488,9 +495,10 @@ def singleBlogAccountNickname(baseDir: str) -> str:
|
||||||
return acct.split('@')[0]
|
return acct.split('@')[0]
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def htmlBlogView(authorized: bool, \
|
|
||||||
session,baseDir: str,httpPrefix: str, \
|
def htmlBlogView(authorized: bool,
|
||||||
translate: {},domain: str,port: int, \
|
session, baseDir: str, httpPrefix: str,
|
||||||
|
translate: {}, domain: str, port: int,
|
||||||
noOfItems: int) -> str:
|
noOfItems: int) -> str:
|
||||||
"""Show the blog main page
|
"""Show the blog main page
|
||||||
"""
|
"""
|
||||||
|
@ -506,9 +514,9 @@ def htmlBlogView(authorized: bool, \
|
||||||
if noOfBlogAccounts(baseDir) <= 1:
|
if noOfBlogAccounts(baseDir) <= 1:
|
||||||
nickname = singleBlogAccountNickname(baseDir)
|
nickname = singleBlogAccountNickname(baseDir)
|
||||||
if nickname:
|
if nickname:
|
||||||
return htmlBlogPage(authorized,session, \
|
return htmlBlogPage(authorized, session,
|
||||||
baseDir,httpPrefix,translate, \
|
baseDir, httpPrefix, translate,
|
||||||
nickname,domain,port, \
|
nickname, domain, port,
|
||||||
noOfItems, 1)
|
noOfItems, 1)
|
||||||
|
|
||||||
domainFull = domain
|
domainFull = domain
|
||||||
|
@ -526,8 +534,7 @@ def htmlBlogView(authorized: bool, \
|
||||||
blogsIndex = accountDir + '/tlblogs.index'
|
blogsIndex = accountDir + '/tlblogs.index'
|
||||||
if os.path.isfile(blogsIndex):
|
if os.path.isfile(blogsIndex):
|
||||||
blogStr += '<p class="blogaccount">'
|
blogStr += '<p class="blogaccount">'
|
||||||
blogStr+= \
|
blogStr += '<a href="' + \
|
||||||
'<a href="'+ \
|
|
||||||
httpPrefix + '://' + domainFull + '/blog/' + \
|
httpPrefix + '://' + domainFull + '/blog/' + \
|
||||||
acct.split('@')[0] + '">' + acct + '</a>'
|
acct.split('@')[0] + '">' + acct + '</a>'
|
||||||
blogStr += '</p>'
|
blogStr += '</p>'
|
||||||
|
@ -535,11 +542,12 @@ def htmlBlogView(authorized: bool, \
|
||||||
return blogStr + htmlFooter()
|
return blogStr + htmlFooter()
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def htmlEditBlog(mediaInstance: bool,translate: {}, \
|
|
||||||
baseDir: str,httpPrefix: str, \
|
def htmlEditBlog(mediaInstance: bool, translate: {},
|
||||||
path: str, \
|
baseDir: str, httpPrefix: str,
|
||||||
pageNumber: int, \
|
path: str,
|
||||||
nickname: str,domain: str, \
|
pageNumber: int,
|
||||||
|
nickname: str, domain: str,
|
||||||
postUrl: str) -> str:
|
postUrl: str) -> str:
|
||||||
"""Edit a blog post after it was created
|
"""Edit a blog post after it was created
|
||||||
"""
|
"""
|
||||||
|
@ -555,8 +563,7 @@ def htmlEditBlog(mediaInstance: bool,translate: {}, \
|
||||||
|
|
||||||
iconsDir = getIconsDir(baseDir)
|
iconsDir = getIconsDir(baseDir)
|
||||||
|
|
||||||
editBlogText= \
|
editBlogText = '<p class="new-post-text">' + \
|
||||||
'<p class="new-post-text">'+ \
|
|
||||||
translate['Write your post text below.'] + '</p>'
|
translate['Write your post text below.'] + '</p>'
|
||||||
|
|
||||||
if os.path.isfile(baseDir + '/accounts/newpost.txt'):
|
if os.path.isfile(baseDir + '/accounts/newpost.txt'):
|
||||||
|
@ -576,7 +583,8 @@ def htmlEditBlog(mediaInstance: bool,translate: {}, \
|
||||||
pathBase = path
|
pathBase = path
|
||||||
|
|
||||||
editBlogImageSection = ' <div class="container">'
|
editBlogImageSection = ' <div class="container">'
|
||||||
editBlogImageSection+=' <label class="labels">'+translate['Image description']+'</label>'
|
editBlogImageSection += ' <label class="labels">' + \
|
||||||
|
translate['Image description'] + '</label>'
|
||||||
editBlogImageSection += ' <input type="text" name="imageDescription">'
|
editBlogImageSection += ' <input type="text" name="imageDescription">'
|
||||||
editBlogImageSection += ' <input type="file" id="attachpic" name="attachpic"'
|
editBlogImageSection += ' <input type="file" id="attachpic" name="attachpic"'
|
||||||
editBlogImageSection += ' accept=".png, .jpg, .jpeg, .gif, .webp, .mp4, .webm, .ogv, .mp3, .ogg">'
|
editBlogImageSection += ' accept=".png, .jpg, .jpeg, .gif, .webp, .mp4, .webm, .ogv, .mp3, .ogg">'
|
||||||
|
@ -591,12 +599,10 @@ def htmlEditBlog(mediaInstance: bool,translate: {}, \
|
||||||
dateAndLocation = ''
|
dateAndLocation = ''
|
||||||
dateAndLocation = '<div class="container">'
|
dateAndLocation = '<div class="container">'
|
||||||
|
|
||||||
dateAndLocation+= \
|
dateAndLocation += '<p><input type="checkbox" class="profilecheckbox" name="schedulePost"><label class="labels">' + \
|
||||||
'<p><input type="checkbox" class="profilecheckbox" name="schedulePost"><label class="labels">'+ \
|
|
||||||
translate['This is a scheduled post.'] + '</label></p>'
|
translate['This is a scheduled post.'] + '</label></p>'
|
||||||
|
|
||||||
dateAndLocation+= \
|
dateAndLocation += '<p><img loading="lazy" alt="" title="" class="emojicalendar" src="/' + \
|
||||||
'<p><img loading="lazy" alt="" title="" class="emojicalendar" src="/'+ \
|
|
||||||
iconsDir + '/calendar.png"/>'
|
iconsDir + '/calendar.png"/>'
|
||||||
dateAndLocation += '<label class="labels">' + translate['Date'] + ': </label>'
|
dateAndLocation += '<label class="labels">' + translate['Date'] + ': </label>'
|
||||||
dateAndLocation += '<input type="date" name="eventDate">'
|
dateAndLocation += '<input type="date" name="eventDate">'
|
||||||
|
@ -610,10 +616,7 @@ def htmlEditBlog(mediaInstance: bool,translate: {}, \
|
||||||
|
|
||||||
editBlogForm = htmlHeader(cssFilename, editBlogCSS)
|
editBlogForm = htmlHeader(cssFilename, editBlogCSS)
|
||||||
|
|
||||||
mentionsStr=''
|
editBlogForm += '<form enctype="multipart/form-data" method="POST" accept-charset="UTF-8" action="' + \
|
||||||
|
|
||||||
editBlogForm+= \
|
|
||||||
'<form enctype="multipart/form-data" method="POST" accept-charset="UTF-8" action="'+ \
|
|
||||||
pathBase + '?' + endpoint + '?page=' + str(pageNumber) + '">'
|
pathBase + '?' + endpoint + '?page=' + str(pageNumber) + '">'
|
||||||
editBlogForm += ' <input type="hidden" name="postUrl" value="' + postUrl + '">'
|
editBlogForm += ' <input type="hidden" name="postUrl" value="' + postUrl + '">'
|
||||||
editBlogForm += ' <input type="hidden" name="pageNumber" value="' + str(pageNumber) + '">'
|
editBlogForm += ' <input type="hidden" name="pageNumber" value="' + str(pageNumber) + '">'
|
||||||
|
@ -622,47 +625,38 @@ def htmlEditBlog(mediaInstance: bool,translate: {}, \
|
||||||
editBlogForm += ' <div class="container">'
|
editBlogForm += ' <div class="container">'
|
||||||
|
|
||||||
editBlogForm += ' <div class="dropbtn">'
|
editBlogForm += ' <div class="dropbtn">'
|
||||||
editBlogForm+= \
|
editBlogForm += ' <img loading="lazy" alt="" title="" src="/' + iconsDir + \
|
||||||
' <img loading="lazy" alt="" title="" src="/'+iconsDir+ \
|
|
||||||
'/' + scopeIcon + '"/><b class="scope-desc">' + scopeDescription + '</b>'
|
'/' + scopeIcon + '"/><b class="scope-desc">' + scopeDescription + '</b>'
|
||||||
editBlogForm += ' </div>'
|
editBlogForm += ' </div>'
|
||||||
|
|
||||||
editBlogForm+= \
|
editBlogForm += ' <a href="' + pathBase + \
|
||||||
' <a href="'+pathBase+ \
|
|
||||||
'/searchemoji"><img loading="lazy" ' + \
|
'/searchemoji"><img loading="lazy" ' + \
|
||||||
'class="emojisearch" src="/emoji/1F601.png" title="' + \
|
'class="emojisearch" src="/emoji/1F601.png" title="' + \
|
||||||
translate['Search for emoji'] + '" alt="' + \
|
translate['Search for emoji'] + '" alt="' + \
|
||||||
translate['Search for emoji'] + '"/></a>'
|
translate['Search for emoji'] + '"/></a>'
|
||||||
editBlogForm += ' </div>'
|
editBlogForm += ' </div>'
|
||||||
editBlogForm += ' <div class="container"><center>'
|
editBlogForm += ' <div class="container"><center>'
|
||||||
editBlogForm+= \
|
editBlogForm += ' <a href="' + pathBase + \
|
||||||
' <a href="'+pathBase+ \
|
|
||||||
'/inbox"><button class="cancelbtn">' + \
|
'/inbox"><button class="cancelbtn">' + \
|
||||||
translate['Cancel'] + '</button></a>'
|
translate['Cancel'] + '</button></a>'
|
||||||
editBlogForm+= \
|
editBlogForm += ' <input type="submit" name="submitPost" value="' + \
|
||||||
' <input type="submit" name="submitPost" value="'+ \
|
|
||||||
translate['Submit'] + '">'
|
translate['Submit'] + '">'
|
||||||
editBlogForm += ' </center></div>'
|
editBlogForm += ' </center></div>'
|
||||||
if mediaInstance:
|
if mediaInstance:
|
||||||
editBlogForm += editBlogImageSection
|
editBlogForm += editBlogImageSection
|
||||||
editBlogForm+= \
|
editBlogForm += ' <label class="labels">' + placeholderSubject + '</label><br>'
|
||||||
' <label class="labels">'+placeholderSubject+'</label><br>'
|
|
||||||
titleStr = ''
|
titleStr = ''
|
||||||
if postJsonObject['object'].get('summary'):
|
if postJsonObject['object'].get('summary'):
|
||||||
titleStr = postJsonObject['object']['summary']
|
titleStr = postJsonObject['object']['summary']
|
||||||
editBlogForm+= \
|
editBlogForm += ' <input type="text" name="subject" value="' + titleStr + '">'
|
||||||
' <input type="text" name="subject" value="'+titleStr+'">'
|
|
||||||
editBlogForm += ''
|
editBlogForm += ''
|
||||||
editBlogForm+= \
|
editBlogForm += ' <br><label class="labels">' + \
|
||||||
' <br><label class="labels">'+ \
|
|
||||||
placeholderMessage + '</label>'
|
placeholderMessage + '</label>'
|
||||||
messageBoxHeight = 800
|
messageBoxHeight = 800
|
||||||
|
|
||||||
contentStr= \
|
contentStr = postJsonObject['object']['content'].replace('<p>', '').replace('</p>', '\n')
|
||||||
postJsonObject['object']['content'].replace('<p>','').replace('</p>','\n')
|
|
||||||
|
|
||||||
editBlogForm+= \
|
editBlogForm += ' <textarea id="message" name="message" style="height:' + \
|
||||||
' <textarea id="message" name="message" style="height:'+ \
|
|
||||||
str(messageBoxHeight) + 'px">' + contentStr + '</textarea>'
|
str(messageBoxHeight) + 'px">' + contentStr + '</textarea>'
|
||||||
editBlogForm += dateAndLocation
|
editBlogForm += dateAndLocation
|
||||||
if not mediaInstance:
|
if not mediaInstance:
|
||||||
|
@ -670,8 +664,8 @@ def htmlEditBlog(mediaInstance: bool,translate: {}, \
|
||||||
editBlogForm += ' </div>'
|
editBlogForm += ' </div>'
|
||||||
editBlogForm += '</form>'
|
editBlogForm += '</form>'
|
||||||
|
|
||||||
editBlogForm= \
|
editBlogForm = editBlogForm.replace('<body>',
|
||||||
editBlogForm.replace('<body>','<body onload="focusOnMessage()">')
|
'<body onload="focusOnMessage()">')
|
||||||
|
|
||||||
editBlogForm += htmlFooter()
|
editBlogForm += htmlFooter()
|
||||||
return editBlogForm
|
return editBlogForm
|
||||||
|
|
Loading…
Reference in New Issue