Add art site url as a profile field

main
Bob Mottram 2024-08-15 20:58:26 +01:00
parent 83dd0b09c6
commit 3dddec273f
34 changed files with 241 additions and 36 deletions

116
art.py 100644
View File

@ -0,0 +1,116 @@
__filename__ = "art.py"
__author__ = "Bob Mottram"
__license__ = "AGPL3+"
__version__ = "1.5.0"
__maintainer__ = "Bob Mottram"
__email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Profile Metadata"
from utils import get_attachment_property_value
from utils import remove_html
from utils import string_contains
from utils import resembles_url
art_fieldnames = ('art')
art_sites = (
'etsy.com', 'shopify.com', 'folksy.com', 'aftcra.com',
'justartisan.com', 'goimagine.com', 'artfire.com',
'indiecart.com', 'madeit.com.au', 'icraftgifts.com',
'felt.co.nz', 'shootproof.com', 'pixieset.com',
'instaproofs.com', 'smugmug.com', 'singulart.com',
'pic-time.com', 'zenfolio.com', 'photoshelter.com',
'squarespace.com', 'alamy.com', 'shutterstock.com',
'dreamstime.com', 'canstockphoto.com',
'stock.adobe.com', 'gettyimages.', 'istockphoto.com',
'stocksy.com', '500px.com', 'fineartamerica.com'
)
def get_art_site_url(actor_json: {}) -> str:
"""Returns art site url for the given actor
"""
if not actor_json.get('attachment'):
return ''
if not isinstance(actor_json['attachment'], list):
return ''
for property_value in actor_json['attachment']:
if not property_value.get('type'):
continue
if not isinstance(property_value['type'], str):
continue
if not property_value['type'].endswith('PropertyValue'):
continue
prop_value_name, _ = \
get_attachment_property_value(property_value)
if not prop_value_name:
continue
art_text = remove_html(property_value[prop_value_name])
if not string_contains(art_text, art_sites):
continue
if not resembles_url(art_text):
continue
return art_text
return ''
def set_art_site_url(actor_json: {}, art_site_url: str) -> None:
"""Sets art site url for the given actor
"""
art_site_url = remove_html(art_site_url)
if not resembles_url(art_site_url):
return
if not actor_json.get('attachment'):
actor_json['attachment'] = []
# remove any existing value
property_found = None
for property_value in actor_json['attachment']:
name_value = None
if property_value.get('name'):
name_value = property_value['name'].lower()
elif property_value.get('schema:name'):
name_value = property_value['schema:name'].lower()
if not name_value:
continue
if not property_value.get('type'):
continue
if not string_contains(name_value, art_fieldnames):
continue
property_found = property_value
break
if property_found:
actor_json['attachment'].remove(property_found)
for property_value in actor_json['attachment']:
name_value = None
if property_value.get('name'):
name_value = property_value['name']
elif property_value.get('schema:name'):
name_value = property_value['schema:name']
if not name_value:
continue
if not property_value.get('type'):
continue
name_value = name_value.lower()
if not string_contains(name_value, art_fieldnames):
continue
if not property_value['type'].endswith('PropertyValue'):
continue
prop_value_name, _ = \
get_attachment_property_value(property_value)
if not prop_value_name:
continue
property_value[prop_value_name] = remove_html(art_site_url)
return
new_art = {
"type": "PropertyValue",
"name": "Art",
"value": remove_html(art_site_url)
}
actor_json['attachment'].append(new_art)

View File

@ -85,6 +85,8 @@ from discord import get_discord
from discord import set_discord
from music import get_music_site_url
from music import set_music_site_url
from art import get_art_site_url
from art import set_art_site_url
from youtube import get_youtube
from youtube import set_youtube
from pixelfed import get_pixelfed
@ -2026,6 +2028,23 @@ def _profile_post_music_site_url(actor_json: {}, fields: {},
return actor_changed
def _profile_post_art_site_url(actor_json: {}, fields: {},
actor_changed: bool) -> bool:
""" HTTP POST change art site url address
"""
current_art = get_art_site_url(actor_json)
if fields.get('artSiteUrl'):
if fields['artSiteUrl'] != current_art:
set_art_site_url(actor_json,
fields['artSiteUrl'])
actor_changed = True
else:
if current_art:
set_art_site_url(actor_json, '')
actor_changed = True
return actor_changed
def _profile_post_discord(actor_json: {}, fields: {},
actor_changed: bool) -> bool:
""" HTTP POST change discord channel address
@ -2960,6 +2979,10 @@ def profile_edit(self, calling_domain: str, cookie: str,
_profile_post_music_site_url(actor_json, fields,
actor_changed)
actor_changed = \
_profile_post_art_site_url(actor_json, fields,
actor_changed)
actor_changed = \
_profile_post_peertube(actor_json, fields,
actor_changed)

View File

@ -46,6 +46,7 @@ from donate import get_website
from donate import get_gemini_link
from pronouns import get_pronouns
from discord import get_discord
from art import get_art_site_url
from music import get_music_site_url
from youtube import get_youtube
from pixelfed import get_pixelfed
@ -663,6 +664,7 @@ def show_person_options(self, calling_domain: str, path: str,
pronouns = None
pixelfed = None
discord = None
art_site_url = None
music_site_url = None
youtube = None
peertube = None
@ -697,6 +699,7 @@ def show_person_options(self, calling_domain: str, path: str,
pronouns = get_pronouns(actor_json)
pixelfed = get_pixelfed(actor_json)
discord = get_discord(actor_json)
art_site_url = get_art_site_url(actor_json)
music_site_url = get_music_site_url(actor_json)
youtube = get_youtube(actor_json)
peertube = get_peertube(actor_json)
@ -774,7 +777,8 @@ def show_person_options(self, calling_domain: str, path: str,
repo_url,
self.server.sites_unavailable,
youtube, peertube, pixelfed,
discord, music_site_url)
discord, music_site_url,
art_site_url)
if msg:
msg = msg.encode('utf-8')
msglen = len(msg)

10
pgp.py
View File

@ -29,6 +29,7 @@ from session import post_json
from pronouns import get_pronouns
from pixelfed import get_pixelfed
from discord import get_discord
from art import get_art_site_url
from music import get_music_site_url
from youtube import get_youtube
from peertube import get_peertube
@ -762,6 +763,10 @@ def actor_to_vcard(actor: {}, domain: str, translate: {}) -> str:
pixelfed = get_pixelfed(actor)
if pixelfed:
vcard_str += 'SOCIALPROFILE;SERVICE-TYPE=Pixelfed:' + pixelfed + '\n'
art_site_url = get_art_site_url(actor)
if art_site_url:
vcard_str += \
'SOCIALPROFILE;SERVICE-TYPE=Art:' + art_site_url + '\n'
music_site_url = get_music_site_url(actor)
if music_site_url:
vcard_str += \
@ -871,6 +876,11 @@ def actor_to_vcard_xml(actor: {}, domain: str, translate: {}) -> str:
vcard_str += ' <url>' + \
'<parameters><type><text>youtube</text></type></parameters>' + \
'<uri>' + youtube + '</uri></url>\n'
art_site_url = get_art_site_url(actor)
if art_site_url:
vcard_str += ' <url>' + \
'<parameters><type><text>art</text></type></parameters>' + \
'<uri>' + art_site_url + '</uri></url>\n'
music_site_url = get_music_site_url(actor)
if music_site_url:
vcard_str += ' <url>' + \

View File

@ -698,5 +698,6 @@
"Watermark image": "صورة العلامة المائية",
"Apply a watermark to uploaded images": "إضافة علامة مائية على الصور التي تم تحميلها",
"Pronouns": "الضمائر",
"Music": "موسيقى"
"Music": "موسيقى",
"Art": "فن"
}

View File

@ -698,5 +698,6 @@
"Watermark image": "ওয়াটারমার্ক ইমেজ",
"Apply a watermark to uploaded images": "আপলোড করা ছবিগুলিতে একটি জলছাপ প্রয়োগ করুন",
"Pronouns": "সর্বনাম",
"Music": "সঙ্গীত"
"Music": "সঙ্গীত",
"Art": "শিল্প"
}

View File

@ -698,5 +698,6 @@
"Watermark image": "Imatge de filigrana",
"Apply a watermark to uploaded images": "Apliqueu una marca d'aigua a les imatges penjades",
"Pronouns": "Els pronoms",
"Music": "Música"
"Music": "Música",
"Art": "Art"
}

View File

@ -698,5 +698,6 @@
"Watermark image": "Delwedd dyfrnod",
"Apply a watermark to uploaded images": "Cymhwyso dyfrnod i ddelweddau sydd wedi'u llwytho i fyny",
"Pronouns": "Rhagenwau",
"Music": "Cerddoriaeth"
"Music": "Cerddoriaeth",
"Art": "Celf"
}

View File

@ -698,5 +698,6 @@
"Watermark image": "Wasserzeichenbild",
"Apply a watermark to uploaded images": "Hochgeladenen Bildern ein Wasserzeichen hinzufügen",
"Pronouns": "Pronomen",
"Music": "Musik"
"Music": "Musik",
"Art": "Kunst"
}

View File

@ -698,5 +698,6 @@
"Watermark image": "Εικόνα υδατογραφήματος",
"Apply a watermark to uploaded images": "Εφαρμόστε ένα υδατογράφημα στις μεταφορτωμένες εικόνες",
"Pronouns": "Αντωνυμίες",
"Music": "Μουσική"
"Music": "Μουσική",
"Art": "Τέχνη"
}

View File

@ -698,5 +698,6 @@
"Watermark image": "Watermark image",
"Apply a watermark to uploaded images": "Apply a watermark to uploaded images",
"Pronouns": "Pronouns",
"Music": "Music"
"Music": "Music",
"Art": "Art"
}

View File

@ -698,5 +698,6 @@
"Watermark image": "Imagen de marca de agua",
"Apply a watermark to uploaded images": "Aplicar una marca de agua a las imágenes cargadas",
"Pronouns": "Pronombres",
"Music": "Música"
"Music": "Música",
"Art": "Arte"
}

View File

@ -698,5 +698,6 @@
"Watermark image": "تصویر واترمارک",
"Apply a watermark to uploaded images": "اعمال واترمارک روی تصاویر آپلود شده",
"Pronouns": "ضمایر",
"Music": "موسیقی"
"Music": "موسیقی",
"Art": "هنر"
}

View File

@ -698,5 +698,6 @@
"Watermark image": "Vesileiman kuva",
"Apply a watermark to uploaded images": "Lisää ladattuihin kuviin vesileima",
"Pronouns": "Pronominit",
"Music": "Musiikki"
"Music": "Musiikki",
"Art": "Taide"
}

View File

@ -698,5 +698,6 @@
"Watermark image": "Image en filigrane",
"Apply a watermark to uploaded images": "Appliquer un filigrane aux images téléchargées",
"Pronouns": "Pronoms",
"Music": "Musique"
"Music": "Musique",
"Art": "Art"
}

View File

@ -698,5 +698,6 @@
"Watermark image": "Íomhá comhartha uisce",
"Apply a watermark to uploaded images": "Cuir comhartha uisce i bhfeidhm ar íomhánna uaslódáilte",
"Pronouns": "Forainmneacha",
"Music": "Ceol"
"Music": "Ceol",
"Art": "Ealaín"
}

View File

@ -698,5 +698,6 @@
"Watermark image": "תמונת סימן מים",
"Apply a watermark to uploaded images": "החל סימן מים על תמונות שהועלו",
"Pronouns": "כינויים",
"Music": "מוּסִיקָה"
"Music": "מוּסִיקָה",
"Art": "אָמָנוּת"
}

View File

@ -698,5 +698,6 @@
"Watermark image": "वॉटरमार्क छवि",
"Apply a watermark to uploaded images": "अपलोड की गई छवियों पर वॉटरमार्क लागू करें",
"Pronouns": "सर्वनाम",
"Music": "संगीत"
"Music": "संगीत",
"Art": "कला"
}

View File

@ -698,5 +698,6 @@
"Watermark image": "Immagine filigrana",
"Apply a watermark to uploaded images": "Applicare una filigrana alle immagini caricate",
"Pronouns": "Pronomi",
"Music": "Musica"
"Music": "Musica",
"Art": "Arte"
}

View File

@ -698,5 +698,6 @@
"Watermark image": "透かし画像",
"Apply a watermark to uploaded images": "アップロードした画像に透かしを適用する",
"Pronouns": "代名詞",
"Music": "音楽"
"Music": "音楽",
"Art": "美術"
}

View File

@ -698,5 +698,6 @@
"Watermark image": "워터마크 이미지",
"Apply a watermark to uploaded images": "업로드한 이미지에 워터마크를 적용합니다",
"Pronouns": "대명사",
"Music": "음악"
"Music": "음악",
"Art": "미술"
}

View File

@ -698,5 +698,6 @@
"Watermark image": "Wêneyê Watermark",
"Apply a watermark to uploaded images": "Li ser wêneyên barkirî ava nîşanek bicîh bikin",
"Pronouns": "Cînavk",
"Music": "Mûzîk"
"Music": "Mûzîk",
"Art": "Fen"
}

View File

@ -698,5 +698,6 @@
"Watermark image": "Watermerk afbeelding",
"Apply a watermark to uploaded images": "Een watermerk toepassen op geüploade afbeeldingen",
"Pronouns": "Voornaamwoorden",
"Music": "Muziek"
"Music": "Muziek",
"Art": "Kunst"
}

View File

@ -694,5 +694,6 @@
"Watermark image": "Watermark image",
"Apply a watermark to uploaded images": "Apply a watermark to uploaded images",
"Pronouns": "Pronouns",
"Music": "Music"
"Music": "Music",
"Art": "Art"
}

View File

@ -698,5 +698,6 @@
"Watermark image": "Obraz znaku wodnego",
"Apply a watermark to uploaded images": "Zastosuj znak wodny do przesłanych obrazów",
"Pronouns": "Zaimki",
"Music": "Muzyka"
"Music": "Muzyka",
"Art": "Sztuka"
}

View File

@ -698,5 +698,6 @@
"Watermark image": "Imagem de marca de água",
"Apply a watermark to uploaded images": "Aplicar uma marca de água nas imagens enviadas",
"Pronouns": "Pronomes",
"Music": "Música"
"Music": "Música",
"Art": "Arte"
}

View File

@ -698,5 +698,6 @@
"Watermark image": "Изображение водяного знака",
"Apply a watermark to uploaded images": "Накладывать водяной знак на загружаемые изображения",
"Pronouns": "Местоимения",
"Music": "Музыка"
"Music": "Музыка",
"Art": "Искусство"
}

View File

@ -698,5 +698,6 @@
"Watermark image": "Picha ya watermark",
"Apply a watermark to uploaded images": "Tumia watermark kwa picha zilizopakiwa",
"Pronouns": "Viwakilishi",
"Music": "Muziki"
"Music": "Muziki",
"Art": "Sanaa"
}

View File

@ -698,5 +698,6 @@
"Watermark image": "Filigran resmi",
"Apply a watermark to uploaded images": "Yüklenen görsellere filigran uygulayın",
"Pronouns": "Zamirler",
"Music": "Müzik"
"Music": "Müzik",
"Art": "Sanat"
}

View File

@ -698,5 +698,6 @@
"Watermark image": "Зображення водяного знака",
"Apply a watermark to uploaded images": "Застосування водяного знака до завантажених зображень",
"Pronouns": "Займенники",
"Music": "музика"
"Music": "музика",
"Art": "ст"
}

View File

@ -698,5 +698,6 @@
"Watermark image": "וואָטערמאַרק בילד",
"Apply a watermark to uploaded images": "צולייגן אַ וואָטערמאַרק צו ופּלאָאַדעד בילדער",
"Pronouns": "פּראָנאָונס",
"Music": "מוזיק"
"Music": "מוזיק",
"Art": "קונסט"
}

View File

@ -698,5 +698,6 @@
"Watermark image": "水印图像",
"Apply a watermark to uploaded images": "将水印应用于上传的图像",
"Pronouns": "代词",
"Music": "音乐"
"Music": "音乐",
"Art": "艺术"
}

View File

@ -174,7 +174,8 @@ def html_person_options(default_timeline: str,
youtube: str, peertube: str,
pixelfed: str,
discord: str,
music_site_url: str) -> str:
music_site_url: str,
art_site_url: str) -> str:
"""Show options for a person: view/follow/block/report
"""
options_link_str = ''
@ -449,6 +450,11 @@ def html_person_options(default_timeline: str,
' <p class="imText">Discord' + \
': <a href="' + remove_html(discord) + '">' + \
discord + '</a></p>\n'
if art_site_url:
options_str += \
' <p class="imText">' + translate['Art'] + \
': <a href="' + remove_html(art_site_url) + '">' + \
art_site_url + '</a></p>\n'
if music_site_url:
options_str += \
' <p class="imText">' + translate['Music'] + \

View File

@ -69,6 +69,7 @@ from donate import get_gemini_link
from pronouns import get_pronouns
from pixelfed import get_pixelfed
from discord import get_discord
from art import get_art_site_url
from music import get_music_site_url
from youtube import get_youtube
from peertube import get_peertube
@ -332,6 +333,7 @@ def html_profile_after_search(authorized: bool,
pronouns = get_pronouns(profile_json)
discord = get_discord(profile_json)
art_site_url = get_art_site_url(profile_json)
music_site_url = get_music_site_url(profile_json)
youtube = get_youtube(profile_json)
peertube = get_peertube(profile_json)
@ -461,7 +463,8 @@ def html_profile_after_search(authorized: bool,
person_url, no_of_books,
birth_date,
youtube, peertube, pixelfed,
discord, music_site_url)
discord, music_site_url,
art_site_url)
domain_full = get_full_domain(domain, port)
@ -834,7 +837,8 @@ def _get_profile_header_after_search(base_dir: str,
peertube: str,
pixelfed: str,
discord: str,
music_site_url: str) -> str:
music_site_url: str,
art_site_url: str) -> str:
"""The header of a searched for handle, containing background
image and avatar
"""
@ -959,6 +963,9 @@ def _get_profile_header_after_search(base_dir: str,
if discord:
html_str += ' <p>Discord: <a href="' + discord + '">' + \
discord + '</a></p>\n'
if art_site_url:
html_str += ' <p>' + translate['Art'] + ': <a href="' + \
art_site_url + '">' + art_site_url + '</a></p>\n'
if music_site_url:
html_str += ' <p>' + translate['Music'] + ': <a href="' + \
music_site_url + '">' + music_site_url + '</a></p>\n'
@ -1130,6 +1137,7 @@ def html_profile(signing_priv_key_pem: str,
pronouns = get_pronouns(profile_json)
pixelfed = get_pixelfed(profile_json)
discord = get_discord(profile_json)
art_site_url = get_art_site_url(profile_json)
music_site_url = get_music_site_url(profile_json)
youtube = get_youtube(profile_json)
peertube = get_peertube(profile_json)
@ -1142,7 +1150,7 @@ def html_profile(signing_priv_key_pem: str,
verified_site_checkmark = ''
premium = is_premium_account(base_dir, nickname, domain)
if donate_url or website_url or repo_url or pronouns or discord or \
music_site_url or youtube or peertube or pixelfed or \
art_site_url or music_site_url or youtube or peertube or pixelfed or \
xmpp_address or matrix_address or \
ssb_address or tox_address or briar_address or cwtch_address or \
pgp_pub_key or enigma_pub_key or pgp_fingerprint or email_address:
@ -1217,6 +1225,11 @@ def html_profile(signing_priv_key_pem: str,
donate_section += \
'<p>Discord: <a href="' + \
discord + '" tabindex="1">' + discord + '</a></p>\n'
if art_site_url:
donate_section += \
'<p>' + translate['Art'] + ': <a href="' + \
art_site_url + '" tabindex="1">' + \
art_site_url + '</a></p>\n'
if music_site_url:
donate_section += \
'<p>' + translate['Music'] + ': <a href="' + \
@ -2779,7 +2792,8 @@ def _html_edit_profile_contact_info(email_address: str,
peertube: str,
pixelfed: str,
discord: str,
music_site_url: str) -> str:
music_site_url: str,
art_site_url: str) -> str:
"""Contact Information section of edit profile screen
"""
edit_profile_form = begin_edit_section(translate['Contact Details'])
@ -2803,6 +2817,8 @@ def _html_edit_profile_contact_info(email_address: str,
pixelfed)
edit_profile_form += edit_text_field('Discord', 'discordChannel',
discord)
edit_profile_form += edit_text_field(translate['Art'],
'artSiteUrl', art_site_url)
edit_profile_form += edit_text_field(translate['Music'],
'musicSiteUrl', music_site_url)
edit_profile_form += end_edit_section()
@ -3255,7 +3271,7 @@ def html_edit_profile(server, translate: {},
pgp_fingerprint = pronouns = peertube = youtube = pixelfed = ''
ssb_address = blog_address = matrix_address = tox_address = ''
cwtch_address = briar_address = xmpp_address = ''
discord = music_site_url = ''
discord = music_site_url = art_site_url = ''
manually_approves_followers = reject_spam_actors = ''
actor_json = load_json(actor_filename)
@ -3269,6 +3285,7 @@ def html_edit_profile(server, translate: {},
pronouns = get_pronouns(actor_json)
pixelfed = get_pixelfed(actor_json)
discord = get_discord(actor_json)
art_site_url = get_art_site_url(actor_json)
music_site_url = get_music_site_url(actor_json)
youtube = get_youtube(actor_json)
peertube = get_peertube(actor_json)
@ -3492,7 +3509,8 @@ def html_edit_profile(server, translate: {},
briar_address,
cwtch_address, translate,
youtube, peertube, pixelfed,
discord, music_site_url)
discord, music_site_url,
art_site_url)
# notification settings
edit_profile_form += \