diff --git a/daemon.py b/daemon.py index f42c15bec..38569277f 100644 --- a/daemon.py +++ b/daemon.py @@ -147,6 +147,7 @@ from webapp_utils import getAvatarImageUrl from webapp_utils import htmlHashtagBlocked from webapp_utils import htmlFollowingList from webapp_utils import setBlogAddress +from webapp_utils import htmlShowShare from webapp_calendar import htmlCalendarDeleteConfirm from webapp_calendar import htmlCalendar from webapp_about import htmlAbout @@ -11254,6 +11255,37 @@ class PubServer(BaseHTTPRequestHandler): 'person options done', 'blog post 2 done') + # after selecting a shared item from the left column then show it + if htmlGET and '?showshare=' in self.path: + itemID = self.path.split('?showshare=')[1] + usersPath = self.path.split('?showshare=')[0] + itemID = urllib.parse.unquote_plus(itemID.strip()) + msg = \ + htmlShowShare(self.server.baseDir, + self.server.domain, self.server.nickname, + self.server.httpPrefix, self.server.domainFull, + itemID, self.server.translate, + self.server.sharedItemsFederatedDomains) + if not msg: + if callingDomain.endswith('.onion') and \ + self.server.onionDomain: + actor = 'http://' + self.server.onionDomain + usersPath + elif (callingDomain.endswith('.i2p') and + self.server.i2pDomain): + actor = 'http://' + self.server.i2pDomain + usersPath + self._redirect_headers(actor + '/tlshares', + cookie, callingDomain) + return + msg = msg.encode('utf-8') + msglen = len(msg) + self._set_headers('text/html', msglen, + cookie, callingDomain) + self._write(msg) + self._benchmarkGETtimings(GETstartTime, GETtimings, + 'blog post 2 done', + 'htmlShowShare') + return + # remove a shared item if htmlGET and '?rmshare=' in self.path: itemID = self.path.split('?rmshare=')[1] diff --git a/webapp_column_left.py b/webapp_column_left.py index f804cfc4e..b13bf03a2 100644 --- a/webapp_column_left.py +++ b/webapp_column_left.py @@ -53,9 +53,9 @@ def _getLeftColumnShares(baseDir: str, sharedesc = item['displayName'] if '<' in sharedesc or '?' in sharedesc: continue - contactActor = item['actor'] - shareLink = actor + '?replydm=sharedesc:' + \ - sharedesc.replace(' ', '_') + '?mention=' + contactActor + shareId = item['shareId'] + # selecting this link calls htmlShowShare + shareLink = actor + '?showshare=' + shareId linksList.append(sharedesc + ' ' + shareLink) ctr += 1 if ctr >= maxSharesInLeftColumn: diff --git a/webapp_search.py b/webapp_search.py index aec4f78ba..31d03f1af 100644 --- a/webapp_search.py +++ b/webapp_search.py @@ -25,7 +25,6 @@ from utils import firstParagraphFromString from utils import searchBoxPosts from utils import getAltPath from utils import acctDir -from utils import isfloat from skills import noOfActorSkills from skills import getSkillsFromList from categories import getHashtagCategory @@ -36,6 +35,7 @@ from webapp_utils import htmlHeaderWithExternalStyle from webapp_utils import htmlFooter from webapp_utils import getSearchBannerFile from webapp_utils import htmlPostSeparator +from webapp_utils import htmlSearchResultShare from webapp_post import individualPostAsHtml from webapp_hashtagswarm import htmlHashTagSwarm @@ -120,60 +120,6 @@ def _matchSharedItem(searchStrLowerList: [], return False -def _htmlSearchResultShare(sharedItem: {}, translate: {}, - httpPrefix: str, domainFull: str, - contactNickname: str, name: str, - actor: str) -> str: - """Returns the html for an individual shared item - """ - sharedItemsForm = '
\n' - sharedItemsForm += \ - '

' + sharedItem['displayName'] + '

\n' - if sharedItem.get('imageUrl'): - sharedItemsForm += \ - '\n' - sharedItemsForm += \ - 'Item image\n' - sharedItemsForm += '

' + sharedItem['summary'] + '

\n

' - if sharedItem.get('itemQty'): - if sharedItem['itemQty'] > 1: - sharedItemsForm += \ - '' + translate['Quantity'] + \ - ': ' + str(sharedItem['itemQty']) + '
' - sharedItemsForm += \ - '' + translate['Type'] + ': ' + sharedItem['itemType'] + '
' - sharedItemsForm += \ - '' + translate['Category'] + ': ' + \ - sharedItem['category'] + '
' - if sharedItem.get('location'): - sharedItemsForm += \ - '' + translate['Location'] + ': ' + \ - sharedItem['location'] + '
' - if sharedItem.get('itemPrice') and \ - sharedItem.get('itemCurrency'): - if isfloat(sharedItem['itemPrice']): - if float(sharedItem['itemPrice']) > 0: - sharedItemsForm += \ - ' ' + translate['Price'] + \ - ': ' + sharedItem['itemPrice'] + \ - ' ' + sharedItem['itemCurrency'] - sharedItemsForm += '

\n' - contactActor = \ - httpPrefix + '://' + domainFull + '/users/' + contactNickname - sharedItemsForm += \ - '

\n' - if actor.endswith('/users/' + contactNickname): - sharedItemsForm += \ - ' \n' - sharedItemsForm += '

\n' - return sharedItemsForm - - def _htmlSearchResultSharePage(actor: str, domainFull: str, callingDomain: str, pageNumber: int, searchStrLower: str, translate: {}, @@ -227,10 +173,10 @@ def _htmlSharesResult(sharesJson: {}, pageNumber: int, resultsPerPage: int, if currPage == pageNumber: # show individual search result sharedItemsForm += \ - _htmlSearchResultShare(sharedItem, translate, - httpPrefix, domainFull, - contactNickname, - name, actor) + htmlSearchResultShare(sharedItem, translate, + httpPrefix, domainFull, + contactNickname, + name, actor) if not resultsExist and currPage > 1: # show the previous page button sharedItemsForm += \ diff --git a/webapp_utils.py b/webapp_utils.py index 0f1a2da73..b3457de1f 100644 --- a/webapp_utils.py +++ b/webapp_utils.py @@ -18,6 +18,8 @@ from utils import loadJson from utils import getCachedPostFilename from utils import getConfigParam from utils import acctDir +from utils import getNicknameFromActor +from utils import isfloat from cache import storePersonInCache from content import addHtmlTags from content import replaceEmojiFromTags @@ -1249,3 +1251,120 @@ def editTextArea(label: str, name: str, value: str = "", text += 'spellcheck="' + str(spellcheck).lower() + '">' text += value + '\n' return text + + +def htmlSearchResultShare(sharedItem: {}, translate: {}, + httpPrefix: str, domainFull: str, + contactNickname: str, name: str, + actor: str) -> str: + """Returns the html for an individual shared item + """ + sharedItemsForm = '
\n' + sharedItemsForm += \ + '

' + sharedItem['displayName'] + '

\n' + if sharedItem.get('imageUrl'): + sharedItemsForm += \ + '\n' + sharedItemsForm += \ + 'Item image\n' + sharedItemsForm += '

' + sharedItem['summary'] + '

\n

' + if sharedItem.get('itemQty'): + if sharedItem['itemQty'] > 1: + sharedItemsForm += \ + '' + translate['Quantity'] + \ + ': ' + str(sharedItem['itemQty']) + '
' + sharedItemsForm += \ + '' + translate['Type'] + ': ' + sharedItem['itemType'] + '
' + sharedItemsForm += \ + '' + translate['Category'] + ': ' + \ + sharedItem['category'] + '
' + if sharedItem.get('location'): + sharedItemsForm += \ + '' + translate['Location'] + ': ' + \ + sharedItem['location'] + '
' + if sharedItem.get('itemPrice') and \ + sharedItem.get('itemCurrency'): + if isfloat(sharedItem['itemPrice']): + if float(sharedItem['itemPrice']) > 0: + sharedItemsForm += \ + ' ' + translate['Price'] + \ + ': ' + sharedItem['itemPrice'] + \ + ' ' + sharedItem['itemCurrency'] + sharedItemsForm += '

\n' + contactActor = \ + httpPrefix + '://' + domainFull + '/users/' + contactNickname + sharedItemsForm += \ + '

\n' + if actor.endswith('/users/' + contactNickname): + sharedItemsForm += \ + ' \n' + sharedItemsForm += '

\n' + return sharedItemsForm + + +def htmlShowShare(baseDir: str, domain: str, nickname: str, + httpPrefix: str, domainFull: str, + itemID: str, translate: {}, + sharedItemsFederatedDomains: []) -> str: + """Shows an individual shared item after selecting it from the left column + """ + sharesJson = None + + shareUrl = itemID.replace('___', '://').replace('--', '/') + contactNickname = getNicknameFromActor(shareUrl) + if not contactNickname: + return None + + if '://' + domainFull + '/' in shareUrl: + # shared item on this instance + sharesFilename = \ + acctDir(baseDir, contactNickname, domain) + '/shares.json' + if not os.path.isfile(sharesFilename): + return None + sharesJson = loadJson(sharesFilename) + else: + # federated shared item + catalogsDir = baseDir + '/cache/catalogs' + if not os.path.isdir(catalogsDir): + return None + for subdir, dirs, files in os.walk(catalogsDir): + for f in files: + if '#' in f: + continue + if not f.endswith('.shares.json'): + continue + federatedDomain = f.split('.')[0] + if federatedDomain not in sharedItemsFederatedDomains: + continue + sharesFilename = catalogsDir + '/' + f + sharesJson = loadJson(sharesFilename) + if not sharesJson: + continue + if sharesJson.get(itemID): + break + break + + if not sharesJson: + return None + if not sharesJson.get(itemID): + return None + sharedItem = sharesJson[itemID] + actor = httpPrefix + '://' + domainFull + '/users/' + nickname + shareStr = \ + htmlSearchResultShare(sharedItem, translate, httpPrefix, + domainFull, contactNickname, itemID, + actor) + + cssFilename = baseDir + '/epicyon-profile.css' + if os.path.isfile(baseDir + '/epicyon.css'): + cssFilename = baseDir + '/epicyon.css' + instanceTitle = \ + getConfigParam(baseDir, 'instanceTitle') + + return htmlHeaderWithExternalStyle(cssFilename, instanceTitle) + \ + shareStr + htmlFooter()