|
Revision 1019
(checked in by piv, 1 year ago)
|
version 1.4.0
|
- Property svn:eol-style set to
native
|
| Line | |
|---|
| 1 |
import re, commands |
|---|
| 2 |
from zope.interface import implements |
|---|
| 3 |
from Products.CMFCore.utils import getToolByName |
|---|
| 4 |
from Products.qSEOptimizer.interfaces import IKeywords |
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
class AdditionalKeywords(object): |
|---|
| 8 |
implements(IKeywords) |
|---|
| 9 |
|
|---|
| 10 |
def __init__(self, context): |
|---|
| 11 |
self.context = context |
|---|
| 12 |
|
|---|
| 13 |
def listKeywords(self): |
|---|
| 14 |
portal_props = getToolByName(self.context, 'portal_properties') |
|---|
| 15 |
seo_props = getToolByName(portal_props, 'seo_properties') |
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
keywords = list(self.context.qSEO_Keywords()) |
|---|
| 24 |
lower_keywords = map(lambda x: x.lower(), keywords) |
|---|
| 25 |
additional = seo_props.additional_keywords |
|---|
| 26 |
|
|---|
| 27 |
is_test = self.context.REQUEST.get('qseo_without_additional_keywords', None) |
|---|
| 28 |
|
|---|
| 29 |
if additional and is_test is None: |
|---|
| 30 |
|
|---|
| 31 |
text = commands.getoutput('lynx --dump --nolist %s?qseo_without_additional_keywords=1' % self.context.absolute_url()).lower() |
|---|
| 32 |
if text and text != 'sh: lynx: command not found': |
|---|
| 33 |
for keyword in additional: |
|---|
| 34 |
if keyword.lower() not in lower_keywords and re.compile(r'\b%s\b' % keyword, re.I).search(text): |
|---|
| 35 |
keywords.append(keyword) |
|---|
| 36 |
|
|---|
| 37 |
return ', '.join(keywords) |
|---|