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 | # now set type is not using because of it unordered behaviour |
---|
18 | #original = set(self.context.qSEO_Keywords()) |
---|
19 | #additional = set(seo_props.additional_keywords) |
---|
20 | #text = set(self.context.SearchableText().split()) |
---|
21 | #keywords = list(additional.intersection(text).union(original)) |
---|
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 | # extract words from url page using lynx browser |
---|
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) |
---|