def __build_profile_menu(self, profile): if profile.is_me(): return "<span class='disabled action_you'>%s</span>" % (i18n.get('this_is_you')) menu = '' cmd = "'%s','%s'" % (profile.account_id, profile.username) # Direct Messages menu += "<a href=\"javascript: send_direct_from_profile(%s)\" class='action'>%s</a>" % (cmd, i18n.get('message')) # Follow cmd = ARG_SEP.join([profile.account_id, profile.username]) if profile.following: label = i18n.get('do_you_want_to_unfollow_user') % profile.username menu += """<a id='profile-follow-cmd' href="javascript:show_confirm_window('%s', '%s', 'cmd:unfollow:%s')" class='action'>%s</a>""" % ( i18n.get('confirm_unfollow'), label, cmd, i18n.get('unfollow')) elif profile.follow_request: menu += "<span class='action'>%s</span>" % (i18n.get('requested')) else: menu += "<a id='profile-follow-cmd' href='cmd:follow:%s' class='action'>%s</a>" % (cmd, i18n.get('follow')) # Mute if profile.muted: menu += "<a id='profile-mute-cmd' href='cmd:unmute:%s' class='action'>%s</a>" % (profile.username, i18n.get('unmute')) else: menu += "<a id='profile-mute-cmd' href='cmd:mute:%s' class='action'>%s</a>" % (profile.username, i18n.get('mute')) # Block menu += "<a href='cmd:block:%s' class='action'>%s</a>" % (cmd, i18n.get('block')) # Spam menu += "<a href='cmd:report_spam:%s' class='action'>%s</a>" % (cmd, i18n.get('spam')) return menu
def __build_status_menu(self, status): menu = '' if not status.is_own and not status.is_direct(): # Reply mentions = status.get_reply_mentions() str_mentions = '[\'' + '\',\''.join(mentions) + '\']' title = i18n.get('in_reply_to').capitalize() + " " + mentions[0] cmd = "'%s','%s','%s',%s" % (status.account_id, status.id_, title, str_mentions) menu += "<a href=\"javascript: reply_status(%s)\" class='action'>%s</a>" % (cmd, self.__image_tag('action-reply.png', tooltip=i18n.get('reply'))) # Repeat args = ARG_SEP.join([status.account_id, status.id_, status.username, self.__url_quote(status.text)]) menu += "<a href='cmd:repeat_menu:%s' class='action'>%s</a>" % (args, self.__image_tag('action-repeat.png', tooltip=i18n.get('repeat'))) # Conversation if status.in_reply_to_user: args = ARG_SEP.join([status.account_id, status.id_, '%s' % status.in_reply_to_id]) menu += """<a href='cmd:show_conversation:%s' class='action'>%s</a>""" % (args, self.__image_tag('action-conversation.png', tooltip=i18n.get('conversation'))) elif not status.is_own and status.is_direct(): # Reply cmd = "'%s','%s'" % (status.account_id, status.username) menu += "<a href=\"javascript: reply_direct(%s)\" class='action'>%s</a>" % (cmd, self.__image_tag('action-reply.png', tooltip=i18n.get('reply'))) # Delete cmd = ARG_SEP.join([status.account_id, status.id_]) menu += """<a href="javascript:show_confirm_window('%s', '%s', 'cmd:delete_direct:%s')" class='action'>%s</a>""" % ( i18n.get('confirm_delete'), i18n.get('do_you_want_to_delete_direct_message'), cmd, self.__image_tag('action-delete.png', tooltip=i18n.get('delete'))) elif status.is_own and not status.is_direct(): cmd = ARG_SEP.join([status.account_id, status.id_]) menu += """<a href="javascript:show_confirm_window('%s', '%s', 'cmd:delete_status:%s')" class='action'>%s</a>""" % ( i18n.get('confirm_delete'), i18n.get('do_you_want_to_delete_status'), cmd, self.__image_tag('action-clear.png', tooltip=i18n.get('delete'))) elif status.is_own and status.is_direct(): cmd = ARG_SEP.join([status.account_id, status.id_]) menu += """<a href="javascript:show_confirm_window('%s', '%s', 'cmd:delete_direct:%s')" class='action'>%s</a>""" % ( i18n.get('confirm_delete'), i18n.get('do_you_want_to_delete_direct_message'), cmd, self.__image_tag('action-clear.png', tooltip=i18n.get('delete'))) return menu
def __highlight_urls(self, status, text): for url in status.entities['urls']: if url.url == None: url.url = url.search_for #if url.url[0:7] != "http://": # url.url = "http://%s" % url.url if not showmediautils.is_service_supported(url.url): cad = '<a href="link:%s" title="%s">%s</a>' % (url.url, url.url, url.display_text) else: pars = ARG_SEP.join([url.url.replace(":", "$"), status.account_id]) cad = '<a href="cmd:show_media:%s" title="%s">%s</a>' % (pars, url.url, url.display_text) text = text.replace(url.search_for, cad) return text
def __highlight_urls(self, status, text): for url in status.entities['urls']: if url.url == None: url.url = url.search_for #if url.url[0:7] != "http://": # url.url = "http://%s" % url.url if not showmediautils.is_service_supported(url.url): cad = '<a href="link:%s" title="%s">%s</a>' % ( url.url, url.url, url.display_text) else: pars = ARG_SEP.join( [url.url.replace(":", "$"), status.account_id]) cad = '<a href="cmd:show_media:%s" title="%s">%s</a>' % ( pars, url.url, url.display_text) text = text.replace(url.search_for, cad) return text
def __build_profile_menu(self, profile): if profile.is_me(): return "<span class='disabled action_you'>%s</span>" % ( i18n.get('this_is_you')) menu = '' cmd = "'%s','%s'" % (profile.account_id, profile.username) # Direct Messages menu += "<a href=\"javascript: send_direct_from_profile(%s)\" class='action'>%s</a>" % ( cmd, i18n.get('message')) # Follow cmd = ARG_SEP.join([profile.account_id, profile.username]) if profile.following: label = i18n.get('do_you_want_to_unfollow_user') % profile.username menu += """<a id='profile-follow-cmd' href="javascript:show_confirm_window('%s', '%s', 'cmd:unfollow:%s')" class='action'>%s</a>""" % ( i18n.get('confirm_unfollow'), label, cmd, i18n.get('unfollow')) elif profile.follow_request: menu += "<span class='action'>%s</span>" % (i18n.get('requested')) else: menu += "<a id='profile-follow-cmd' href='cmd:follow:%s' class='action'>%s</a>" % ( cmd, i18n.get('follow')) # Mute if profile.muted: menu += "<a id='profile-mute-cmd' href='cmd:unmute:%s' class='action'>%s</a>" % ( profile.username, i18n.get('unmute')) else: menu += "<a id='profile-mute-cmd' href='cmd:mute:%s' class='action'>%s</a>" % ( profile.username, i18n.get('mute')) # Block menu += "<a href='cmd:block:%s' class='action'>%s</a>" % ( cmd, i18n.get('block')) # Spam menu += "<a href='cmd:report_spam:%s' class='action'>%s</a>" % ( cmd, i18n.get('spam')) return menu
def status(self, status, ignore_reply=False, profile_status=False): timestamp = status.datetime if status.source: if status.source.url: timestamp += ' %s <a href="link:%s">%s</a>' % (i18n.get('from'), status.source.url, status.source.name) else: timestamp += ' %s %s' % (i18n.get('from'), status.source.name) if status.in_reply_to_user and not ignore_reply: timestamp += ' %s %s' % (i18n.get('in_reply_to'), status.in_reply_to_user) reposted_by = '' if status.reposted_by: count = len(status.reposted_by) if count > 1: temp = '%i %s' % (count, i18n.get('people')) elif count == 1: temp = '1 %s' % i18n.get('person') reposted_by = '%s %s' % (i18n.get('retweeted_by'), status.reposted_by) args = ARG_SEP.join([status.account_id, status.id_]) tmp_cmd = "<a name='fav-cmd' href='%s' class='action'>%s</a>" if status.is_favorite: cmd = "cmd:unfav_status:%s" % args fav_cmd = tmp_cmd % (cmd, self.__image_tag('action-fav.png', tooltip=i18n.get('-fav'))) is_fav = 'true' show_fav = '' else: cmd = "cmd:fav_status:%s" % args fav_cmd = tmp_cmd % (cmd, self.__image_tag('action-unfav.png', tooltip=i18n.get('+fav'))) is_fav = 'false' show_fav = 'display: none' message = self.__highlight_urls(status, status.text) message = self.__highlight_hashtags(status, message) message = self.__highlight_groups(status, message) message = self.__highlight_mentions(status, message) message = message.replace('\r', ' ') message = message.replace('\\"', '"') message = message.replace('\\', "\") username = self.__highlight_username(status) menu = self.__build_status_menu(status) args = ARG_SEP.join([status.account_id, status.id_]) # Decide what template to use if profile_status: section = self.__open_partial('profile_status') else: section = self.__open_partial('status') section = section.replace('<% @status_id %>', status.id_) section = section.replace('<% @status_display_id %>', status.display_id) if status.in_reply_to_id: section = section.replace('<% @status_replyto_id %>', '%s' % status.id_) else: section = section.replace('<% @status_replyto_id %>', '') section = section.replace('<% @avatar %>', status.avatar) section = section.replace('<% @account_id %>', status.account_id) section = section.replace('<% @clean_username %>', status.username) section = section.replace('<% @username %>', username) section = section.replace('<% @message %>', message) section = section.replace('<% @timestamp %>', timestamp) section = section.replace('<% @reposted_by %>', reposted_by) section = section.replace('<% @verified %>', self.__verified_tag(status.is_verified)) section = section.replace('<% @protected %>', self.__protected_tag(status.is_protected)) section = section.replace('<% @reposted %>', self.__reposted_tag(status.reposted_by)) section = section.replace('<% @is_fav %>', is_fav) section = section.replace('<% @show_favorite %>', show_fav) section = section.replace('<% @favorite_cmd %>', fav_cmd) section = section.replace('<% @retweeted_visible %>', self.__retweeted_visible(status)) section = section.replace('<% @retweeted %>', self.__retweeted_tag()) section = section.replace('<% @menu %>', menu) return section
def status(self, status, ignore_reply=False, profile_status=False): timestamp = status.datetime if status.source: if status.source.url: timestamp += ' %s <a href="link:%s">%s</a>' % ( i18n.get('from'), status.source.url, status.source.name) else: timestamp += ' %s %s' % (i18n.get('from'), status.source.name) if status.in_reply_to_user and not ignore_reply: timestamp += ' %s %s' % (i18n.get('in_reply_to'), status.in_reply_to_user) reposted_by = '' if status.reposted_by: count = len(status.reposted_by) if count > 1: temp = '%i %s' % (count, i18n.get('people')) elif count == 1: temp = '1 %s' % i18n.get('person') reposted_by = '%s %s' % (i18n.get('retweeted_by'), status.reposted_by) args = ARG_SEP.join([status.account_id, status.id_]) tmp_cmd = "<a name='fav-cmd' href='%s' class='action'>%s</a>" if status.is_favorite: cmd = "cmd:unfav_status:%s" % args fav_cmd = tmp_cmd % (cmd, self.__image_tag('action-fav.png', tooltip=i18n.get('-fav'))) is_fav = 'true' show_fav = '' else: cmd = "cmd:fav_status:%s" % args fav_cmd = tmp_cmd % (cmd, self.__image_tag('action-unfav.png', tooltip=i18n.get('+fav'))) is_fav = 'false' show_fav = 'display: none' message = self.__highlight_urls(status, status.text) message = self.__highlight_hashtags(status, message) message = self.__highlight_groups(status, message) message = self.__highlight_mentions(status, message) message = message.replace('\r', ' ') message = message.replace('\\"', '"') message = message.replace('\\', "\") username = self.__highlight_username(status) menu = self.__build_status_menu(status) args = ARG_SEP.join([status.account_id, status.id_]) # Decide what template to use if profile_status: section = self.__open_partial('profile_status') else: section = self.__open_partial('status') section = section.replace('<% @status_id %>', status.id_) section = section.replace('<% @status_display_id %>', status.display_id) if status.in_reply_to_id: section = section.replace('<% @status_replyto_id %>', '%s' % status.id_) else: section = section.replace('<% @status_replyto_id %>', '') section = section.replace('<% @avatar %>', status.avatar) section = section.replace('<% @account_id %>', status.account_id) section = section.replace('<% @clean_username %>', status.username) section = section.replace('<% @username %>', username) section = section.replace('<% @message %>', message) section = section.replace('<% @timestamp %>', timestamp) section = section.replace('<% @reposted_by %>', reposted_by) section = section.replace('<% @verified %>', self.__verified_tag(status.is_verified)) section = section.replace('<% @protected %>', self.__protected_tag(status.is_protected)) section = section.replace('<% @reposted %>', self.__reposted_tag(status.reposted_by)) section = section.replace('<% @is_fav %>', is_fav) section = section.replace('<% @show_favorite %>', show_fav) section = section.replace('<% @favorite_cmd %>', fav_cmd) section = section.replace('<% @retweeted_visible %>', self.__retweeted_visible(status)) section = section.replace('<% @retweeted %>', self.__retweeted_tag()) section = section.replace('<% @menu %>', menu) return section
def __build_status_menu(self, status): menu = '' if not status.is_own and not status.is_direct(): # Reply mentions = status.get_reply_mentions() str_mentions = '[\'' + '\',\''.join(mentions) + '\']' title = i18n.get('in_reply_to').capitalize() + " " + mentions[0] cmd = "'%s','%s','%s',%s" % (status.account_id, status.id_, title, str_mentions) menu += "<a href=\"javascript: reply_status(%s)\" class='action'>%s</a>" % ( cmd, self.__image_tag('action-reply.png', tooltip=i18n.get('reply'))) # Repeat args = ARG_SEP.join([ status.account_id, status.id_, status.username, self.__url_quote(status.text) ]) menu += "<a href='cmd:repeat_menu:%s' class='action'>%s</a>" % ( args, self.__image_tag('action-repeat.png', tooltip=i18n.get('repeat'))) # Conversation if status.in_reply_to_user: args = ARG_SEP.join([ status.account_id, status.id_, '%s' % status.in_reply_to_id ]) menu += """<a href='cmd:show_conversation:%s' class='action'>%s</a>""" % ( args, self.__image_tag('action-conversation.png', tooltip=i18n.get('conversation'))) elif not status.is_own and status.is_direct(): # Reply cmd = "'%s','%s'" % (status.account_id, status.username) menu += "<a href=\"javascript: reply_direct(%s)\" class='action'>%s</a>" % ( cmd, self.__image_tag('action-reply.png', tooltip=i18n.get('reply'))) # Delete cmd = ARG_SEP.join([status.account_id, status.id_]) menu += """<a href="javascript:show_confirm_window('%s', '%s', 'cmd:delete_direct:%s')" class='action'>%s</a>""" % ( i18n.get('confirm_delete'), i18n.get('do_you_want_to_delete_direct_message'), cmd, self.__image_tag('action-delete.png', tooltip=i18n.get('delete'))) elif status.is_own and not status.is_direct(): cmd = ARG_SEP.join([status.account_id, status.id_]) menu += """<a href="javascript:show_confirm_window('%s', '%s', 'cmd:delete_status:%s')" class='action'>%s</a>""" % ( i18n.get('confirm_delete'), i18n.get('do_you_want_to_delete_status'), cmd, self.__image_tag('action-clear.png', tooltip=i18n.get('delete'))) elif status.is_own and status.is_direct(): cmd = ARG_SEP.join([status.account_id, status.id_]) menu += """<a href="javascript:show_confirm_window('%s', '%s', 'cmd:delete_direct:%s')" class='action'>%s</a>""" % ( i18n.get('confirm_delete'), i18n.get('do_you_want_to_delete_direct_message'), cmd, self.__image_tag('action-clear.png', tooltip=i18n.get('delete'))) return menu