From 2740d760c919e97c1b3df2d4278f210df26bd290 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 11 Sep 2019 19:10:32 +0100 Subject: [PATCH] Optional separate directories for themed icons --- webinterface.py | 110 ++++++++++++++++++++++++++++-------------------- 1 file changed, 65 insertions(+), 45 deletions(-) diff --git a/webinterface.py b/webinterface.py index ca1789104..19a184c4a 100644 --- a/webinterface.py +++ b/webinterface.py @@ -98,6 +98,16 @@ def htmlSearchEmoji(translate: {},baseDir: str,searchStr: str) -> str: emojiForm+=htmlFooter() return emojiForm +def getIconsDir(baseDir: str) -> str: + """Returns the directory where icons exist + """ + iconsDir='icons' + theme=getConfigParam(baseDir,'theme') + if theme: + if os.path.isdir(baseDir+'img/icons/'+theme): + iconsDir='icons/'+theme + return iconsDir + def htmlSearchSharedItems(translate: {}, \ baseDir: str,searchStr: str, \ pageNumber: int, \ @@ -106,6 +116,7 @@ def htmlSearchSharedItems(translate: {}, \ domainFull: str,actor: str) -> str: """Search results for shared items """ + iconsDir=getIconsDir(baseDir) currPage=1 ctr=0 sharedItemsForm='' @@ -168,7 +179,7 @@ def htmlSearchSharedItems(translate: {}, \ ' ' \ '
' \ '
' \ - ' '+translate['Page up']+'' \ + ' '+translate['Page up']+'' \ '
' \ '' resultsExist=True @@ -182,7 +193,7 @@ def htmlSearchSharedItems(translate: {}, \ ' ' \ '
' \ '
' \ - ' '+translate['Page down']+'' \ + ' '+translate['Page down']+'' \ '
' \ '' break @@ -238,6 +249,7 @@ def htmlHashtagSearch(translate: {}, \ httpPrefix: str,projectVersion: str) -> str: """Show a page containing search results for a hashtag """ + iconsDir=getIconsDir(baseDir) if hashtag.startswith('#'): hashtag=hashtag[1:] hashtagIndexFile=baseDir+'/tags/'+hashtag+'.txt' @@ -264,7 +276,7 @@ def htmlHashtagSearch(translate: {}, \ hashtagSearchForm+='

#'+hashtag+'

' if startIndex!=len(lines)-1: # previous page link - hashtagSearchForm+='
'+translate['Page up']+'
' + hashtagSearchForm+='
'+translate['Page up']+'
' index=startIndex while index>=endIndex: postId=lines[index].strip('\n') @@ -286,7 +298,7 @@ def htmlHashtagSearch(translate: {}, \ index-=1 continue hashtagSearchForm+= \ - individualPostAsHtml(translate,None, \ + individualPostAsHtml(iconsDir,translate,None, \ baseDir,session,wfRequest,personCache, \ nickname,domain,port,postJsonObject, \ None,True,False, \ @@ -296,7 +308,7 @@ def htmlHashtagSearch(translate: {}, \ if endIndex>0: # next page link - hashtagSearchForm+='
'+translate['Page down']+'
' + hashtagSearchForm+='
'+translate['Page down']+'
' hashtagSearchForm+=htmlFooter() return hashtagSearchForm @@ -725,6 +737,7 @@ def htmlNewPost(translate: {},baseDir: str, \ reportUrl: str,pageNumber: int) -> str: """New post screen """ + iconsDir=getIconsDir(baseDir) replyStr='' if not path.endswith('/newshare'): if not path.endswith('/newreport'): @@ -805,7 +818,7 @@ def htmlNewPost(translate: {},baseDir: str, \ # only show the share option if this is not a reply shareOptionOnDropdown='' if not replyStr: - shareOptionOnDropdown='Share
'+translate['Describe a shared item']+'
' + shareOptionOnDropdown='Share
'+translate['Describe a shared item']+'
' mentionsStr='' for m in mentions: @@ -848,11 +861,11 @@ def htmlNewPost(translate: {},baseDir: str, \ if not reportUrl: dropDownContent= \ ' ' else: @@ -864,7 +877,7 @@ def htmlNewPost(translate: {},baseDir: str, \ ' ' \ '
' \ '
' \ - ' '+scopeDescription+''+ \ + ' '+scopeDescription+''+ \ dropDownContent+ \ '
' \ ' ' \ @@ -932,6 +945,7 @@ def htmlProfilePosts(translate: {}, \ """Shows posts on the profile screen These should only be public posts """ + iconsDir=getIconsDir(baseDir) profileStr='' maxItems=4 profileStr+='' @@ -951,7 +965,7 @@ def htmlProfilePosts(translate: {}, \ break for item in outboxFeed['orderedItems']: if item['type']=='Create': - postStr=individualPostAsHtml(translate,None, \ + postStr=individualPostAsHtml(iconsDir,translate,None, \ baseDir,session,wfRequest,personCache, \ nickname,domain,port,item,None,True,False, \ httpPrefix,projectVersion, \ @@ -977,11 +991,12 @@ def htmlProfileFollowing(translate: {},baseDir: str,httpPrefix: str, \ """ profileStr='' + iconsDir=getIconsDir(baseDir) if authorized and pageNumber: if authorized and pageNumber>1: # page up arrow profileStr+= \ - '
'+translate['Page up']+'
' + '
'+translate['Page up']+'
' for item in followingJson['orderedItems']: profileStr+= \ @@ -994,7 +1009,7 @@ def htmlProfileFollowing(translate: {},baseDir: str,httpPrefix: str, \ if len(followingJson['orderedItems'])>=maxItemsPerPage: # page down arrow profileStr+= \ - '
'+translate['Page down']+'
' + '
'+translate['Page down']+'
' return profileStr def htmlProfileRoles(translate: {},nickname: str,domain: str,rolesJson: {}) -> str: @@ -1457,7 +1472,7 @@ def rejectAnnounce(announceFilename: str): rejectAnnounceFile.write('\n') rejectAnnounceFile.close() -def individualPostAsHtml(translate: {}, \ +def individualPostAsHtml(iconsDir: str,translate: {}, \ pageNumber: int,baseDir: str, \ session,wfRequest: {},personCache: {}, \ nickname: str,domain: str,port: int, \ @@ -1594,7 +1609,7 @@ def individualPostAsHtml(translate: {}, \ # Show a DM icon for DMs in the inbox timeline if showDMicon: - titleStr=titleStr+' ' + titleStr=titleStr+' ' if showRepeatIcon: if isAnnounced: @@ -1604,13 +1619,13 @@ def individualPostAsHtml(translate: {}, \ announceDomain,announcePort=getDomainFromActor(postJsonObject['object']['attributedTo']) announceDisplayName=getDisplayName(postJsonObject['object']['attributedTo'],personCache) if announceDisplayName: - titleStr+=' '+announceDisplayName+'' + titleStr+=' '+announceDisplayName+'' else: - titleStr+=' @'+announceNickname+'@'+announceDomain+'' + titleStr+=' @'+announceNickname+'@'+announceDomain+'' else: - titleStr+=' @unattributed' + titleStr+=' @unattributed' else: - titleStr+=' @unattributed' + titleStr+=' @unattributed' else: if postJsonObject['object'].get('inReplyTo'): containerClassIcons='containericons darker' @@ -1623,17 +1638,17 @@ def individualPostAsHtml(translate: {}, \ if replyNickname and replyDomain: replyDisplayName=getDisplayName(postJsonObject['object']['inReplyTo'],personCache) if replyDisplayName: - titleStr+=' '+replyDisplayName+'' + titleStr+=' '+replyDisplayName+'' else: - titleStr+=' @'+replyNickname+'@'+replyDomain+'' + titleStr+=' @'+replyNickname+'@'+replyDomain+'' else: - titleStr+=' @unknown' + titleStr+=' @unknown' else: postDomain=postJsonObject['object']['inReplyTo'].replace('https://','').replace('http://','').replace('dat://','') if '/' in postDomain: postDomain=postDomain.split('/',1)[0] if postDomain: - titleStr+=' '+postDomain+'' + titleStr+=' '+postDomain+'' attachmentStr='' if postJsonObject['object'].get('attachment'): if isinstance(postJsonObject['object']['attachment'], list): @@ -1756,7 +1771,7 @@ def individualPostAsHtml(translate: {}, \ announceTitle=translate['Undo the repeat'] announceStr= \ '' \ - '' + '' likeStr='' if not isModerationPost: @@ -1770,7 +1785,7 @@ def individualPostAsHtml(translate: {}, \ likeTitle=translate['Undo the like'] likeStr= \ '' \ - '' + '' deleteStr='' if allowDeletion or \ @@ -1779,7 +1794,7 @@ def individualPostAsHtml(translate: {}, \ if '/users/'+nickname+'/' in postJsonObject['object']['id']: deleteStr= \ '' \ - '' + '' # change the background color for DMs in inbox timeline if showDMicon: @@ -1808,7 +1823,7 @@ def individualPostAsHtml(translate: {}, \ footerStr+='' else: footerStr+='' - footerStr+='' + footerStr+='' footerStr+=announceStr+likeStr+deleteStr footerStr+=''+publishedStr+'' footerStr+='
' @@ -1866,6 +1881,7 @@ def htmlTimeline(translate: {},pageNumber: int, \ manuallyApproveFollowers: bool) -> str: """Show the timeline as html """ + iconsDir=getIconsDir(baseDir) cssFilename=baseDir+'/epicyon-profile.css' if os.path.isfile(baseDir+'/epicyon.css'): cssFilename=baseDir+'/epicyon.css' @@ -1901,7 +1917,7 @@ def htmlTimeline(translate: {},pageNumber: int, \ for line in f: if len(line)>0: # show follow approvals icon - followApprovals=''+translate['Approve follow requests']+'' + followApprovals=''+translate['Approve follow requests']+'' break moderationButtonStr='' @@ -1915,11 +1931,11 @@ def htmlTimeline(translate: {},pageNumber: int, \ if boxName!='dm': if not manuallyApproveFollowers: - newPostButtonStr=''+translate['Create a new post']+'' + newPostButtonStr=''+translate['Create a new post']+'' else: - newPostButtonStr=''+translate['Create a new post']+'' + newPostButtonStr=''+translate['Create a new post']+'' else: - newPostButtonStr=''+translate['Create a new DM']+'' + newPostButtonStr=''+translate['Create a new DM']+'' # banner and row of buttons tlStr+= \ @@ -1931,8 +1947,8 @@ def htmlTimeline(translate: {},pageNumber: int, \ ' ' \ ' '+ \ moderationButtonStr+newPostButtonStr+ \ - ' '+translate['Search and follow']+''+ \ - ' '+translate['Refresh']+''+ \ + ' '+translate['Search and follow']+''+ \ + ' '+translate['Refresh']+''+ \ followApprovals+ \ '' @@ -1955,7 +1971,7 @@ def htmlTimeline(translate: {},pageNumber: int, \ # page up arrow if pageNumber>1: - tlStr+='
'+translate['Page up']+'
' + tlStr+='
'+translate['Page up']+'
' # show the posts itemCtr=0 @@ -1964,7 +1980,7 @@ def htmlTimeline(translate: {},pageNumber: int, \ itemCtr+=1 avatarUrl=getPersonAvatarUrl(baseDir,item['actor'],personCache) tlStr+= \ - individualPostAsHtml(translate,pageNumber, \ + individualPostAsHtml(iconsDir,translate,pageNumber, \ baseDir,session,wfRequest,personCache, \ nickname,domain,port,item,avatarUrl,True, \ allowDeletion, \ @@ -1975,7 +1991,7 @@ def htmlTimeline(translate: {},pageNumber: int, \ # page down arrow if itemCtr>=itemsPerPage: - tlStr+='
'+translate['Page down']+'
' + tlStr+='
'+translate['Page down']+'
' tlStr+=htmlFooter() return tlStr @@ -2038,9 +2054,11 @@ def htmlIndividualPost(translate: {}, \ postJsonObject: {},httpPrefix: str,projectVersion: str) -> str: """Show an individual post as html """ + iconsDir=getIconsDir(baseDir) postStr='' postStr+= \ - individualPostAsHtml(translate,None,baseDir,session,wfRequest,personCache, \ + individualPostAsHtml(iconsDir,translate,None, \ + baseDir,session,wfRequest,personCache, \ nickname,domain,port,postJsonObject,None,True,False, \ httpPrefix,projectVersion,False,authorized,False,False) messageId=postJsonObject['id'].replace('/activity','') @@ -2053,7 +2071,7 @@ def htmlIndividualPost(translate: {}, \ with open(postFilename, 'r') as fp: postJsonObject=commentjson.load(fp) postStr= \ - individualPostAsHtml(translate,None, \ + individualPostAsHtml(iconsDir,translate,None, \ baseDir,session,wfRequest,personCache, \ nickname,domain,port,postJsonObject, \ None,True,False, \ @@ -2072,7 +2090,7 @@ def htmlIndividualPost(translate: {}, \ # add items to the html output for item in repliesJson['orderedItems']: postStr+= \ - individualPostAsHtml(translate,None, \ + individualPostAsHtml(iconsDir,translate,None, \ baseDir,session,wfRequest,personCache, \ nickname,domain,port,item,None,True,False, \ httpPrefix,projectVersion, \ @@ -2086,11 +2104,12 @@ def htmlPostReplies(translate: {},baseDir: str, \ httpPrefix: str,projectVersion: str) -> str: """Show the replies to an individual post as html """ + iconsDir=getIconsDir(baseDir) repliesStr='' if repliesJson.get('orderedItems'): for item in repliesJson['orderedItems']: repliesStr+= \ - individualPostAsHtml(translate,None, \ + individualPostAsHtml(iconsDir,translate,None, \ baseDir,session,wfRequest,personCache, \ nickname,domain,port,item,None,True,False, \ httpPrefix,projectVersion, \ @@ -2156,7 +2175,7 @@ def htmlDeletePost(translate,pageNumber: int, \ """ if '/statuses/' not in messageId: return None - + iconsDir=getIconsDir(baseDir) actor=messageId.split('/statuses/')[0] nickname=getNicknameFromActor(actor) domain,port=getDomainFromActor(actor) @@ -2181,7 +2200,7 @@ def htmlDeletePost(translate,pageNumber: int, \ deletePostStr=htmlHeader(cssFilename,profileStyle) deletePostStr+='' deletePostStr+= \ - individualPostAsHtml(translate,pageNumber, \ + individualPostAsHtml(iconsDir,translate,pageNumber, \ baseDir,session,wfRequest,personCache, \ nickname,domain,port,postJsonObject, \ None,True,False, \ @@ -2595,6 +2614,7 @@ def htmlProfileAfterSearch(translate: {}, \ profileStr+='' + iconsDir=getIconsDir(baseDir) result = [] i = 0 for item in parseUserFeed(session,outboxUrl,asHeader, \ @@ -2606,7 +2626,7 @@ def htmlProfileAfterSearch(translate: {}, \ if not item.get('object'): continue profileStr+= \ - individualPostAsHtml(translate,None,baseDir, \ + individualPostAsHtml(iconsDir,translate,None,baseDir, \ session,wfRequest,personCache, \ nickname,domain,port, \ item,avatarUrl,False,False, \