src/pyams_content/shared/common/skin/opengraph.py
changeset 1065 50612c78ed2a
parent 1064 2375abafdeb1
child 1066 161cca66b0f9
--- a/src/pyams_content/shared/common/skin/opengraph.py	Wed Nov 07 17:49:35 2018 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,98 +0,0 @@
-#
-# Copyright (c) 2008-2018 Thierry Florac <tflorac AT ulthar.net>
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-
-__docformat__ = 'restructuredtext'
-
-
-# import standard library
-
-# import interfaces
-from pyams_content.component.illustration import IIllustration, IIllustrationTarget
-from pyams_content.component.theme.interfaces import ITagsInfo
-from pyams_content.shared.common.interfaces import IWfSharedContent
-from pyams_i18n.interfaces import II18n, INegotiator, II18nManager
-from pyams_file.interfaces import IThumbnails
-from pyams_skin.interfaces.configuration import IConfiguration
-from pyams_skin.interfaces.metas import IHTMLContentMetas
-from pyams_skin.layer import IPyAMSUserLayer
-from pyams_workflow.interfaces import IWorkflowPublicationInfo
-from zope.dublincore.interfaces import IZopeDublinCore
-
-# import packages
-from pyams_skin.metas import PropertyMeta
-from pyams_utils.adapter import adapter_config, ContextRequestViewAdapter
-from pyams_utils.registry import get_utility
-from pyams_utils.traversing import get_parent
-from pyams_utils.url import canonical_url, absolute_url
-from zope.interface import Interface
-
-
-@adapter_config(name='opengraph', context=(IWfSharedContent, IPyAMSUserLayer, Interface), provides=IHTMLContentMetas)
-class OpengraphSharedContentMetasAdapter(ContextRequestViewAdapter):
-    """Opengraph shared content metas adapter"""
-
-    order = 15
-
-    def get_metas(self):
-        context = self.context
-        i18n = II18n(context)
-        request = self.request
-        negotiator = get_utility(INegotiator)
-        lang = negotiator.server_language
-        # main properties
-        yield PropertyMeta('og:title', i18n.query_attribute('title', lang=lang, request=request))
-        yield PropertyMeta('og:description', i18n.query_attribute('description', lang=lang, request=request) or '')
-        yield PropertyMeta('og:type', 'article')
-        # workflow informations
-        dc = IZopeDublinCore(context, None)
-        if (dc is not None) and dc.modified:
-            yield PropertyMeta('article:modified_time', dc.modified.isoformat())
-        pub_info = IWorkflowPublicationInfo(context, None)
-        if pub_info is not None:
-            if pub_info.first_publication_date:
-                yield PropertyMeta('article:published_time', pub_info.first_publication_date.isoformat())
-            if pub_info.publication_expiration_date:
-                yield PropertyMeta('article:expiration_time', pub_info.publication_expiration_date.isoformat())
-        # tags
-        tags = ITagsInfo(context, None)
-        if tags is not None:
-            for tag in tags.tags or ():
-                yield PropertyMeta('article:tag', tag.label)
-        # URL and site name
-        yield PropertyMeta('og:url', canonical_url(context, request))
-        configuration = IConfiguration(request.root)
-        yield PropertyMeta('og:site_name', configuration.title)
-        # illustration properties
-        registry = request.registry
-        illustration = None
-        target = context
-        while target is not None:
-            illustration = registry.queryAdapter(target, IIllustration, name='link')
-            if (illustration is None) or (not illustration.has_data()):
-                illustration = registry.queryAdapter(target, IIllustration)
-            if (illustration is not None) and illustration.has_data():
-                break
-            target = get_parent(target, IIllustrationTarget, allow_context=False)
-        if (target is not None) and (illustration is not None):
-            data = II18n(illustration).query_attribute('data', lang=lang, request=request)
-            thumbnail = IThumbnails(data).get_thumbnail('800x600')
-            yield PropertyMeta('og:image:url', absolute_url(thumbnail, self.request))
-            yield PropertyMeta('og:image:type', thumbnail.content_type)
-            image_size = thumbnail.image_size
-            yield PropertyMeta('og:image:width', image_size[0])
-            yield PropertyMeta('og:image:height', image_size[1])
-            yield PropertyMeta('og:image:alt', II18n(illustration).query_attribute('alt_title', lang=lang,
-                                                                                   request=request))
-        # locales properties
-        yield PropertyMeta('og:locale', lang)
-        for lang in II18nManager(context).languages or ():
-            yield PropertyMeta('og:locale:alternate', lang)