__filename__ = "webapp_confirm.py" __author__ = "Bob Mottram" __license__ = "AGPL3+" __version__ = "1.2.0" __maintainer__ = "Bob Mottram" __email__ = "bob@libreserver.org" __status__ = "Production" __module_group__ = "Web Interface" import os from shutil import copyfile from utils import get_full_domain from utils import getNicknameFromActor from utils import getDomainFromActor from utils import locate_post from utils import load_json from utils import get_config_param from utils import get_alt_path from utils import acct_dir from webapp_utils import setCustomBackground from webapp_utils import htmlHeaderWithExternalStyle from webapp_utils import htmlFooter from webapp_post import individualPostAsHtml def htmlConfirmDelete(cssCache: {}, recent_posts_cache: {}, max_recent_posts: int, translate, pageNumber: int, session, base_dir: str, messageId: str, http_prefix: str, project_version: str, cached_webfingers: {}, person_cache: {}, calling_domain: str, yt_replace_domain: str, twitter_replacement_domain: str, show_published_date_only: bool, peertube_instances: [], allow_local_network_access: bool, theme_name: str, system_language: str, max_like_count: int, signing_priv_key_pem: str, cw_lists: {}, lists_enabled: str) -> str: """Shows a screen asking to confirm the deletion of a post """ if '/statuses/' not in messageId: return None actor = messageId.split('/statuses/')[0] nickname = getNicknameFromActor(actor) domain, port = getDomainFromActor(actor) domain_full = get_full_domain(domain, port) post_filename = locate_post(base_dir, nickname, domain, messageId) if not post_filename: return None post_json_object = load_json(post_filename) if not post_json_object: return None deletePostStr = None cssFilename = base_dir + '/epicyon-profile.css' if os.path.isfile(base_dir + '/epicyon.css'): cssFilename = base_dir + '/epicyon.css' instanceTitle = \ get_config_param(base_dir, 'instanceTitle') deletePostStr = \ htmlHeaderWithExternalStyle(cssFilename, instanceTitle, None) deletePostStr += \ individualPostAsHtml(signing_priv_key_pem, True, recent_posts_cache, max_recent_posts, translate, pageNumber, base_dir, session, cached_webfingers, person_cache, nickname, domain, port, post_json_object, None, True, False, http_prefix, project_version, 'outbox', yt_replace_domain, twitter_replacement_domain, show_published_date_only, peertube_instances, allow_local_network_access, theme_name, system_language, max_like_count, False, False, False, False, False, False, cw_lists, lists_enabled) deletePostStr += '
' deletePostStr += \ '

' + \ translate['Delete this post?'] + '

' postActor = get_alt_path(actor, domain_full, calling_domain) deletePostStr += \ '
\n' deletePostStr += \ ' \n' deletePostStr += \ ' \n' deletePostStr += \ ' \n' deletePostStr += \ ' \n' deletePostStr += '
\n' deletePostStr += '
\n' deletePostStr += htmlFooter() return deletePostStr def htmlConfirmRemoveSharedItem(cssCache: {}, translate: {}, base_dir: str, actor: str, itemID: str, calling_domain: str, sharesFileType: str) -> str: """Shows a screen asking to confirm the removal of a shared item """ nickname = getNicknameFromActor(actor) domain, port = getDomainFromActor(actor) domain_full = get_full_domain(domain, port) sharesFile = \ acct_dir(base_dir, nickname, domain) + '/' + sharesFileType + '.json' if not os.path.isfile(sharesFile): print('ERROR: no ' + sharesFileType + ' file ' + sharesFile) return None sharesJson = load_json(sharesFile) if not sharesJson: print('ERROR: unable to load ' + sharesFileType + '.json') return None if not sharesJson.get(itemID): print('ERROR: share named "' + itemID + '" is not in ' + sharesFile) return None sharedItemDisplayName = sharesJson[itemID]['displayName'] sharedItemImageUrl = None if sharesJson[itemID].get('imageUrl'): sharedItemImageUrl = sharesJson[itemID]['imageUrl'] setCustomBackground(base_dir, 'shares-background', 'follow-background') cssFilename = base_dir + '/epicyon-follow.css' if os.path.isfile(base_dir + '/follow.css'): cssFilename = base_dir + '/follow.css' instanceTitle = get_config_param(base_dir, 'instanceTitle') sharesStr = htmlHeaderWithExternalStyle(cssFilename, instanceTitle, None) sharesStr += '
\n' sharesStr += '
\n' sharesStr += '
\n' if sharedItemImageUrl: sharesStr += ' \n' sharesStr += \ '

' + translate['Remove'] + \ ' ' + sharedItemDisplayName + ' ?

\n' postActor = get_alt_path(actor, domain_full, calling_domain) if sharesFileType == 'shares': endpoint = 'rmshare' else: endpoint = 'rmwanted' sharesStr += \ '
\n' sharesStr += \ ' \n' sharesStr += ' \n' sharesStr += \ ' \n' sharesStr += \ ' \n' sharesStr += '
\n' sharesStr += '
\n' sharesStr += '
\n' sharesStr += '
\n' sharesStr += htmlFooter() return sharesStr def htmlConfirmFollow(cssCache: {}, translate: {}, base_dir: str, originPathStr: str, followActor: str, followProfileUrl: str) -> str: """Asks to confirm a follow """ followDomain, port = getDomainFromActor(followActor) if os.path.isfile(base_dir + '/accounts/follow-background-custom.jpg'): if not os.path.isfile(base_dir + '/accounts/follow-background.jpg'): copyfile(base_dir + '/accounts/follow-background-custom.jpg', base_dir + '/accounts/follow-background.jpg') cssFilename = base_dir + '/epicyon-follow.css' if os.path.isfile(base_dir + '/follow.css'): cssFilename = base_dir + '/follow.css' instanceTitle = get_config_param(base_dir, 'instanceTitle') followStr = htmlHeaderWithExternalStyle(cssFilename, instanceTitle, None) followStr += '
\n' followStr += '
\n' followStr += '
\n' followStr += ' \n' followStr += ' \n' followStr += \ '

' + translate['Follow'] + ' ' + \ getNicknameFromActor(followActor) + '@' + followDomain + ' ?

\n' followStr += '
\n' followStr += ' \n' followStr += \ ' \n' followStr += \ ' \n' followStr += '
\n' followStr += '
\n' followStr += '
\n' followStr += '
\n' followStr += htmlFooter() return followStr def htmlConfirmUnfollow(cssCache: {}, translate: {}, base_dir: str, originPathStr: str, followActor: str, followProfileUrl: str) -> str: """Asks to confirm unfollowing an actor """ followDomain, port = getDomainFromActor(followActor) if os.path.isfile(base_dir + '/accounts/follow-background-custom.jpg'): if not os.path.isfile(base_dir + '/accounts/follow-background.jpg'): copyfile(base_dir + '/accounts/follow-background-custom.jpg', base_dir + '/accounts/follow-background.jpg') cssFilename = base_dir + '/epicyon-follow.css' if os.path.isfile(base_dir + '/follow.css'): cssFilename = base_dir + '/follow.css' instanceTitle = get_config_param(base_dir, 'instanceTitle') followStr = htmlHeaderWithExternalStyle(cssFilename, instanceTitle, None) followStr += '
\n' followStr += '
\n' followStr += '
\n' followStr += ' \n' followStr += ' \n' followStr += \ '

' + translate['Stop following'] + \ ' ' + getNicknameFromActor(followActor) + \ '@' + followDomain + ' ?

\n' followStr += '
\n' followStr += ' \n' followStr += \ ' \n' followStr += \ ' \n' followStr += '
\n' followStr += '
\n' followStr += '
\n' followStr += '
\n' followStr += htmlFooter() return followStr def htmlConfirmUnblock(cssCache: {}, translate: {}, base_dir: str, originPathStr: str, blockActor: str, blockProfileUrl: str) -> str: """Asks to confirm unblocking an actor """ blockDomain, port = getDomainFromActor(blockActor) setCustomBackground(base_dir, 'block-background', 'follow-background') cssFilename = base_dir + '/epicyon-follow.css' if os.path.isfile(base_dir + '/follow.css'): cssFilename = base_dir + '/follow.css' instanceTitle = get_config_param(base_dir, 'instanceTitle') blockStr = htmlHeaderWithExternalStyle(cssFilename, instanceTitle, None) blockStr += '
\n' blockStr += '
\n' blockStr += '
\n' blockStr += ' \n' blockStr += ' \n' blockStr += \ '

' + translate['Stop blocking'] + ' ' + \ getNicknameFromActor(blockActor) + '@' + blockDomain + ' ?

\n' blockStr += '
\n' blockStr += ' \n' blockStr += \ ' \n' blockStr += \ ' \n' blockStr += '
\n' blockStr += '
\n' blockStr += '
\n' blockStr += '
\n' blockStr += htmlFooter() return blockStr