diff -r d05fc6aa4217 -r fc32ec8a8f53 src/pyams_content/component/paragraph/html.py --- a/src/pyams_content/component/paragraph/html.py Fri Jul 03 14:42:15 2020 +0200 +++ b/src/pyams_content/component/paragraph/html.py Fri Jul 03 18:43:46 2020 +0200 @@ -10,24 +10,17 @@ # FOR A PARTICULAR PURPOSE. # -import re - -from pyquery import PyQuery from pyramid.events import subscriber -from pyramid.threadlocal import get_current_registry from zope.interface import implementer -from zope.lifecycleevent import ObjectCreatedEvent from zope.lifecycleevent.interfaces import IObjectAddedEvent, IObjectModifiedEvent from zope.schema.fieldproperty import FieldProperty -from pyams_content.component.association.interfaces import IAssociationContainer -from pyams_content.component.extfile.interfaces import IBaseExtFile, IExtFileContainerTarget +from pyams_content.component.extfile.interfaces import IExtFileContainerTarget from pyams_content.component.illustration.interfaces import IIllustrationTarget -from pyams_content.component.links import ExternalLink, InternalLink, MailtoLink -from pyams_content.component.links.interfaces import IExternalLink, IInternalLink, \ - ILinkContainerTarget, IMailtoLink +from pyams_content.component.links.interfaces import ILinkContainerTarget from pyams_content.component.paragraph import BaseParagraph, BaseParagraphContentChecker, \ BaseParagraphFactory +from pyams_content.component.paragraph.association import check_associations from pyams_content.component.paragraph.interfaces import IParagraphFactory from pyams_content.component.paragraph.interfaces.html import HTML_PARAGRAPH_NAME, \ HTML_PARAGRAPH_RENDERERS, HTML_PARAGRAPH_TYPE, IHTMLParagraph, IRawParagraph, \ @@ -36,13 +29,10 @@ MISSING_VALUE from pyams_content.features.renderer import RenderersVocabulary from pyams_i18n.interfaces import II18n, II18nManager, INegotiator -from pyams_sequence.interfaces import ISequentialIntIds from pyams_utils.adapter import adapter_config from pyams_utils.factory import factory_config from pyams_utils.registry import get_utility, utility_config -from pyams_utils.request import check_request from pyams_utils.traversing import get_parent -from pyams_utils.url import absolute_url from pyams_utils.vocabulary import vocabulary_config @@ -129,75 +119,6 @@ content_type = HTMLParagraph -FULL_EMAIL = re.compile('(.*) \<(.*)\>') - - -def check_associations(context, body, lang, notify=True): - """Check for link associations from HTML content""" - registry = get_current_registry() - associations = IAssociationContainer(context) - html = PyQuery('{0}'.format(body)) - for link in html('a[href]'): - link_info = None - has_link = False - href = link.attrib['href'] - if href.startswith('oid://'): - sequence = get_utility(ISequentialIntIds) - oid = sequence.get_full_oid(href.split('//', 1)[1]) - for association in associations.values(): - internal_info = IInternalLink(association, None) - if (internal_info is not None) and (internal_info.reference == oid): - has_link = True - break - if not has_link: - link_info = InternalLink() - link_info.visible = False - link_info.reference = oid - link_info.title = {lang: link.attrib.get('title') or link.text} - elif href.startswith('mailto:'): - name = None - email = href[7:] - if '<' in email: - groups = FULL_EMAIL.findall(email) - if groups: - name, email = groups[0] - for association in associations.values(): - mailto_info = IMailtoLink(association, None) - if (mailto_info is not None) and (mailto_info.address == email): - has_link = True - break - if not has_link: - link_info = MailtoLink() - link_info.visible = False - link_info.address = email - link_info.address_name = name or email - link_info.title = {lang: link.attrib.get('title') or link.text} - elif href.startswith('http://') or href.startswith('https://'): - for association in associations.values(): - external_info = IExternalLink(association, None) - if (external_info is not None) and (external_info.url == href): - has_link = True - break - else: - extfile_info = IBaseExtFile(association, None) - if extfile_info is not None: - request = check_request() - extfile_url = absolute_url( - II18n(extfile_info).query_attribute('data', request=request), - request=request) - if extfile_url.endswith(href): - has_link = True - break - if not has_link: - link_info = ExternalLink() - link_info.visible = False - link_info.url = href - link_info.title = {lang: link.attrib.get('title') or link.text} - if link_info is not None: - registry.notify(ObjectCreatedEvent(link_info)) - associations.append(link_info, notify=notify) - - @subscriber(IObjectAddedEvent, context_selector=IHTMLParagraph) def handle_added_html_paragraph(event): """Check for new associations from added paragraph"""