diff --git a/daemon.py b/daemon.py index 01f0d3285..bd728dd10 100644 --- a/daemon.py +++ b/daemon.py @@ -274,6 +274,7 @@ from languages import set_actor_languages from languages import get_understood_languages from like import update_likes_collection from reaction import update_reaction_collection +from utils import license_link_from_name from utils import acct_handle_dir from utils import load_reverse_timeline from utils import save_reverse_timeline @@ -6454,11 +6455,14 @@ class PubServer(BaseHTTPRequestHandler): set_config_param(base_dir, 'libretranslateApiKey', '') - # change instance short description + # change instance content license if fields.get('contentLicenseUrl'): if fields['contentLicenseUrl'] != \ self.server.content_license_url: license_str = fields['contentLicenseUrl'] + if '://' not in license_str: + license_str = \ + license_link_from_name(license_str) set_config_param(base_dir, 'contentLicenseUrl', license_str) diff --git a/utils.py b/utils.py index aaf999258..656358261 100644 --- a/utils.py +++ b/utils.py @@ -4172,3 +4172,41 @@ def is_quote_toot(post_json_object: str) -> bool: continue return True return False + + +def license_link_from_name(license: str) -> str: + """Returns the license link from its name + """ + if '://' in license: + return license + value_upper = license.upper() + if 'CC-BY-SA-NC' in value_upper or \ + 'CC-BY-NC-SA' in value_upper or \ + 'CC BY SA NC' in value_upper or \ + 'CC BY NC SA' in value_upper: + value = 'https://creativecommons.org/licenses/by-nc-sa/4.0' + elif 'CC-BY-SA' in value_upper or 'CC-SA-BY' in value_upper or \ + 'CC BY SA' in value_upper or 'CC SA BY' in value_upper: + value = 'https://creativecommons.org/licenses/by-sa/4.0' + elif 'CC-BY-NC' in value_upper or 'CC BY NC' in value_upper: + value = 'https://creativecommons.org/licenses/by-nc/4.0' + elif 'CC-BY-ND' in value_upper or 'CC BY ND' in value_upper: + value = 'https://creativecommons.org/licenses/by-nc-nd/4.0' + elif 'CC-BY' in value_upper or 'CC BY' in value_upper: + value = 'https://creativecommons.org/licenses/by/4.0' + elif 'GFDL' in value_upper or 'GNU FREE DOC' in value_upper: + value = 'https://www.gnu.org/licenses/fdl-1.3.html' + elif 'OPL' in value_upper or 'OPEN PUBLICATION LIC' in value_upper: + value = 'https://opencontent.org/openpub' + elif 'PDL' in value_upper or \ + 'PUBLIC DOCUMENTATION LIC' in value_upper: + value = 'http://www.openoffice.org/licenses/PDL.html' + elif 'FREEBSD' in value_upper: + value = 'https://www.freebsd.org/copyright/freebsd-doc-license' + elif 'WTF' in value_upper: + value = 'http://www.wtfpl.net/txt/copying' + elif 'UNLICENSE' in value_upper: + value = 'https://unlicense.org' + else: + value = 'https://creativecommons.org/publicdomain/zero/1.0' + return value diff --git a/webapp_post.py b/webapp_post.py index 5a8d016cb..75ff621d1 100644 --- a/webapp_post.py +++ b/webapp_post.py @@ -26,6 +26,7 @@ from posts import post_is_muted from posts import get_person_box from posts import download_announce from posts import populate_replies_json +from utils import license_link_from_name from utils import dont_speak_hashtags from utils import remove_eol from utils import disallow_announce @@ -1581,15 +1582,8 @@ def _get_footer_with_icons(show_icons: bool, if not is_news_post(post_json_object): footer_str += ' ' if content_license_url: - # show the CC symbol - copyright_symbol = '🅭 ' - if '/zero/' in content_license_url: - copyright_symbol = '🄍 ' - footer_str += '' + \ - ' ' + \ - copyright_symbol + ' ' + footer_str += _get_copyright_footer(content_license_url, + time_class) # show the date date_link = '/users/' + nickname + '?convthread=' + \ published_link.replace('/', '--') @@ -1725,36 +1719,32 @@ def _get_content_license(post_json_object: {}) -> str: continue value = item['value'] if '://' not in value: - value_upper = value.upper() - if 'CC-BY-SA-NC' in value_upper or \ - 'CC-BY-NC-SA' in value_upper or \ - 'CC BY SA NC' in value_upper or \ - 'CC BY NC SA' in value_upper: - value = 'https://creativecommons.org/licenses/by-nc-sa/4.0' - elif 'CC-BY-SA' in value_upper or 'CC-SA-BY' in value_upper or \ - 'CC BY SA' in value_upper or 'CC SA BY' in value_upper: - value = 'https://creativecommons.org/licenses/by-sa/4.0' - elif 'CC-BY-NC' in value_upper or 'CC BY NC' in value_upper: - value = 'https://creativecommons.org/licenses/by-nc/4.0' - elif 'CC-BY-ND' in value_upper or 'CC BY ND' in value_upper: - value = 'https://creativecommons.org/licenses/by-nc-nd/4.0' - elif 'CC-BY' in value_upper or 'CC BY' in value_upper: - value = 'https://creativecommons.org/licenses/by/4.0' - elif 'GFDL' in value_upper or 'GNU FREE DOC' in value_upper: - value = 'https://www.gnu.org/licenses/fdl-1.3.html' - elif 'OPL' in value_upper or 'OPEN PUBLICATION LIC' in value_upper: - value = 'https://opencontent.org/openpub' - elif 'PDL' in value_upper or \ - 'PUBLIC DOCUMENTATION LIC' in value_upper: - value = 'http://www.openoffice.org/licenses/PDL.html' - elif 'FREEBSD' in value_upper: - value = 'https://www.freebsd.org/copyright/freebsd-doc-license' - else: - value = 'https://creativecommons.org/publicdomain/zero/1.0' + value = license_link_from_name(value) return value return None +def _get_copyright_footer(content_license_url: str, + time_class: str) -> str: + """Returns the footer copyright link + """ + # show the CC symbol + copyright_symbol = '🅭 ' + if '/zero/' in content_license_url: + copyright_symbol = '🄍 ' + elif 'unlicense' in content_license_url: + copyright_symbol = '🅮' + elif 'wtfpl' in content_license_url: + copyright_symbol = '🅮' + elif '/fdl' in content_license_url: + copyright_symbol = '🄎' + return '' + \ + '' + \ + copyright_symbol + ' ' + + def individual_post_as_html(signing_priv_key_pem: str, allow_downloads: bool, recent_posts_cache: {}, max_recent_posts: int, @@ -2286,8 +2276,13 @@ def individual_post_as_html(signing_priv_key_pem: str, domain + ':' + str(port) + '/users/' in published_link: published_link = '/users/' + published_link.split('/users/')[1] + content_license_url = _get_content_license(post_json_object) if not is_news_post(post_json_object): - footer_str = '' + \ published_str + '\n' else: @@ -2367,7 +2362,6 @@ def individual_post_as_html(signing_priv_key_pem: str, if disallow_reply(content_all_str): reply_str = '' - content_license_url = _get_content_license(post_json_object) new_footer_str = \ _get_footer_with_icons(show_icons, container_class_icons,