Changeset 1012

Show
Ignore:
Timestamp:
11/30/07 07:22:04
Author:
piv
Message:

refactored keywords checking

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • qSEOptimizer/trunk/configure.zcml

    r988 r1012  
    11<configure 
    22    xmlns="http://namespaces.zope.org/zope" 
    3     xmlns:five="http://namespaces.zope.org/five" 
    4     > 
     3    xmlns:browser="http://namespaces.zope.org/browser"> 
     4 
     5    <browser:page 
     6        for="Products.Archetypes.interfaces.IBaseObject" 
     7        attribute="validateKeywords" 
     8        class=".browser.keywords.ValidateSEOKeywordsView" 
     9        name="checkSEOKeywords" 
     10        permission="cmf.ModifyPortalContent" 
     11        /> 
    512 
    613  <adapter 
  • qSEOptimizer/trunk/skins/qSEOptimizer/checkkeywords.js.dtml

    r1006 r1012  
    1 /****************************************************************** 
    2 <dtml-with portal_properties> 
     1/******************************************************************/ 
    32 
    4 *******************************************************************/ 
     3var url = '&dtml-absolute_url;/checkSEOKeywords'; 
     4var KEYWORDS_IDS = ['seo_keywords',]; 
     5// var KEYWORDS_REPORT = {}; 
    56 
    6 var KEYWORDS_IDS = ['seo_keywords',]; 
    7 var KEYWORDS_REPORT = {}; 
     7// function extractWords(data) { 
     8//     data = data // replace all non-word character with space 
     9//                 .replace(/[^a-zA-Z0-9\-\'\u2019\"\`]+/g, ' ') 
     10//                 // replace "-" and "'" symbols if it create groups event inside of token 
     11//                 .replace(/[\-\'\u2019\"\`]{2,}/g, ' ') 
     12//                 // replace all non-word characters and "-", "'" if it stay at word edge 
     13//                 .replace(/(?:^|\s+)[^a-zA-Z0-9]+|[^a-zA-Z0-9]+(?:\s+|$)/g, ' ') 
     14//                 // strip whitespaces 
     15//                 .replace(/^\s*(.*?)\s*$/, '$1'); 
     16//     return data.split(/[^a-zA-Z0-9\-\'\u2019\"\`]+/); 
     17// } 
     18//  
     19// function countTerm(node, word, id) { 
     20//     var contents = extractWords(node.nodeValue.toLowerCase()); 
     21//     var term = word.toLowerCase(); 
     22//     for (var i = 0, w; w = contents[i]; i++) { 
     23//         if (w == term) { 
     24//             KEYWORDS_REPORT[id][word] = 1; 
     25//             return 'found'; 
     26//         } 
     27//     } 
     28//     return false; 
     29// } 
     30//  
     31// function keywordsWalkTextNodes(node, func, data, id) { 
     32//     if (!node) return false; 
     33//     if (KEYWORDS_REPORT[id][data] == 1) return 'found'; 
     34//     if (node.hasChildNodes) { 
     35//         if (node.nodeType == 3) { 
     36//             if (func(node, data, id) == 'found') { 
     37//                 return 'found'; 
     38//             } 
     39//         } 
     40//         for (var i = 0; i < node.childNodes.length; i++) { 
     41//             if (keywordsWalkTextNodes(node.childNodes[i], func, data, id) == 'found') { 
     42//                 return 'found'; 
     43//             } 
     44//         } 
     45//     } 
     46// } 
    847 
    9 function extractWords(data) { 
    10     data = data // replace all non-word character with space 
    11                 .replace(/[^a-zA-Z0-9\-\'\u2019\"\`]+/g, ' ') 
    12                 // replace "-" and "'" symbols if it create groups event inside of token 
    13                 .replace(/[\-\'\u2019\"\`]{2,}/g, ' ') 
    14                 // replace all non-word characters and "-", "'" if it stay at word edge 
    15                 .replace(/(?:^|\s+)[^a-zA-Z0-9]+|[^a-zA-Z0-9]+(?:\s+|$)/g, ' ') 
    16                 // strip whitespaces 
    17                 .replace(/^\s*(.*?)\s*$/, '$1'); 
    18     return data.split(/[^a-zA-Z0-9\-\'\u2019\"\`]+/); 
    19 
    20  
    21 function countTerm(node, word, id) { 
    22     var contents = extractWords(node.nodeValue.toLowerCase()); 
    23     var term = word.toLowerCase(); 
    24     for (var i = 0, w; w = contents[i]; i++) { 
    25         if (w == term) { 
    26             KEYWORDS_REPORT[id][word] = 1; 
    27             return 'found'; 
    28         } 
    29     } 
    30     return false; 
    31 
    32  
    33 function keywordsWalkTextNodes(node, func, data, id) { 
    34     if (!node) return false; 
    35     if (KEYWORDS_REPORT[id][data] == 1) return 'found'; 
    36     if (node.hasChildNodes) { 
    37         if (node.nodeType == 3) { 
    38             if (func(node, data, id) == 'found') { 
    39                 return 'found'; 
    40             } 
    41         } 
    42         for (var i = 0; i < node.childNodes.length; i++) { 
    43             if (keywordsWalkTextNodes(node.childNodes[i], func, data, id) == 'found') { 
    44                 return 'found'; 
    45             } 
    46         } 
    47     } 
    48 
     48// function checkPageKeywords(event) { 
     49//     var event = event ? event:window.event; 
     50//     var target = event.target ? event.target : event.srcElement; 
     51//     if (!target) {return false;}; 
     52//     var id = target.id.replace('_check_keywords', '') 
     53//     KEYWORDS_REPORT[id] = {}; 
     54//     var area = document.getElementById(id); 
     55//     if (area && typeof(area.value) != 'undefined') { 
     56//         var terms = extractWords(area.value); 
     57//         for (var i = 0, term; term = terms[i]; i++) { 
     58//             if (KEYWORDS_REPORT[id][term] == 1) continue; 
     59//             KEYWORDS_REPORT[id][term] = 0; 
     60//             keywordsWalkTextNodes(document.body, countTerm, term, id); 
     61//         } 
     62//     } 
     63//     var report = ''; 
     64//     for (var term in KEYWORDS_REPORT[id]) { 
     65//         if (KEYWORDS_REPORT[id][term] != 1) 
     66//             report += term + ' '; 
     67//     } 
     68//     KEYWORDS_REPORT[id] = {}; 
     69//     if (report != '') { 
     70//         report = 'Next keywords did not appear on the page:\n' + report; 
     71//     } else { 
     72//         report = 'All keywords found on the page!'; 
     73//     } 
     74//     alert(report); 
     75//     return false; 
     76// } 
    4977 
    5078function checkPageKeywords(event) { 
     
    5381    if (!target) {return false;}; 
    5482    var id = target.id.replace('_check_keywords', '') 
    55     KEYWORDS_REPORT[id] = {}; 
    5683    var area = document.getElementById(id); 
    5784    if (area && typeof(area.value) != 'undefined') { 
    58         var terms = extractWords(area.value); 
    59         for (var i = 0, term; term = terms[i]; i++) { 
    60             if (KEYWORDS_REPORT[id][term] == 1) continue; 
    61             KEYWORDS_REPORT[id][term] = 0; 
    62             keywordsWalkTextNodes(document.body, countTerm, term, id); 
    63         } 
     85        var req = new XMLHttpRequest(); 
     86        req.open("POST", url, true); 
     87        req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
     88        req.onreadystatechange = function(request) { 
     89            if (req.readyState == 4) { 
     90                if (req.status == '200') { 
     91                    alert(req.responseText); 
     92                } else { 
     93                    alert('Error on server!'); 
     94                } 
     95            } 
     96        }; 
     97        req.send("text="+area.value); 
    6498    } 
    65     var div = document.createElement('DIV'); 
    66     var report = ''; 
    67     for (var term in KEYWORDS_REPORT[id]) { 
    68         if (KEYWORDS_REPORT[id][term] != 1) 
    69             report += term + ' '; 
    70     } 
    71     KEYWORDS_REPORT[id] = {}; 
    72     if (report != '') { 
    73         report = 'Next keywords did not appear on the page:\n' + report; 
    74     } else { 
    75         report = 'All keywords found on the page!'; 
    76     } 
    77     alert(report); 
    7899    return false; 
    79100} 
     
    91112        area.parentNode.insertBefore(button, area.nextSibling); 
    92113        registerEventListener(button, 'click', checkPageKeywords); 
    93         KEYWORDS_REPORT[id] = {}; 
     114//         KEYWORDS_REPORT[id] = {}; 
    94115    } 
    95116} 
    96117 
    97118registerPloneFunction(addKeywordsButton); 
    98  
    99 /*</dtml-with> Register onload function */ 
  • qSEOptimizer/trunk/skins/qSEOptimizer/qseo_properties_edit_form.cpt

    r1007 r1012  
    1717      <script type="text/javascript" 
    1818              tal:condition="python:exists('portal/statistics.js')" 
    19               tal:attributes="src string:$portal_url/statistics.js"> 
     19              tal:attributes="src string:${here/absolute_url}/statistics.js"> 
    2020      </script> 
    2121      <script type="text/javascript" 
    2222              tal:condition="python:exists('portal/checkkeywords.js')" 
    23               tal:attributes="src string:$portal_url/checkkeywords.js"> 
     23              tal:attributes="src string:${here/absolute_url}/checkkeywords.js"> 
    2424      </script> 
    2525      <script type="text/javascript" 
    2626              tal:condition="python:exists('portal/custommetatags.js')" 
    27               tal:attributes="src string:$portal_url/custommetatags.js"> 
     27              tal:attributes="src string:${here/absolute_url}/custommetatags.js"> 
    2828      </script> 
    2929  </metal:javascript_head>