__filename__ = "webapp_column_right.py" __author__ = "Bob Mottram" __license__ = "AGPL3+" __version__ = "1.2.0" __maintainer__ = "Bob Mottram" __email__ = "bob@libreserver.org" __status__ = "Production" __module_group__ = "Web Interface Columns" import os from datetime import datetime from content import remove_long_words from content import limit_repeated_words from utils import get_fav_filename_from_url from utils import get_base_content_from_post from utils import remove_html from utils import locate_post from utils import load_json from utils import votes_on_newswire_item from utils import get_nickname_from_actor from utils import is_editor from utils import get_config_param from utils import remove_domain_port from utils import acct_dir from posts import is_moderator from newswire import get_newswire_favicon_url from webapp_utils import get_right_image_file from webapp_utils import html_header_with_external_style from webapp_utils import html_footer from webapp_utils import get_banner_file from webapp_utils import html_post_separator from webapp_utils import header_buttons_front_screen from webapp_utils import edit_text_field def _votes_indicator(total_votes: int, positive_voting: bool) -> str: """Returns an indicator of the number of votes on a newswire item """ if total_votes <= 0: return '' total_votes_str = ' ' for _ in range(total_votes): if positive_voting: total_votes_str += '✓' else: total_votes_str += '✗' return total_votes_str def get_right_column_content(base_dir: str, nickname: str, domain_full: str, http_prefix: str, translate: {}, moderator: bool, editor: bool, newswire: {}, positive_voting: bool, show_back_button: bool, timeline_path: str, show_publish_button: bool, show_publish_as_icon: bool, rss_icon_at_top: bool, publish_button_at_top: bool, authorized: bool, show_header_image: bool, theme: str, default_timeline: str, access_keys: {}) -> str: """Returns html content for the right column """ html_str = '' domain = remove_domain_port(domain_full) if authorized: # only show the publish button if logged in, otherwise replace it with # a login button title_str = translate['Publish a blog article'] if default_timeline == 'tlfeatures': title_str = translate['Publish a news article'] publish_button_str = \ ' ' + \ '\n' else: # if not logged in then replace the publish button with # a login button publish_button_str = \ ' \n' # show publish button at the top if needed if publish_button_at_top: html_str += '
' + \ '' + \ '' + \ favicon_link + title + '' + total_votes_str if moderator: html_str += \ ' ' + date_shown + '' html_str += '
\n' else: html_str += ' ' html_str += date_shown + '\n' else: total_votes_str = '' total_votes = 0 if moderator: if moderated_item: total_votes = votes_on_newswire_item(item[2]) # show a number of ticks or crosses for how many # votes for or against total_votes_str = \ _votes_indicator(total_votes, positive_voting) title = remove_long_words(item[0], 16, []).replace('\n', '' + \ '' + \ favicon_link + title + '' + total_votes_str html_str += ' ' + date_shown html_str += '' html_str += '' html_str += '
\n' else: html_str += '' + \ '' + \ favicon_link + title + '' + total_votes_str html_str += ' ' html_str += date_shown + '
\n' if html_str: html_str = '\n' return html_str def html_citations(base_dir: str, nickname: str, domain: str, http_prefix: str, default_timeline: str, translate: {}, newswire: {}, css_cache: {}, blog_title: str, blog_content: str, blog_image_filename: str, blog_image_attachment_media_type: str, blog_image_description: str, theme: str) -> str: """Show the citations screen when creating a blog """ html_str = '' # create a list of dates for citations # these can then be used to re-select checkboxes later citations_filename = \ acct_dir(base_dir, nickname, domain) + '/.citations.txt' citations_selected = [] if os.path.isfile(citations_filename): citations_separator = '#####' with open(citations_filename, 'r') as fp_cit: citations = fp_cit.readlines() for line in citations: if citations_separator not in line: continue sections = line.strip().split(citations_separator) if len(sections) != 3: continue date_str = sections[0] citations_selected.append(date_str) # the css filename css_filename = base_dir + '/epicyon-profile.css' if os.path.isfile(base_dir + '/epicyon.css'): css_filename = base_dir + '/epicyon.css' instance_title = \ get_config_param(base_dir, 'instanceTitle') html_str = \ html_header_with_external_style(css_filename, instance_title, None) # top banner banner_file, _ = \ get_banner_file(base_dir, nickname, domain, theme) html_str += \ '\n' html_str += '\n' html_str += \ '\n' return html_str + html_footer() def html_newswire_mobile(css_cache: {}, base_dir: str, nickname: str, domain: str, domain_full: str, http_prefix: str, translate: {}, newswire: {}, positive_voting: bool, timeline_path: str, show_publish_as_icon: bool, authorized: bool, rss_icon_at_top: bool, icons_as_buttons: bool, default_timeline: str, theme: str, access_keys: {}) -> str: """Shows the mobile version of the newswire right column """ html_str = '' # the css filename css_filename = base_dir + '/epicyon-profile.css' if os.path.isfile(base_dir + '/epicyon.css'): css_filename = base_dir + '/epicyon.css' if nickname == 'news': editor = False moderator = False else: # is the user a moderator? moderator = is_moderator(base_dir, nickname) # is the user a site editor? editor = is_editor(base_dir, nickname) show_publish_button = editor instance_title = \ get_config_param(base_dir, 'instanceTitle') html_str = \ html_header_with_external_style(css_filename, instance_title, None) banner_file, _ = \ get_banner_file(base_dir, nickname, domain, theme) html_str += \ '' + \ '\n' html_str += '