You are here

function keyword_rules_headings in SEO Compliance Checker 6.2

Same name and namespace in other branches
  1. 6 keyword_rules/keyword_rules.module \keyword_rules_headings()
1 string reference to 'keyword_rules_headings'
keyword_rules_register_seo_rules in keyword_rules/keyword_rules.module
Implementation of hook_register_seo_rules().

File

keyword_rules/keyword_rules.module, line 135
Implements some keyword based rules for the SEO Checker.

Code

function keyword_rules_headings($form_values) {
  $tags = _keyword_rules_extract_tags($form_values);
  $body = $form_values['body'];
  if (!($nr_matches = preg_match_all('/<h(\\d)>(.*?)<\\/h\\d>/i', $body, $matches, PREG_SET_ORDER))) {
    return 100;
  }
  $good_weight = 0;
  $bad_weight = 0;
  foreach ($matches as $match) {
    $weight = $match[1];
    $heading = $match[2];
    $found = 0;
    foreach ($tags as $tag) {
      $found += intval(seo_checker_wordipos($heading, $tag) !== FALSE);
    }
    if ($found > 0) {
      $good_weight += $found / $weight;
    }
    else {
      $bad_weight += 1 / $weight;
    }
  }
  return 100 * ($good_weight / ($good_weight + $bad_weight));
}