epicyon/webinterface.py

585 lines
26 KiB
Python
Raw Normal View History

2019-07-20 21:13:36 +00:00
__filename__ = "webinterface.py"
__author__ = "Bob Mottram"
__license__ = "AGPL3+"
__version__ = "0.0.1"
__maintainer__ = "Bob Mottram"
__email__ = "bob@freedombone.net"
__status__ = "Production"
import json
2019-07-24 22:38:42 +00:00
import time
import os
from shutil import copyfile
from pprint import pprint
2019-07-21 22:38:44 +00:00
from person import personBoxJson
2019-07-21 12:41:31 +00:00
from utils import getNicknameFromActor
from utils import getDomainFromActor
2019-07-22 14:09:21 +00:00
from posts import getPersonBox
2019-07-20 21:13:36 +00:00
2019-07-25 10:56:24 +00:00
def htmlGetLoginCredentials(loginParams: str,lastLoginTime: int) -> (str,str):
"""Receives login credentials via HTTPServer POST
2019-07-24 22:38:42 +00:00
"""
2019-07-25 10:56:24 +00:00
if not loginParams.startswith('username='):
2019-07-24 22:38:42 +00:00
return None,None
# minimum time between login attempts
currTime=int(time.time())
if currTime<lastLoginTime+5:
return None,None
if '&' not in loginParams:
return None,None
loginArgs=loginParams.split('&')
nickname=None
password=None
for arg in loginArgs:
if '=' in arg:
2019-07-25 10:56:24 +00:00
if arg.split('=',1)[0]=='username':
2019-07-24 22:38:42 +00:00
nickname=arg.split('=',1)[1]
elif arg.split('=',1)[0]=='password':
password=arg.split('=',1)[1]
return nickname,password
def htmlLogin(baseDir: str) -> str:
if not os.path.isfile(baseDir+'/accounts/login.png'):
copyfile(baseDir+'/img/login.png',baseDir+'/accounts/login.png')
2019-07-25 19:56:25 +00:00
if os.path.isfile(baseDir+'/img/login-background.png'):
if not os.path.isfile(baseDir+'/accounts/login-background.png'):
copyfile(baseDir+'/img/login-background.png',baseDir+'/accounts/login-background.png')
2019-07-25 19:22:19 +00:00
2019-07-25 19:56:25 +00:00
loginText='<p class="login-text">Welcome. Please enter your login details below.</p>'
2019-07-25 19:22:19 +00:00
if os.path.isfile(baseDir+'/accounts/login.txt'):
with open(baseDir+'/accounts/login.txt', 'r') as file:
2019-07-25 19:56:25 +00:00
loginText = '<p class="login-text">'+file.read()+'</p>'
with open(baseDir+'/epicyon-login.css', 'r') as cssFile:
loginCSS = cssFile.read()
2019-07-24 22:38:42 +00:00
loginForm=htmlHeader(loginCSS)
loginForm+= \
2019-07-25 21:39:09 +00:00
'<form method="POST" action="/login">' \
2019-07-24 22:38:42 +00:00
' <div class="imgcontainer">' \
2019-07-25 19:22:19 +00:00
' <img src="login.png" alt="login image" class="loginimage">'+ \
loginText+ \
2019-07-24 22:38:42 +00:00
' </div>' \
'' \
' <div class="container">' \
' <label for="nickname"><b>Nickname</b></label>' \
2019-07-25 10:56:24 +00:00
' <input type="text" placeholder="Enter Nickname" name="username" required>' \
2019-07-24 22:38:42 +00:00
'' \
' <label for="password"><b>Password</b></label>' \
' <input type="password" placeholder="Enter Password" name="password" required>' \
'' \
2019-07-25 10:56:24 +00:00
' <button type="submit" name="submit">Login</button>' \
2019-07-24 22:38:42 +00:00
' </div>' \
'</form>'
loginForm+=htmlFooter()
return loginForm
2019-07-25 21:39:09 +00:00
def htmlNewPost(baseDir: str,path: str) -> str:
2019-07-28 11:35:57 +00:00
if not path.endswith('/newshare'):
newPostText='<p class="new-post-text">Enter your post text below.</p>'
else:
newPostText='<p class="new-post-text">Enter the details for your shared item below.</p>'
2019-07-25 21:39:09 +00:00
if os.path.isfile(baseDir+'/accounts/newpost.txt'):
with open(baseDir+'/accounts/newpost.txt', 'r') as file:
newPostText = '<p class="new-post-text">'+file.read()+'</p>'
with open(baseDir+'/epicyon-profile.css', 'r') as cssFile:
newPostCSS = cssFile.read()
2019-07-26 12:26:41 +00:00
pathBase=path.replace('/newpost','').replace('/newshare','').replace('/newunlisted','').replace('/newfollowers','').replace('/newdm','')
scopeIcon='scope_public.png'
scopeDescription='Public'
placeholderSubject='Subject or Content Warning (optional)...'
placeholderMessage='Write something...'
2019-07-26 12:59:30 +00:00
extraFields=''
2019-07-27 20:30:58 +00:00
endpoint='newpost'
2019-07-26 12:26:41 +00:00
if path.endswith('/newunlisted'):
scopeIcon='scope_unlisted.png'
scopeDescription='Unlisted'
2019-07-27 20:30:58 +00:00
endpoint='newunlisted'
2019-07-26 12:26:41 +00:00
if path.endswith('/newfollowers'):
scopeIcon='scope_followers.png'
scopeDescription='Followers Only'
2019-07-27 20:30:58 +00:00
endpoint='newfollowers'
2019-07-26 12:26:41 +00:00
if path.endswith('/newdm'):
scopeIcon='scope_dm.png'
scopeDescription='Direct Message'
2019-07-27 20:30:58 +00:00
endpoint='newdm'
2019-07-26 12:26:41 +00:00
if path.endswith('/newshare'):
scopeIcon='scope_share.png'
scopeDescription='Shared Item'
placeholderSubject='Name of the shared item...'
placeholderMessage='Description of the item being shared...'
2019-07-27 20:30:58 +00:00
endpoint='newshare'
2019-07-26 12:59:30 +00:00
extraFields= \
2019-07-26 14:19:37 +00:00
'<div class="container">' \
2019-07-28 11:35:57 +00:00
' <input type="text" class="itemType" placeholder="Type of shared item. eg. hat" name="itemType">' \
' <input type="text" class="category" placeholder="Category of shared item. eg. clothing" name="category">' \
' <label class="labels">Duration of listing in days:</label> <input type="number" name="duration" min="1" max="365" step="1" value="14">' \
2019-07-26 14:19:37 +00:00
'</div>' \
2019-07-26 12:59:30 +00:00
'<input type="text" placeholder="City or location of the shared item" name="location">'
2019-07-25 21:39:09 +00:00
newPostForm=htmlHeader(newPostCSS)
newPostForm+= \
2019-07-27 20:30:58 +00:00
'<form enctype="multipart/form-data" method="POST" action="'+path+'?'+endpoint+'">' \
2019-07-25 21:39:09 +00:00
' <div class="vertical-center">' \
' <label for="nickname"><b>'+newPostText+'</b></label>' \
2019-07-26 10:30:13 +00:00
' <div class="container">' \
2019-07-26 14:19:37 +00:00
' <div class="dropdown">' \
' <img src="/icons/'+scopeIcon+'"/><b class="scope-desc">'+scopeDescription+'</b>' \
' <div class="dropdown-content">' \
' <a href="'+pathBase+'/newpost"><img src="/icons/scope_public.png"/><b>Public</b><br>Visible to anyone</a>' \
' <a href="'+pathBase+'/newunlisted"><img src="/icons/scope_unlisted.png"/><b>Unlisted</b><br>Not on public timeline</a>' \
' <a href="'+pathBase+'/newfollowers"><img src="/icons/scope_followers.png"/><b>Followers Only</b><br>Only to followers</a>' \
' <a href="'+pathBase+'/newdm"><img src="/icons/scope_dm.png"/><b>Direct Message</b><br>Only to mentioned people</a>' \
' <a href="'+pathBase+'/newshare"><img src="/icons/scope_share.png"/><b>Share</b><br>Describe a shared item</a>' \
' </div>' \
' </div>' \
2019-07-28 15:16:14 +00:00
' <input type="submit" name="submitPost" value="Submit">' \
' <a href="'+pathBase+'/outbox"><button class="cancelbtn">Cancel</button></a>' \
2019-07-28 12:04:32 +00:00
' </div>' \
' <input type="text" placeholder="'+placeholderSubject+'" name="subject">' \
'' \
' <textarea id="message" name="message" placeholder="'+placeholderMessage+'" style="height:200px"></textarea>' \
''+extraFields+ \
' <div class="container">' \
' <input type="text" placeholder="Image description" name="imageDescription">' \
' <input type="file" id="attachpic" name="attachpic"' \
' accept=".png, .jpg, .jpeg, .gif">' \
2019-07-26 10:30:13 +00:00
' </div>' \
2019-07-25 21:39:09 +00:00
' </div>' \
'</form>'
newPostForm+=htmlFooter()
return newPostForm
2019-07-21 18:18:58 +00:00
def htmlHeader(css=None,lang='en') -> str:
if not css:
htmlStr= \
'<!DOCTYPE html>\n' \
'<html lang="'+lang+'">\n' \
' <meta charset="utf-8">\n' \
' <style>\n' \
2019-07-24 11:03:56 +00:00
' @import url("epicyon-profile.css");\n'+ \
2019-07-21 18:18:58 +00:00
' </style>\n' \
' <body>\n'
else:
htmlStr= \
'<!DOCTYPE html>\n' \
'<html lang="'+lang+'">\n' \
' <meta charset="utf-8">\n' \
' <style>\n'+css+'</style>\n' \
' <body>\n'
2019-07-20 21:13:36 +00:00
return htmlStr
def htmlFooter() -> str:
htmlStr= \
' </body>\n' \
'</html>\n'
return htmlStr
2019-07-22 14:09:21 +00:00
def htmlProfilePosts(baseDir: str,httpPrefix: str, \
authorized: bool,ocapAlways: bool, \
nickname: str,domain: str,port: int, \
session,wfRequest: {},personCache: {}) -> str:
2019-07-22 09:38:02 +00:00
"""Shows posts on the profile screen
"""
profileStr=''
2019-07-22 14:09:21 +00:00
outboxFeed= \
personBoxJson(baseDir,domain, \
port,'/users/'+nickname+'/outbox?page=1', \
httpPrefix, \
4, 'outbox', \
authorized, \
ocapAlways)
2019-07-22 09:38:02 +00:00
for item in outboxFeed['orderedItems']:
if item['type']=='Create':
2019-07-22 14:09:21 +00:00
profileStr+= \
individualPostAsHtml(session,wfRequest,personCache, \
2019-07-28 19:54:05 +00:00
nickname,domain,port,item)
2019-07-22 09:38:02 +00:00
return profileStr
2019-07-22 14:09:21 +00:00
def htmlProfileFollowing(baseDir: str,httpPrefix: str, \
authorized: bool,ocapAlways: bool, \
nickname: str,domain: str,port: int, \
session,wfRequest: {},personCache: {}, \
followingJson: {}) -> str:
"""Shows following on the profile screen
"""
profileStr=''
for item in followingJson['orderedItems']:
2019-07-22 14:09:21 +00:00
profileStr+=individualFollowAsHtml(session,wfRequest,personCache,domain,item)
return profileStr
2019-07-22 17:21:45 +00:00
def htmlProfileRoles(nickname: str,domain: str,rolesJson: {}) -> str:
"""Shows roles on the profile screen
"""
profileStr=''
for project,rolesList in rolesJson.items():
profileStr+='<div class="roles"><h2>'+project+'</h2><div class="roles-inner">'
for role in rolesList:
profileStr+='<h3>'+role+'</h3>'
profileStr+='</div></div>'
if len(profileStr)==0:
profileStr+='<p>@'+nickname+'@'+domain+' has no roles assigned</p>'
else:
profileStr='<div>'+profileStr+'</div>'
return profileStr
2019-07-22 20:01:46 +00:00
def htmlProfileSkills(nickname: str,domain: str,skillsJson: {}) -> str:
"""Shows skills on the profile screen
"""
profileStr=''
for skill,level in skillsJson.items():
profileStr+='<div>'+skill+'<br><div id="myProgress"><div id="myBar" style="width:'+str(level)+'%"></div></div></div><br>'
if len(profileStr)==0:
profileStr+='<p>@'+nickname+'@'+domain+' has no skills assigned</p>'
else:
profileStr='<center><div class="skill-title">'+profileStr+'</div></center>'
return profileStr
2019-07-23 12:33:09 +00:00
def htmlProfileShares(nickname: str,domain: str,sharesJson: {}) -> str:
"""Shows shares on the profile screen
"""
profileStr=''
for item in sharesJson['orderedItems']:
profileStr+='<div class="container">'
2019-07-24 09:53:07 +00:00
profileStr+='<p class="share-title">'+item['displayName']+'</p>'
profileStr+='<a href="'+item['imageUrl']+'">'
2019-07-24 09:53:07 +00:00
profileStr+='<img src="'+item['imageUrl']+'" alt="Item image"></a>'
profileStr+='<p>'+item['summary']+'</p>'
2019-07-24 09:53:07 +00:00
profileStr+='<p><b>Type:</b> '+item['itemType']+' '
profileStr+='<b>Category:</b> '+item['category']+' '
profileStr+='<b>Location:</b> '+item['location']+'</p>'
profileStr+='</div>'
2019-07-23 12:33:09 +00:00
if len(profileStr)==0:
profileStr+='<p>@'+nickname+'@'+domain+' is not sharing any items</p>'
else:
profileStr='<div class="share-title">'+profileStr+'</div>'
2019-07-23 12:33:09 +00:00
return profileStr
2019-07-22 14:09:21 +00:00
def htmlProfile(baseDir: str,httpPrefix: str,authorized: bool, \
ocapAlways: bool,profileJson: {},selected: str, \
session,wfRequest: {},personCache: {}, \
extraJson=None) -> str:
2019-07-20 21:13:36 +00:00
"""Show the profile page as html
"""
2019-07-21 18:18:58 +00:00
nickname=profileJson['name']
if not nickname:
return ""
preferredName=profileJson['preferredUsername']
domain,port=getDomainFromActor(profileJson['id'])
if not domain:
return ""
domainFull=domain
if port:
domainFull=domain+':'+str(port)
2019-07-21 20:36:58 +00:00
profileDescription=profileJson['publicKey']['summary']
profileDescription='A test description'
2019-07-22 09:38:02 +00:00
postsButton='button'
followingButton='button'
followersButton='button'
rolesButton='button'
skillsButton='button'
sharesButton='button'
if selected=='posts':
postsButton='buttonselected'
elif selected=='following':
followingButton='buttonselected'
elif selected=='followers':
followersButton='buttonselected'
elif selected=='roles':
rolesButton='buttonselected'
elif selected=='skills':
skillsButton='buttonselected'
elif selected=='shares':
sharesButton='buttonselected'
2019-07-28 15:52:59 +00:00
loginButton=''
2019-07-29 18:48:23 +00:00
followApprovalsSection=''
followApprovals=''
2019-07-28 15:52:59 +00:00
if not authorized:
loginButton='<br><a href="/login"><button class="loginButton">Login</button></a>'
2019-07-29 18:48:23 +00:00
else:
# are there any follow requests?
followRequestsFilename=baseDir+'/accounts/'+nickname+'@'+domain+'/followrequests.txt'
if os.path.isfile(followRequestsFilename):
with open(followRequestsFilename,'r') as f:
for line in f:
if len(line)>0:
# show a star on the followers tab
followApprovals='<img class="highlight" src="/icons/new.png"/>'
break
if selected=='followers':
if len(followApprovals)>0:
with open(followRequestsFilename,'r') as f:
for followerHandle in f:
if len(line)>0:
if '://' in followerHandle:
followerActor=followerHandle
else:
followerActor=httpPrefix+'://'+followerHandle.split('@')[1]+'/users/'+followerHandle.split('@')[0]
basePath=httpPrefix+'://'+domainFull+'/users/'+nickname
followApprovalsSection+='<div class="container">'
followApprovalsSection+='<a href="'+followerActor+'">'
followApprovalsSection+='<span class="followRequestHandle">'+followerHandle+'</span></a>'
followApprovalsSection+='<a href="'+basePath+'/followapprove='+followerHandle+'">'
followApprovalsSection+='<button class="followApprove">Approve</button></a>'
followApprovalsSection+='<a href="'+basePath+'/followdeny='+followerHandle+'">'
followApprovalsSection+='<button class="followDeny">Deny</button></a>'
followApprovalsSection+='</div>'
2019-07-22 10:01:10 +00:00
actor=profileJson['id']
2019-07-21 18:18:58 +00:00
profileStr= \
' <div class="hero-image">' \
' <div class="hero-text">' \
2019-07-21 20:36:58 +00:00
' <img src="'+profileJson['icon']['url']+'" alt="'+nickname+'@'+domainFull+'">' \
2019-07-21 18:18:58 +00:00
' <h1>'+preferredName+'</h1>' \
' <p><b>@'+nickname+'@'+domainFull+'</b></p>' \
2019-07-28 15:52:59 +00:00
' <p>'+profileDescription+'</p>'+ \
loginButton+ \
2019-07-21 18:18:58 +00:00
' </div>' \
2019-07-21 19:37:48 +00:00
'</div>' \
'<div class="container">\n' \
' <center>' \
2019-07-22 10:01:10 +00:00
' <a href="'+actor+'"><button class="'+postsButton+'"><span>Posts </span></button></a>' \
' <a href="'+actor+'/following"><button class="'+followingButton+'"><span>Following </span></button></a>' \
2019-07-29 18:48:23 +00:00
' <a href="'+actor+'/followers"><button class="'+followersButton+'"><span>Followers </span>'+followApprovals+'</button></a>' \
2019-07-22 10:01:10 +00:00
' <a href="'+actor+'/roles"><button class="'+rolesButton+'"><span>Roles </span></button></a>' \
' <a href="'+actor+'/skills"><button class="'+skillsButton+'"><span>Skills </span></button></a>' \
' <a href="'+actor+'/shares"><button class="'+sharesButton+'"><span>Shares </span></button></a>' \
2019-07-21 19:37:48 +00:00
' </center>' \
2019-07-21 18:18:58 +00:00
'</div>'
2019-07-29 18:48:23 +00:00
profileStr+=followApprovalsSection
2019-07-22 17:42:39 +00:00
with open(baseDir+'/epicyon-profile.css', 'r') as cssFile:
profileStyle = cssFile.read().replace('image.png',actor+'/image.png')
2019-07-21 22:38:44 +00:00
2019-07-22 17:42:39 +00:00
if selected=='posts':
profileStr+= \
htmlProfilePosts(baseDir,httpPrefix,authorized, \
ocapAlways,nickname,domain,port, \
session,wfRequest,personCache)
if selected=='following' or selected=='followers':
profileStr+= \
htmlProfileFollowing(baseDir,httpPrefix, \
authorized,ocapAlways,nickname, \
domain,port,session, \
wfRequest,personCache,extraJson)
if selected=='roles':
profileStr+= \
htmlProfileRoles(nickname,domainFull,extraJson)
2019-07-22 20:01:46 +00:00
if selected=='skills':
profileStr+= \
htmlProfileSkills(nickname,domainFull,extraJson)
2019-07-23 12:33:09 +00:00
if selected=='shares':
profileStr+= \
htmlProfileShares(nickname,domainFull,extraJson)
2019-07-22 17:42:39 +00:00
profileStr=htmlHeader(profileStyle)+profileStr+htmlFooter()
2019-07-21 18:18:58 +00:00
return profileStr
2019-07-20 21:13:36 +00:00
2019-07-22 14:09:21 +00:00
def individualFollowAsHtml(session,wfRequest: {}, \
personCache: {},domain: str, \
followUrl: str) -> str:
nickname=getNicknameFromActor(followUrl)
domain,port=getDomainFromActor(followUrl)
titleStr='@'+nickname+'@'+domain
2019-07-22 14:09:21 +00:00
avatarUrl=followUrl+'/avatar.png'
if domain not in followUrl:
2019-07-22 14:21:49 +00:00
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl2,preferredName = \
2019-07-22 14:09:21 +00:00
getPersonBox(session,wfRequest,personCache,'outbox')
if avatarUrl2:
avatarUrl=avatarUrl2
2019-07-22 14:21:49 +00:00
if preferredName:
titleStr=preferredName+' '+titleStr
return \
'<div class="container">\n' \
'<a href="'+followUrl+'">' \
2019-07-22 14:09:21 +00:00
'<img src="'+avatarUrl+'" alt="Avatar">\n'+ \
'<p>'+titleStr+'</p></a>'+ \
'</div>\n'
2019-07-22 14:09:21 +00:00
def individualPostAsHtml(session,wfRequest: {},personCache: {}, \
2019-07-28 19:54:05 +00:00
nickname: str,domain: str,port: int, \
postJsonObject: {}) -> str:
2019-07-21 11:20:49 +00:00
avatarPosition=''
containerClass='container'
timeClass='time-right'
2019-07-28 19:54:05 +00:00
actorNickname=getNicknameFromActor(postJsonObject['actor'])
actorDomain,actorPort=getDomainFromActor(postJsonObject['actor'])
titleStr='@'+actorNickname+'@'+actorDomain
2019-07-21 11:20:49 +00:00
if postJsonObject['object']['inReplyTo']:
containerClass='container darker'
avatarPosition=' class="right"'
timeClass='time-left'
2019-07-21 13:03:57 +00:00
if '/statuses/' in postJsonObject['object']['inReplyTo']:
replyNickname=getNicknameFromActor(postJsonObject['object']['inReplyTo'])
replyDomain,replyPort=getDomainFromActor(postJsonObject['object']['inReplyTo'])
2019-07-21 13:05:07 +00:00
if replyNickname and replyDomain:
titleStr+=' <i>replying to</i> <a href="'+postJsonObject['object']['inReplyTo']+'">@'+replyNickname+'@'+replyDomain+'</a>'
2019-07-21 13:03:57 +00:00
else:
titleStr+=' <i>replying to</i> '+postJsonObject['object']['inReplyTo']
2019-07-21 11:20:49 +00:00
attachmentStr=''
if postJsonObject['object']['attachment']:
if isinstance(postJsonObject['object']['attachment'], list):
attachmentCtr=0
for attach in postJsonObject['object']['attachment']:
if attach.get('mediaType') and attach.get('url'):
mediaType=attach['mediaType']
imageDescription=''
if attach.get('name'):
imageDescription=attach['name']
if mediaType=='image/png' or \
mediaType=='image/jpeg' or \
mediaType=='image/gif':
if attach['url'].endswith('.png') or \
attach['url'].endswith('.jpg') or \
attach['url'].endswith('.jpeg') or \
attach['url'].endswith('.gif'):
if attachmentCtr>0:
attachmentStr+='<br>'
attachmentStr+= \
2019-07-21 12:24:38 +00:00
'<a href="'+attach['url']+'">' \
'<img src="'+attach['url']+'" alt="'+imageDescription+'" title="'+imageDescription+'" class="attachment"></a>\n'
2019-07-21 11:20:49 +00:00
attachmentCtr+=1
2019-07-22 14:09:21 +00:00
avatarUrl=postJsonObject['actor']+'/avatar.png'
2019-07-28 19:54:05 +00:00
fullDomain=domain
if port!=80 and port!=443:
fullDomain=domain+':'+str(port)
2019-07-28 20:14:45 +00:00
2019-07-28 19:54:05 +00:00
if fullDomain not in postJsonObject['actor']:
2019-07-22 14:21:49 +00:00
inboxUrl,pubKeyId,pubKey,fromPersonId,sharedInbox,capabilityAcquisition,avatarUrl2,preferredName = \
2019-07-22 14:09:21 +00:00
getPersonBox(session,wfRequest,personCache,'outbox')
if avatarUrl2:
avatarUrl=avatarUrl2
2019-07-22 14:21:49 +00:00
if preferredName:
titleStr=preferredName+' '+titleStr
2019-07-28 20:14:45 +00:00
avatarDropdown= \
' <a href="'+postJsonObject['actor']+'">' \
' <img src="'+avatarUrl+'" title="Show profile" alt="Avatar"'+avatarPosition+'/></a>'
2019-07-29 16:13:48 +00:00
if fullDomain+'/users/'+nickname not in postJsonObject['actor']:
avatarDropdown= \
2019-07-28 20:14:45 +00:00
' <div class="dropdown-timeline">' \
' <img src="'+avatarUrl+'" alt="Avatar"'+avatarPosition+'/>' \
' <div class="dropdown-timeline-content">' \
' <a href="'+postJsonObject['actor']+'">Visit</a>'+ \
2019-07-28 20:20:58 +00:00
' <a href="/users/'+nickname+'?follow='+postJsonObject['actor']+';'+avatarUrl+'">Follow</a>' \
' <a href="/users/'+nickname+'?block='+postJsonObject['actor']+';'+avatarUrl+'">Block</a>' \
' <a href="/users/'+nickname+'?report='+postJsonObject['actor']+';'+avatarUrl+'">Report</a>' \
2019-07-28 20:14:45 +00:00
' </div>' \
' </div>'
2019-07-21 09:09:28 +00:00
return \
2019-07-28 20:14:45 +00:00
'<div class="'+containerClass+'">\n'+ \
avatarDropdown+ \
2019-07-21 13:03:57 +00:00
'<p class="post-title">'+titleStr+'</p>'+ \
2019-07-21 09:09:28 +00:00
postJsonObject['object']['content']+'\n'+ \
2019-07-21 11:20:49 +00:00
attachmentStr+ \
'<span class="'+timeClass+'">'+postJsonObject['object']['published']+'</span>\n'+ \
2019-07-21 11:52:13 +00:00
'</div>\n'
2019-07-21 09:09:28 +00:00
2019-07-24 12:02:28 +00:00
def htmlTimeline(session,baseDir: str,wfRequest: {},personCache: {}, \
2019-07-28 19:54:05 +00:00
nickname: str,domain: str,port: int,timelineJson: {}, \
2019-07-28 15:56:11 +00:00
boxName: str) -> str:
2019-07-21 09:09:28 +00:00
"""Show the timeline as html
"""
2019-07-24 12:02:28 +00:00
with open(baseDir+'/epicyon-profile.css', 'r') as cssFile:
profileStyle = \
cssFile.read().replace('banner.png', \
'/users/'+nickname+'/banner.png')
localButton='button'
personalButton='button'
federatedButton='button'
2019-07-25 21:39:09 +00:00
newPostButton='button'
2019-07-24 12:02:28 +00:00
if boxName=='inbox':
localButton='buttonselected'
elif boxName=='outbox':
personalButton='buttonselected'
elif boxName=='federated':
federatedButton='buttonselected'
actor='/users/'+nickname
tlStr=htmlHeader(profileStyle)
2019-07-28 15:56:11 +00:00
newPostStr=' <a href="'+actor+'/newpost"><button class="'+newPostButton+'"><span>New Post </span></button></a>'
2019-07-24 12:02:28 +00:00
tlStr+= \
'<div class="timeline-banner">' \
'</div>' \
'<div class="container">\n' \
2019-07-26 10:30:13 +00:00
' <center>'+newPostStr+ \
2019-07-24 12:02:28 +00:00
' <a href="'+actor+'/inbox"><button class="'+localButton+'"><span>Local </span></button></a>' \
' <a href="'+actor+'/outbox"><button class="'+personalButton+'"><span>Personal </span></button></a>' \
' <a href="'+actor+'/federated"><button class="'+federatedButton+'"><span>Federated </span></button></a>' \
' </center>' \
'</div>'
2019-07-21 09:09:28 +00:00
for item in timelineJson['orderedItems']:
if item['type']=='Create':
2019-07-22 14:09:21 +00:00
tlStr+=individualPostAsHtml(session,wfRequest,personCache, \
2019-07-28 19:54:05 +00:00
nickname,domain,port,item)
2019-07-21 09:09:28 +00:00
tlStr+=htmlFooter()
return tlStr
2019-07-24 12:02:28 +00:00
def htmlInbox(session,baseDir: str,wfRequest: {},personCache: {}, \
2019-07-28 19:54:05 +00:00
nickname: str,domain: str,port: int,inboxJson: {}) -> str:
2019-07-20 21:13:36 +00:00
"""Show the inbox as html
"""
2019-07-24 12:02:28 +00:00
return htmlTimeline(session,baseDir,wfRequest,personCache, \
2019-07-28 19:54:05 +00:00
nickname,domain,port,inboxJson,'inbox')
2019-07-20 21:13:36 +00:00
2019-07-24 12:02:28 +00:00
def htmlOutbox(session,baseDir: str,wfRequest: {},personCache: {}, \
2019-07-28 19:54:05 +00:00
nickname: str,domain: str,port: int,outboxJson: {}) -> str:
2019-07-20 21:13:36 +00:00
"""Show the Outbox as html
"""
2019-07-24 12:02:28 +00:00
return htmlTimeline(session,baseDir,wfRequest,personCache, \
2019-07-28 19:54:05 +00:00
nickname,domain,port,outboxJson,'outbox')
2019-07-20 21:13:36 +00:00
2019-07-22 14:09:21 +00:00
def htmlIndividualPost(session,wfRequest: {},personCache: {}, \
2019-07-28 19:54:05 +00:00
nickname: str,domain: str,port: int,postJsonObject: {}) -> str:
2019-07-20 21:13:36 +00:00
"""Show an individual post as html
"""
2019-07-21 09:09:28 +00:00
return htmlHeader()+ \
2019-07-22 14:09:21 +00:00
individualPostAsHtml(session,wfRequest,personCache, \
2019-07-28 19:54:05 +00:00
nickname,domain,port,postJsonObject)+ \
2019-07-21 09:09:28 +00:00
htmlFooter()
2019-07-20 21:13:36 +00:00
def htmlPostReplies(postJsonObject: {}) -> str:
"""Show the replies to an individual post as html
"""
return htmlHeader()+"<h1>Replies</h1>"+htmlFooter()
2019-07-29 09:49:46 +00:00
def htmlFollowConfirm(baseDir: str,originPathStr: str,followActor: str,followProfileUrl: str) -> str:
"""Asks to confirm a follow
"""
followDomain,port=getDomainFromActor(followActor)
if os.path.isfile(baseDir+'/img/follow-background.png'):
if not os.path.isfile(baseDir+'/accounts/follow-background.png'):
copyfile(baseDir+'/img/follow-background.png',baseDir+'/accounts/follow-background.png')
with open(baseDir+'/epicyon-follow.css', 'r') as cssFile:
profileStyle = cssFile.read()
followStr=htmlHeader(profileStyle)
followStr+='<div class="follow">'
followStr+=' <div class="followAvatar">'
followStr+=' <center>'
followStr+=' <a href="'+followActor+'">'
followStr+=' <img src="'+followProfileUrl+'"/></a>'
followStr+=' <p class="followText">Follow '+getNicknameFromActor(followActor)+'@'+followDomain+' ?</p>'
followStr+= \
2019-07-29 16:13:48 +00:00
' <form method="POST" action="'+originPathStr+'/followconfirm">' \
2019-07-29 09:49:46 +00:00
' <input type="hidden" name="actor" value="'+followActor+'">' \
' <button type="submit" class="button" name="submitYes">Yes</button>' \
' <a href="'+originPathStr+'"><button class="button">No</button></a>' \
' </form>'
followStr+='</center>'
followStr+='</div>'
followStr+='</div>'
followStr+=htmlFooter()
return followStr