From 105fe0342676b887bc076422383d3a8ea7b179fd Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 30 Oct 2021 12:08:57 +0100 Subject: [PATCH 1/4] Function to set custom backgrounds --- webapp_calendar.py | 12 +++--------- webapp_confirm.py | 16 ++++------------ webapp_hashtagswarm.py | 12 +++++++----- webapp_search.py | 21 +++++++++++++-------- webapp_utils.py | 16 ++++++++++++++++ 5 files changed, 43 insertions(+), 34 deletions(-) diff --git a/webapp_calendar.py b/webapp_calendar.py index 8dee4eb27..2fa9cdcb3 100644 --- a/webapp_calendar.py +++ b/webapp_calendar.py @@ -10,7 +10,6 @@ __module_group__ = "Calendar" import os from datetime import datetime from datetime import date -from shutil import copyfile from utils import getDisplayName from utils import getConfigParam from utils import getNicknameFromActor @@ -25,6 +24,7 @@ from utils import localActorUrl from utils import replaceUsersWithAt from happening import getTodaysEvents from happening import getCalendarEvents +from webapp_utils import setCustomBackground from webapp_utils import htmlHeaderWithExternalStyle from webapp_utils import htmlFooter from webapp_utils import htmlHideFromScreenReader @@ -51,10 +51,7 @@ def htmlCalendarDeleteConfirm(cssCache: {}, translate: {}, baseDir: str, if not postJsonObject: return None - if os.path.isfile(baseDir + '/img/delete-background.png'): - if not os.path.isfile(baseDir + '/accounts/delete-background.png'): - copyfile(baseDir + '/img/delete-background.png', - baseDir + '/accounts/delete-background.png') + setCustomBackground(baseDir, 'delete-background') deletePostStr = None cssFilename = baseDir + '/epicyon-profile.css' @@ -287,10 +284,7 @@ def htmlCalendar(personCache: {}, cssCache: {}, translate: {}, nickname = getNicknameFromActor(actor) - if os.path.isfile(baseDir + '/img/calendar-background.png'): - if not os.path.isfile(baseDir + '/accounts/calendar-background.png'): - copyfile(baseDir + '/img/calendar-background.png', - baseDir + '/accounts/calendar-background.png') + setCustomBackground(baseDir, 'calendar-background') months = ('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', diff --git a/webapp_confirm.py b/webapp_confirm.py index a2b29250d..a483726cd 100644 --- a/webapp_confirm.py +++ b/webapp_confirm.py @@ -17,6 +17,7 @@ from utils import loadJson from utils import getConfigParam from utils import getAltPath from utils import acctDir +from webapp_utils import setCustomBackground from webapp_utils import htmlHeaderWithExternalStyle from webapp_utils import htmlFooter from webapp_post import individualPostAsHtml @@ -54,10 +55,7 @@ def htmlConfirmDelete(cssCache: {}, if not postJsonObject: return None - if os.path.isfile(baseDir + '/img/delete-background.png'): - if not os.path.isfile(baseDir + '/accounts/delete-background.png'): - copyfile(baseDir + '/img/delete-background.png', - baseDir + '/accounts/delete-background.png') + setCustomBackground(baseDir, 'delete-background') deletePostStr = None cssFilename = baseDir + '/epicyon-profile.css' @@ -134,10 +132,7 @@ def htmlConfirmRemoveSharedItem(cssCache: {}, translate: {}, baseDir: str, if sharesJson[itemID].get('imageUrl'): sharedItemImageUrl = sharesJson[itemID]['imageUrl'] - if os.path.isfile(baseDir + '/img/shares-background.png'): - if not os.path.isfile(baseDir + '/accounts/shares-background.png'): - copyfile(baseDir + '/img/shares-background.png', - baseDir + '/accounts/shares-background.png') + setCustomBackground(baseDir, 'shares-background') cssFilename = baseDir + '/epicyon-follow.css' if os.path.isfile(baseDir + '/follow.css'): @@ -278,10 +273,7 @@ def htmlConfirmUnblock(cssCache: {}, translate: {}, baseDir: str, """ blockDomain, port = getDomainFromActor(blockActor) - if os.path.isfile(baseDir + '/img/block-background.png'): - if not os.path.isfile(baseDir + '/accounts/block-background.png'): - copyfile(baseDir + '/img/block-background.png', - baseDir + '/accounts/block-background.png') + setCustomBackground(baseDir, 'block-background') cssFilename = baseDir + '/epicyon-follow.css' if os.path.isfile(baseDir + '/follow.css'): diff --git a/webapp_hashtagswarm.py b/webapp_hashtagswarm.py index 6eca2a7d7..abf0996d5 100644 --- a/webapp_hashtagswarm.py +++ b/webapp_hashtagswarm.py @@ -8,12 +8,12 @@ __status__ = "Production" __module_group__ = "Web Interface" import os -from shutil import copyfile from datetime import datetime from utils import getNicknameFromActor from utils import getConfigParam from categories import getHashtagCategories from categories import getHashtagCategory +from webapp_utils import setCustomBackground from webapp_utils import getSearchBannerFile from webapp_utils import getContentWarningButton from webapp_utils import htmlHeaderWithExternalStyle @@ -201,10 +201,7 @@ def htmlSearchHashtagCategory(cssCache: {}, translate: {}, categoryStr = path.split('/category/')[1].strip() searchNickname = getNicknameFromActor(actor) - if os.path.isfile(baseDir + '/img/search-background.png'): - if not os.path.isfile(baseDir + '/accounts/search-background.png'): - copyfile(baseDir + '/img/search-background.png', - baseDir + '/accounts/search-background.png') + backgroundExt = setCustomBackground(baseDir, 'search-background') cssFilename = baseDir + '/epicyon-search.css' if os.path.isfile(baseDir + '/search.css'): @@ -213,6 +210,11 @@ def htmlSearchHashtagCategory(cssCache: {}, translate: {}, instanceTitle = \ getConfigParam(baseDir, 'instanceTitle') htmlStr = htmlHeaderWithExternalStyle(cssFilename, instanceTitle) + if backgroundExt: + if backgroundExt != 'jpg': + htmlStr = htmlStr.replace('"follow-background.jpg"', + '"follow-background.' + + backgroundExt + '"') # show a banner above the search box searchBannerFile, searchBannerFilename = \ diff --git a/webapp_search.py b/webapp_search.py index 7375d4f47..94b820ec5 100644 --- a/webapp_search.py +++ b/webapp_search.py @@ -31,6 +31,7 @@ from skills import getSkillsFromList from categories import getHashtagCategory from feeds import rss2TagHeader from feeds import rss2TagFooter +from webapp_utils import setCustomBackground from webapp_utils import htmlKeyboardNavigation from webapp_utils import htmlHeaderWithExternalStyle from webapp_utils import htmlFooter @@ -327,10 +328,7 @@ def htmlSearchEmojiTextEntry(cssCache: {}, translate: {}, actor = path.replace('/search', '') domain, port = getDomainFromActor(actor) - if os.path.isfile(baseDir + '/img/search-background.png'): - if not os.path.isfile(baseDir + '/accounts/search-background.png'): - copyfile(baseDir + '/img/search-background.png', - baseDir + '/accounts/search-background.png') + backgroundExt = setCustomBackground(baseDir, 'search-background') cssFilename = baseDir + '/epicyon-follow.css' if os.path.isfile(baseDir + '/follow.css'): @@ -339,6 +337,11 @@ def htmlSearchEmojiTextEntry(cssCache: {}, translate: {}, instanceTitle = \ getConfigParam(baseDir, 'instanceTitle') emojiStr = htmlHeaderWithExternalStyle(cssFilename, instanceTitle) + if backgroundExt: + if backgroundExt != 'jpg': + emojiStr = emojiStr.replace('"follow-background.jpg"', + '"follow-background.' + + backgroundExt + '"') emojiStr += '
\n' emojiStr += '
\n' emojiStr += '
\n' @@ -370,10 +373,7 @@ def htmlSearch(cssCache: {}, translate: {}, actor = path.replace('/search', '') searchNickname = getNicknameFromActor(actor) - if os.path.isfile(baseDir + '/img/search-background.png'): - if not os.path.isfile(baseDir + '/accounts/search-background.png'): - copyfile(baseDir + '/img/search-background.png', - baseDir + '/accounts/search-background.png') + backgroundExt = setCustomBackground(baseDir, 'search-background') cssFilename = baseDir + '/epicyon-search.css' if os.path.isfile(baseDir + '/search.css'): @@ -381,6 +381,11 @@ def htmlSearch(cssCache: {}, translate: {}, instanceTitle = getConfigParam(baseDir, 'instanceTitle') followStr = htmlHeaderWithExternalStyle(cssFilename, instanceTitle) + if backgroundExt: + if backgroundExt != 'jpg': + followStr = followStr.replace('"follow-background.jpg"', + '"follow-background.' + + backgroundExt + '"') # show a banner above the search box searchBannerFile, searchBannerFilename = \ diff --git a/webapp_utils.py b/webapp_utils.py index 97b7b0141..fa098e881 100644 --- a/webapp_utils.py +++ b/webapp_utils.py @@ -8,6 +8,7 @@ __status__ = "Production" __module_group__ = "Web Interface" import os +from shutil import copyfile from collections import OrderedDict from session import getJson from utils import isAccountDir @@ -1455,3 +1456,18 @@ def htmlShowShare(baseDir: str, domain: str, nickname: str, return htmlHeaderWithExternalStyle(cssFilename, instanceTitle) + \ shareStr + htmlFooter() + + +def setCustomBackground(baseDir: str, background: str) -> str: + """Sets a custom background + Returns the extension, if found + """ + extensions = getImageExtensions() + for ext in extensions: + if os.path.isfile(baseDir + '/img/' + background + '.' + ext): + if not os.path.isfile(baseDir + '/accounts/' + + background + '.' + ext): + copyfile(baseDir + '/img/' + background + '.' + ext, + baseDir + '/accounts/' + background + '.' + ext) + return ext + return None From 5207a2ab3c203cbc1bbd493d72f747229ffcbd17 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 30 Oct 2021 12:20:08 +0100 Subject: [PATCH 2/4] Setting custom background for login screen --- webapp_login.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/webapp_login.py b/webapp_login.py index 97e54811c..786112182 100644 --- a/webapp_login.py +++ b/webapp_login.py @@ -13,6 +13,7 @@ from shutil import copyfile from utils import getConfigParam from utils import noOfAccounts from utils import getNicknameValidationPattern +from webapp_utils import setCustomBackground from webapp_utils import htmlHeaderWithWebsiteMarkup from webapp_utils import htmlFooter from webapp_utils import htmlKeyboardNavigation @@ -92,10 +93,7 @@ def htmlLogin(cssCache: {}, translate: {}, textModeLogo = getTextModeLogo(baseDir) textModeLogoHtml = htmlKeyboardNavigation(textModeLogo, {}, {}) - if os.path.isfile(baseDir + '/accounts/login-background-custom.jpg'): - if not os.path.isfile(baseDir + '/accounts/login-background.jpg'): - copyfile(baseDir + '/accounts/login-background-custom.jpg', - baseDir + '/accounts/login-background.jpg') + backgroundExt = setCustomBackground(baseDir, 'login-background-custom') if accounts > 0: loginText = \ @@ -155,6 +153,11 @@ def htmlLogin(cssCache: {}, translate: {}, htmlHeaderWithWebsiteMarkup(cssFilename, instanceTitle, httpPrefix, domain, systemLanguage) + if backgroundExt: + loginForm = loginForm.replace('"login-background.jpg"', + '"login-background-custom.' + + backgroundExt + '"') + nicknamePattern = getNicknameValidationPattern() instanceTitle = getConfigParam(baseDir, 'instanceTitle') loginForm += \ From 17e08b21366820f295df433a3b35c2764274a401 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 30 Oct 2021 12:51:41 +0100 Subject: [PATCH 3/4] Setting custom backgrounds --- webapp_calendar.py | 4 +--- webapp_confirm.py | 6 ++---- webapp_hashtagswarm.py | 7 +------ webapp_login.py | 6 +----- webapp_search.py | 14 ++------------ webapp_utils.py | 20 +++++++++++--------- 6 files changed, 18 insertions(+), 39 deletions(-) diff --git a/webapp_calendar.py b/webapp_calendar.py index 2fa9cdcb3..161cd63b1 100644 --- a/webapp_calendar.py +++ b/webapp_calendar.py @@ -51,8 +51,6 @@ def htmlCalendarDeleteConfirm(cssCache: {}, translate: {}, baseDir: str, if not postJsonObject: return None - setCustomBackground(baseDir, 'delete-background') - deletePostStr = None cssFilename = baseDir + '/epicyon-profile.css' if os.path.isfile(baseDir + '/epicyon.css'): @@ -284,7 +282,7 @@ def htmlCalendar(personCache: {}, cssCache: {}, translate: {}, nickname = getNicknameFromActor(actor) - setCustomBackground(baseDir, 'calendar-background') + setCustomBackground(baseDir, 'calendar-background', 'calendar-background') months = ('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', diff --git a/webapp_confirm.py b/webapp_confirm.py index a483726cd..0d56fa1ac 100644 --- a/webapp_confirm.py +++ b/webapp_confirm.py @@ -55,8 +55,6 @@ def htmlConfirmDelete(cssCache: {}, if not postJsonObject: return None - setCustomBackground(baseDir, 'delete-background') - deletePostStr = None cssFilename = baseDir + '/epicyon-profile.css' if os.path.isfile(baseDir + '/epicyon.css'): @@ -132,7 +130,7 @@ def htmlConfirmRemoveSharedItem(cssCache: {}, translate: {}, baseDir: str, if sharesJson[itemID].get('imageUrl'): sharedItemImageUrl = sharesJson[itemID]['imageUrl'] - setCustomBackground(baseDir, 'shares-background') + setCustomBackground(baseDir, 'shares-background', 'follow-background') cssFilename = baseDir + '/epicyon-follow.css' if os.path.isfile(baseDir + '/follow.css'): @@ -273,7 +271,7 @@ def htmlConfirmUnblock(cssCache: {}, translate: {}, baseDir: str, """ blockDomain, port = getDomainFromActor(blockActor) - setCustomBackground(baseDir, 'block-background') + setCustomBackground(baseDir, 'block-background', 'follow-background') cssFilename = baseDir + '/epicyon-follow.css' if os.path.isfile(baseDir + '/follow.css'): diff --git a/webapp_hashtagswarm.py b/webapp_hashtagswarm.py index abf0996d5..6f4df63ed 100644 --- a/webapp_hashtagswarm.py +++ b/webapp_hashtagswarm.py @@ -201,7 +201,7 @@ def htmlSearchHashtagCategory(cssCache: {}, translate: {}, categoryStr = path.split('/category/')[1].strip() searchNickname = getNicknameFromActor(actor) - backgroundExt = setCustomBackground(baseDir, 'search-background') + setCustomBackground(baseDir, 'search-background', 'follow-background') cssFilename = baseDir + '/epicyon-search.css' if os.path.isfile(baseDir + '/search.css'): @@ -210,11 +210,6 @@ def htmlSearchHashtagCategory(cssCache: {}, translate: {}, instanceTitle = \ getConfigParam(baseDir, 'instanceTitle') htmlStr = htmlHeaderWithExternalStyle(cssFilename, instanceTitle) - if backgroundExt: - if backgroundExt != 'jpg': - htmlStr = htmlStr.replace('"follow-background.jpg"', - '"follow-background.' + - backgroundExt + '"') # show a banner above the search box searchBannerFile, searchBannerFilename = \ diff --git a/webapp_login.py b/webapp_login.py index 786112182..67d9bca3f 100644 --- a/webapp_login.py +++ b/webapp_login.py @@ -93,7 +93,7 @@ def htmlLogin(cssCache: {}, translate: {}, textModeLogo = getTextModeLogo(baseDir) textModeLogoHtml = htmlKeyboardNavigation(textModeLogo, {}, {}) - backgroundExt = setCustomBackground(baseDir, 'login-background-custom') + setCustomBackground(baseDir, 'login-background-custom', 'login-background') if accounts > 0: loginText = \ @@ -153,10 +153,6 @@ def htmlLogin(cssCache: {}, translate: {}, htmlHeaderWithWebsiteMarkup(cssFilename, instanceTitle, httpPrefix, domain, systemLanguage) - if backgroundExt: - loginForm = loginForm.replace('"login-background.jpg"', - '"login-background-custom.' + - backgroundExt + '"') nicknamePattern = getNicknameValidationPattern() instanceTitle = getConfigParam(baseDir, 'instanceTitle') diff --git a/webapp_search.py b/webapp_search.py index 94b820ec5..a6668c9b8 100644 --- a/webapp_search.py +++ b/webapp_search.py @@ -328,7 +328,7 @@ def htmlSearchEmojiTextEntry(cssCache: {}, translate: {}, actor = path.replace('/search', '') domain, port = getDomainFromActor(actor) - backgroundExt = setCustomBackground(baseDir, 'search-background') + setCustomBackground(baseDir, 'search-background', 'follow-background') cssFilename = baseDir + '/epicyon-follow.css' if os.path.isfile(baseDir + '/follow.css'): @@ -337,11 +337,6 @@ def htmlSearchEmojiTextEntry(cssCache: {}, translate: {}, instanceTitle = \ getConfigParam(baseDir, 'instanceTitle') emojiStr = htmlHeaderWithExternalStyle(cssFilename, instanceTitle) - if backgroundExt: - if backgroundExt != 'jpg': - emojiStr = emojiStr.replace('"follow-background.jpg"', - '"follow-background.' + - backgroundExt + '"') emojiStr += '