source: products/quintagroup.seoptimizer/trunk/quintagroup/seoptimizer/browser/viewlets.py @ 1460

Last change on this file since 1460 was 1313, checked in by liebster, 15 years ago

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

  • Property svn:eol-style set to native
File size: 2.7 KB
RevLine 
[1052]1from cgi import escape
[387]2from zope.component import getMultiAdapter
3from Products.CMFPlone.utils import safe_unicode
4from plone.app.layout.viewlets.common import ViewletBase
5from Products.CMFCore.utils import getToolByName
6
[1313]7
[387]8class TitleCommentViewlet(ViewletBase):
9
10    def update(self):
11        self.portal_state = getMultiAdapter((self.context, self.request),
12                                            name=u'plone_portal_state')
13        self.context_state = getMultiAdapter((self.context, self.request),
14                                             name=u'plone_context_state')
15        self.page_title = self.context_state.object_title
16        self.portal_title = self.portal_state.portal_title
17
18        self.override_title = self.context.hasProperty('qSEO_title')
19        self.override_comments = self.context.hasProperty('qSEO_html_comment')
20
[1052]21    def std_title(self):
22        portal_title = safe_unicode(self.portal_title())
23        page_title = safe_unicode(self.page_title())
24        if page_title == portal_title:
25            return u"<title>%s</title>" % (escape(portal_title))
26        else:
27            return u"<title>%s &mdash; %s</title>" % (
28                escape(safe_unicode(page_title)),
29                escape(safe_unicode(portal_title)))
30
[387]31    def render(self):
[1052]32        std_title = self.std_title()
[413]33        seo_context = getMultiAdapter((self.context, self.request), name='seo_context')
[387]34        if not self.override_title:
35            if not self.override_comments:
36                return std_title
37            else:
[413]38                qseo_comments = u"<!--%s-->"%safe_unicode(seo_context.seo_html_comment())
[387]39                return u"%s\n%s"%(std_title, qseo_comments)
40        else:
[413]41            qseo_title = u"<title>%s</title>" % safe_unicode(seo_context.seo_title())
[387]42            if not self.override_comments:
43                return qseo_title
44            else:
[413]45                qseo_comments = u"<!--%s-->"%safe_unicode(seo_context.seo_html_comment())
[387]46                return u"%s\n%s"%(qseo_title, qseo_comments)
47
48
[869]49class CustomScriptViewlet( ViewletBase ):
50
51    def getCustomScript( self ):
52        context = self.context.aq_inner
53        portal_props = getToolByName(context, 'portal_properties')
54        seo_props = getToolByName(portal_props, 'seo_properties', None)
55        if seo_props is None:
56            return '' 
[1313]57        return seo_props.getProperty('custom_script', '')
[869]58
59    def render( self ):
60        return safe_unicode("""%s"""% self.getCustomScript())
61
[896]62
63class CanonicalUrlViewlet( ViewletBase ):
64    """
65       simple viewlet for canonical url link rendering
66    """
67
68    def render( self ):
69        seo_context = getMultiAdapter((self.context, self.request), name='seo_context')
70        return """<link rel="canonical" href="%s" />""" % seo_context.seo_canonical()
Note: See TracBrowser for help on using the repository browser.