From 77d6f0c48cd7659d6322d7b7c4b941f8cd9dbe30 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 27 Dec 2022 17:19:32 +0000 Subject: [PATCH 1/4] Remove spaces --- webapp_post.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webapp_post.py b/webapp_post.py index 5a8d016cb..0aa0602bb 100644 --- a/webapp_post.py +++ b/webapp_post.py @@ -1588,8 +1588,8 @@ def _get_footer_with_icons(show_icons: bool, footer_str += '' + \ - ' ' + \ - copyright_symbol + ' ' + '' + \ + copyright_symbol + ' ' # show the date date_link = '/users/' + nickname + '?convthread=' + \ published_link.replace('/', '--') From 800712134a533f647b7ab2bbcfb21e8c1d143b3e Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 27 Dec 2022 21:15:42 +0000 Subject: [PATCH 2/4] More licenses --- webapp_post.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/webapp_post.py b/webapp_post.py index 0aa0602bb..13c1fcc9e 100644 --- a/webapp_post.py +++ b/webapp_post.py @@ -1749,6 +1749,10 @@ def _get_content_license(post_json_object: {}) -> str: 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 @@ -2286,8 +2290,20 @@ 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 = '' + \ + '' + \ + copyright_symbol + ' ' + footer_str += '' + \ published_str + '\n' else: @@ -2367,7 +2383,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, From 1ea83254c51e5302e41ef11aabc02089e53a0579 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 27 Dec 2022 21:30:20 +0000 Subject: [PATCH 3/4] Set license link from name --- daemon.py | 6 +++++- utils.py | 38 ++++++++++++++++++++++++++++++++++++++ webapp_post.py | 32 ++------------------------------ 3 files changed, 45 insertions(+), 31 deletions(-) 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 13c1fcc9e..0a65b9a94 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 @@ -1725,36 +1726,7 @@ 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' - 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' + value = license_link_from_name(value) return value return None From 3b145a7ac4a599984d87de667ae3f405d2f2338f Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 27 Dec 2022 21:52:54 +0000 Subject: [PATCH 4/4] Copyright symbols --- webapp_post.py | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/webapp_post.py b/webapp_post.py index 0a65b9a94..75ff621d1 100644 --- a/webapp_post.py +++ b/webapp_post.py @@ -1582,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('/', '--') @@ -1731,6 +1724,27 @@ def _get_content_license(post_json_object: {}) -> str: 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, @@ -2266,15 +2280,8 @@ def individual_post_as_html(signing_priv_key_pem: str, 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) footer_str += '' + \ published_str + '\n'