1 | ## Controller Python Script "qseo_properties_edit" |
---|
2 | ##bind container=container |
---|
3 | ##bind context=context |
---|
4 | ##bind namespace= |
---|
5 | ##bind script=script |
---|
6 | ##bind state=state |
---|
7 | ##bind subpath=traverse_subpath |
---|
8 | ##title=validates SEO Properties |
---|
9 | ##parameters=title=None,description=None,canonical=None,keywords=None,html_comment=None,robots=None,distribution=None,title_override=0,description_override=0,canonical_override=0,keywords_override=0,html_comment_override=0,robots_override=0,distribution_override=0,custommetatags=[] |
---|
10 | |
---|
11 | from Products.CMFCore.utils import getToolByName |
---|
12 | from quintagroup.seoptimizer import SeoptimizerMessageFactory as _ |
---|
13 | |
---|
14 | def getMainDomain(url): |
---|
15 | url = url.split('//')[-1] |
---|
16 | dompath = url.split(':')[0] |
---|
17 | dom = dompath.split('/')[0] |
---|
18 | return '.'.join(dom.split('.')[-2:]) |
---|
19 | |
---|
20 | purl = getToolByName(context, 'portal_url')() |
---|
21 | if canonical: |
---|
22 | pdomain = getMainDomain(purl) |
---|
23 | if not pdomain == getMainDomain(canonical): |
---|
24 | state.setError('canonical', _(u'Canonical URL mast be in "%s" domain' % pdomain), "canonical") |
---|
25 | |
---|
26 | if state.getErrors(): |
---|
27 | context.plone_utils.addPortalMessage(_(u'Please correct the indicated errors.')) |
---|
28 | return state.set(status='failure') |
---|
29 | else: |
---|
30 | return state |
---|