Пример #1
0
    def listMetaTags(self, context):
        site_props = getToolByName(context, 'portal_properties').site_properties
        exposeDCMetaTags = site_props.exposeDCMetaTags

        metaTags = SortedDict()
        metaTags.update(old_lmt(self, context))
        metadataList = [
            ('qSEO_Description', 'description'),
            ('qSEO_Keywords',    'keywords'),
            ('qSEO_Robots',      'robots'),
            ('qSEO_Distribution','distribution')]

        if exposeDCMetaTags:
            metadataList.append(('qSEO_Distribution', 'DC.distribution'))
        for accessor, key in metadataList:
            method = getattr(context, accessor, None)
            if not callable(method):
                # ups
                continue
            # Catch AttributeErrors raised by some AT applications
            try:
                value = method()
            except AttributeError:
                value = None

            if not value:
                # no data
                continue
            if ( type(value) == tuple ) or ( type(value) == list ):
                # convert a list to a string
                value = ', '.join(value)
            metaTags[key] = value

        return metaTags
Пример #2
0
    def listMetaTags(self, context):
        portal_props = getToolByName(context, 'portal_properties')
        seo_props = getToolByName(portal_props, 'seo_properties', None)
        if seo_props is None:
            return old_lmt(self, context)

        site_props = getToolByName(portal_props, 'site_properties')
        exposeDCMetaTags = site_props.exposeDCMetaTags

        metaTags = SortedDict()
        metaTags.update(old_lmt(self, context))
        metadataList = [
            ('qSEO_Description', 'description'),
            ('qSEO_Keywords',    'keywords'),
            ('qSEO_Robots',      'robots'),
            ('qSEO_Distribution','distribution')]

        if exposeDCMetaTags:
            metadataList.append(('qSEO_Distribution', 'DC.distribution'))

        for accessor, key in metadataList:
            method = getattr(context, accessor, None)
            if not callable(method):
                # ups
                continue
            # Catch AttributeErrors raised by some AT applications
            try:
                value = method()
            except AttributeError:
                value = None

            if not value:
                continue
            if isinstance(value, (tuple, list)):
                value = ', '.join(value)

            metaTags[key] = value

        # add custom meta tags (added from qseo tab by user) for given context
        property_prefix = 'qSEO_custom_'
        for property, value in context.propertyItems():
            idx = property.find(property_prefix)
            if idx == 0 and len(property) > len(property_prefix):
                metaTags[property[len(property_prefix):]] = value

        # Set the additional matching keywords, if any
        if zope_interface_available:
            adapter = IKeywords(context, None)
            if adapter is not None:
                keywords = adapter.listKeywords()
                if keywords:
                    metaTags['keywords'] = keywords

        return metaTags