epicyon/webapp_frontscreen.py

215 lines
9.3 KiB
Python
Raw Normal View History

__filename__ = "webapp_frontscreen.py"
__author__ = "Bob Mottram"
__license__ = "AGPL3+"
2021-01-26 10:07:42 +00:00
__version__ = "1.2.0"
__maintainer__ = "Bob Mottram"
2021-09-10 16:14:50 +00:00
__email__ = "bob@libreserver.org"
__status__ = "Production"
2021-06-26 11:27:14 +00:00
__module_group__ = "Timeline"
import os
2021-12-27 15:41:04 +00:00
from utils import is_system_account
2021-12-27 19:05:25 +00:00
from utils import get_domain_from_actor
2021-12-26 14:08:58 +00:00
from utils import get_config_param
2021-12-28 16:50:20 +00:00
from person import person_box_json
2021-12-29 21:55:09 +00:00
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_column_left import get_left_column_content
from webapp_column_right import get_right_column_content
from webapp_post import individual_post_as_html
2021-12-29 21:55:09 +00:00
def _html_front_screen_posts(recent_posts_cache: {}, max_recent_posts: int,
translate: {},
base_dir: str, http_prefix: str,
nickname: str, domain: str, port: int,
session, cached_webfingers: {}, person_cache: {},
project_version: 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 posts on the front screen of a news instance
These should only be public blog posts from the features timeline
which is the blog timeline of the news actor
"""
2021-12-29 21:55:09 +00:00
separatorStr = html_post_separator(base_dir, None)
profileStr = ''
maxItems = 4
ctr = 0
currPage = 1
boxName = 'tlfeatures'
authorized = True
while ctr < maxItems and currPage < 4:
outboxFeedPathStr = \
'/users/' + nickname + '/' + boxName + \
'?page=' + str(currPage)
outboxFeed = \
2021-12-28 16:50:20 +00:00
person_box_json({}, session, base_dir, domain, port,
outboxFeedPathStr,
http_prefix, 10, boxName,
authorized, 0, False, 0)
if not outboxFeed:
break
if len(outboxFeed['orderedItems']) == 0:
break
for item in outboxFeed['orderedItems']:
if item['type'] == 'Create':
postStr = \
2021-12-29 21:55:09 +00:00
individual_post_as_html(signing_priv_key_pem,
True, recent_posts_cache,
max_recent_posts,
translate, None,
base_dir, session,
cached_webfingers,
person_cache,
nickname, domain, port, item,
None, True, False,
http_prefix,
project_version, 'inbox',
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,
True, False, False,
cw_lists, lists_enabled)
if postStr:
profileStr += postStr + separatorStr
ctr += 1
if ctr >= maxItems:
break
currPage += 1
return profileStr
2021-12-29 21:55:09 +00:00
def html_front_screen(signing_priv_key_pem: str,
rss_icon_at_top: bool,
css_cache: {}, icons_as_buttons: bool,
2021-12-31 23:50:29 +00:00
default_timeline: str,
2021-12-29 21:55:09 +00:00
recent_posts_cache: {}, max_recent_posts: int,
translate: {}, project_version: str,
base_dir: str, http_prefix: str, authorized: bool,
profile_json: {}, selected: str,
session, cached_webfingers: {}, person_cache: {},
yt_replace_domain: str,
twitter_replacement_domain: str,
show_published_date_only: bool,
newswire: {}, theme: str,
peertube_instances: [],
allow_local_network_access: bool,
2021-12-31 21:18:12 +00:00
access_keys: {},
2021-12-29 21:55:09 +00:00
system_language: str, max_like_count: int,
shared_items_federated_domains: [],
extraJson: {},
pageNumber: int,
maxItemsPerPage: int,
cw_lists: {}, lists_enabled: str) -> str:
"""Show the news instance front screen
"""
2021-12-26 10:08:06 +00:00
nickname = profile_json['preferredUsername']
if not nickname:
return ""
2021-12-27 15:41:04 +00:00
if not is_system_account(nickname):
return ""
2021-12-27 19:05:25 +00:00
domain, port = get_domain_from_actor(profile_json['id'])
if not domain:
return ""
2021-12-26 10:00:46 +00:00
domain_full = domain
if port:
2021-12-26 10:00:46 +00:00
domain_full = domain + ':' + str(port)
2021-12-29 21:55:09 +00:00
loginButton = header_buttons_front_screen(translate, nickname,
'features', authorized,
icons_as_buttons)
# If this is the news account then show a different banner
2021-12-31 21:18:12 +00:00
banner_file, banner_filename = \
2021-12-29 21:55:09 +00:00
get_banner_file(base_dir, nickname, domain, theme)
profileHeaderStr = \
'<img loading="lazy" class="timeline-banner" ' + \
2021-12-31 21:18:12 +00:00
'src="/users/' + nickname + '/' + banner_file + '" />\n'
if loginButton:
profileHeaderStr += '<center>' + loginButton + '</center>\n'
2021-07-05 20:24:43 +00:00
profileHeaderStr += \
'<table class="timeline">\n' + \
' <colgroup>\n' + \
' <col span="1" class="column-left">\n' + \
' <col span="1" class="column-center">\n' + \
' <col span="1" class="column-right">\n' + \
' </colgroup>\n' + \
' <tbody>\n' + \
' <tr>\n' + \
' <td valign="top" class="col-left">\n'
profileHeaderStr += \
2021-12-29 21:55:09 +00:00
get_left_column_content(base_dir, 'news', domain_full,
http_prefix, translate,
False, False,
False, None, rss_icon_at_top, True,
2021-12-31 21:18:12 +00:00
True, theme, access_keys,
2021-12-29 21:55:09 +00:00
shared_items_federated_domains)
2021-07-05 20:24:43 +00:00
profileHeaderStr += \
' </td>\n' + \
' <td valign="top" class="col-center">\n'
profileStr = profileHeaderStr
2021-12-31 21:18:12 +00:00
css_filename = base_dir + '/epicyon-profile.css'
2021-12-25 16:17:53 +00:00
if os.path.isfile(base_dir + '/epicyon.css'):
2021-12-31 21:18:12 +00:00
css_filename = base_dir + '/epicyon.css'
licenseStr = ''
2021-12-31 21:18:12 +00:00
banner_file, banner_filename = \
2021-12-29 21:55:09 +00:00
get_banner_file(base_dir, nickname, domain, theme)
profileStr += \
2021-12-29 21:55:09 +00:00
_html_front_screen_posts(recent_posts_cache, max_recent_posts,
translate,
base_dir, http_prefix,
nickname, domain, port,
session, cached_webfingers, person_cache,
project_version,
yt_replace_domain,
twitter_replacement_domain,
show_published_date_only,
peertube_instances,
allow_local_network_access,
theme, system_language,
max_like_count,
signing_priv_key_pem,
cw_lists, lists_enabled) + licenseStr
# Footer which is only used for system accounts
profileFooterStr = ' </td>\n'
profileFooterStr += ' <td valign="top" class="col-right">\n'
profileFooterStr += \
2021-12-29 21:55:09 +00:00
get_right_column_content(base_dir, 'news', domain_full,
http_prefix, translate,
False, False, newswire, False,
False, None, False, False,
False, True, authorized, True, theme,
2021-12-31 23:50:29 +00:00
default_timeline, access_keys)
2021-07-05 20:24:43 +00:00
profileFooterStr += \
' </td>\n' + \
' </tr>\n' + \
' </tbody>\n' + \
'</table>\n'
2021-01-11 19:46:21 +00:00
instanceTitle = \
2021-12-26 14:08:58 +00:00
get_config_param(base_dir, 'instanceTitle')
profileStr = \
2021-12-31 21:18:12 +00:00
html_header_with_external_style(css_filename, instanceTitle, None) + \
2021-12-29 21:55:09 +00:00
profileStr + profileFooterStr + html_footer()
return profileStr