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/browser/viewlets.py

    r1308 r1313  
    11from cgi import escape 
    22from zope.component import getMultiAdapter 
    3 from zope.viewlet.interfaces import IViewlet 
    43from Products.CMFPlone.utils import safe_unicode 
    54from plone.app.layout.viewlets.common import ViewletBase 
    65from Products.CMFCore.utils import getToolByName 
    7 from AccessControl import Unauthorized 
    8 from quintagroup.seoptimizer.util import SortedDict 
    9 from quintagroup.seoptimizer.interfaces import IKeywords  
     6 
    107 
    118class TitleCommentViewlet(ViewletBase): 
     
    4946                return u"%s\n%s"%(qseo_title, qseo_comments) 
    5047 
    51 #class HTTPEquiv(ViewletBase): 
    52 #     
    53 #    def charset( self ): 
    54 #        context = self.context.aq_inner 
    55 #        site_properties = getToolByName( context, 'portal_properties').site_properties 
    56 #        return site_properties.getProperty('default_charset', 'utf-8') 
    57 #     
    58 #    def render( self ): 
    59 #        return """<meta http-equiv="Content-Type" content="text/html; charset=%s" />"""%self.charset() 
    60 #          
    61 #class BaseUrlViewlet( ViewletBase ): 
    62 #    """ 
    63 #       simpel viewlet for base href rendering 
    64 #    """ 
    65 #    def renderBase( self ): 
    66 #        # returns correct base href 
    67 #        context = self.context.aq_inner 
    68 #        isFolder = getattr(context.aq_explicit, 'isPrincipiaFolderish', 0) 
    69 #        base_url = context.absolute_url() 
    70 # 
    71 #        # when accessing via WEBDAV you're not allowed to access aq_explicit 
    72 #        try: 
    73 #            return isFolder and '%s/'%base_url or base_url 
    74 #        except (Unauthorized, 'Unauthorized'): 
    75 #            pass 
    76 # 
    77 #    def render( self ): 
    78 #        return """<base href="%s" /><!--[if lt IE 7]></base><![endif]-->"""% self.renderBase() 
    79  
    80 class MetaTagsViewlet( ViewletBase ): 
    81  
    82     def listMetaTags( self ): 
    83         context = self.context.aq_inner 
    84         portal_props = getToolByName(context, 'portal_properties') 
    85         pu = getToolByName(context, 'plone_utils') 
    86         seo_props = getToolByName(portal_props, 'seo_properties', None) 
    87         if seo_props is None: 
    88             return pu.listMetaTags(context) 
    89  
    90         site_props = getToolByName(portal_props, 'site_properties') 
    91         exposeDCMetaTags = site_props.exposeDCMetaTags 
    92  
    93         metaTags = SortedDict() 
    94         #metaTags.update(pu.listMetaTags(context)) 
    95         metadataList = [ 
    96             ('seo_description', 'description'), 
    97             ('seo_keywords',    'keywords'), 
    98             ('seo_robots',      'robots'), 
    99             ('seo_distribution','distribution')] 
    100  
    101         if exposeDCMetaTags: 
    102             metadataList.append(('seo_distribution', 'DC.distribution')) 
    103  
    104         seo_context = getMultiAdapter((self.context, self.request), name='seo_context') 
    105         for accessor, key in metadataList: 
    106             method = getattr(seo_context, accessor, None) 
    107             if not callable(method): 
    108                 # ups 
    109                 continue 
    110             # Catch AttributeErrors raised by some AT applications 
    111             try: 
    112                 value = method() 
    113             except AttributeError: 
    114                 value = None 
    115  
    116             if not value: 
    117                 continue 
    118             if isinstance(value, (tuple, list)): 
    119                 value = ', '.join(value) 
    120  
    121             metaTags[key] = value 
    122  
    123         # add custom meta tags (added from qseo tab by user) for given context and default from configlet 
    124         custom_meta_tags = seo_context.seo_customMetaTags() 
    125         for tag in custom_meta_tags: 
    126             if tag['meta_content']: 
    127                 metaTags[tag['meta_name']] = tag['meta_content'] 
    128  
    129         # Set the additional matching keywords, if any 
    130         adapter = IKeywords(context, None) 
    131         if adapter is not None: 
    132             keywords = adapter.listKeywords() 
    133             if keywords: 
    134                 metaTags['keywords'] = keywords 
    135  
    136         return metaTags 
    137  
    138     def render( self ): 
    139         return '\n'.join([safe_unicode("""<meta name="%s" content="%s" />"""%(name, content)) \ 
    140                                        for name, content in self.listMetaTags().items()]) 
    14148 
    14249class CustomScriptViewlet( ViewletBase ): 
     
    14855        if seo_props is None: 
    14956            return ''  
    150         return seo_props.getProperty('custom_script', '') 
     57        return seo_props.getProperty('custom_script', '') 
    15158 
    15259    def render( self ): 
     
    16269        seo_context = getMultiAdapter((self.context, self.request), name='seo_context') 
    16370        return """<link rel="canonical" href="%s" />""" % seo_context.seo_canonical() 
    164  
Note: See TracChangeset for help on using the changeset viewer.