Ignore:
Timestamp:
Sep 18, 2009 5:29:41 PM (15 years ago)
Author:
liebster
Message:

Added metatags order feature, which is managed by metatags_order property of of configlet

File:
1 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.seoptimizer/trunk/quintagroup/seoptimizer/__init__.py

    r1312 r1313  
    11from AccessControl import allow_module 
    2 from util import SortedDict 
     2from zope.component import queryMultiAdapter 
     3 
    34from Acquisition import aq_inner 
    45from DateTime import DateTime 
    56 
    67from Products.CMFCore.utils import getToolByName 
     8 
     9from quintagroup.seoptimizer.interfaces import IKeywords, IMappingMetaTags 
     10from quintagroup.seoptimizer.util import SortedDict 
    711 
    812allow_module('quintagroup.seoptimizer.util') 
     
    1822 
    1923 
    20  
    2124if _present: 
    2225    old_lmt = PloneTool.listMetaTags 
     
    2528        """Lists meta tags helper. 
    2629 
    27         Creates a mapping of meta tags -> values for the listMetaTags script. 
     30        Creates a mapping of meta tags. 
    2831        """ 
    29         result = {} 
     32 
     33        from quintagroup.seoptimizer.browser.interfaces import IPloneSEOLayer 
     34        if not IPloneSEOLayer.providedBy(self.REQUEST): 
     35            return old_lmt(getToolByName(self, 'plone_utils'), context) 
     36 
     37        result = SortedDict() 
    3038        site_props = getToolByName(self, 'portal_properties').site_properties 
    3139        use_all = site_props.getProperty('exposeDCMetaTags', None) 
    3240 
     41        seo_context = queryMultiAdapter((context, self.REQUEST), name='seo_context') 
     42        adapter = IMappingMetaTags(context, None) 
     43        mapping_metadata = adapter and adapter.getMappingMetaTags() or SortedDict() 
     44 
    3345        if not use_all: 
    34             metadata_names = {'Description': METADATA_DCNAME['Description']} 
     46            metadata_names = mapping_metadata.has_key('DC.description') and {'DC.description': mapping_metadata['DC.description']} or SortedDict() 
     47            if mapping_metadata.has_key('description'): 
     48                metadata_names['description'] = mapping_metadata['description'] 
    3549        else: 
    36             metadata_names = METADATA_DCNAME 
     50            metadata_names = mapping_metadata 
    3751 
    38         for accessor, key in metadata_names.items(): 
    39             method = getattr(aq_inner(context).aq_explicit, accessor, None) 
     52        for key, accessor in metadata_names.items(): 
     53            if accessor == 'seo_keywords': 
     54                # Set the additional matching keywords, if any 
     55                adapter = IKeywords(context, None) 
     56                if adapter is not None: 
     57                    keywords = adapter.listKeywords() 
     58                    if keywords: 
     59                        result['keywords'] = keywords 
     60                continue 
     61 
     62            method = getattr(seo_context, accessor, None) 
     63            if method is None: 
     64                method = getattr(aq_inner(context).aq_explicit, accessor, None) 
     65 
    4066            if not callable(method): 
    4167                continue 
     
    5783                value = ', '.join(value) 
    5884 
    59 #          Exclusion meta tag description and keywords 
    60 #            # Special cases 
    61 #            if accessor == 'Description': 
    62 #                result['description'] = value 
    63 #            elif accessor == 'Subject': 
    64 #                result['keywords'] = value 
     85            # Special cases 
     86            if accessor == 'Description' and not (result.has_key('description') or metadata_names.has_key('description')): 
     87                result['description'] = value 
     88            elif accessor == 'Subject' and not (result.has_key('keywords') or metadata_names.has_key('keywords')): 
     89                result['keywords'] = value 
    6590 
    66             if use_all: 
     91            if accessor not in ('Description', 'Subject'): 
    6792                result[key] = value 
    6893 
     
    104129                result['DC.date.valid_range'] = '%s - %s' % (eff_str, exp_str) 
    105130 
     131        # add custom meta tags (added from qseo tab by user) for given context and default from configlet 
     132        custom_meta_tags = seo_context and seo_context.seo_customMetaTags() or [] 
     133        for tag in custom_meta_tags: 
     134            if tag['meta_content']: 
     135                result[tag['meta_name']] = tag['meta_content'] 
     136 
    106137        return result 
    107138 
Note: See TracChangeset for help on using the changeset viewer.