function contentoptimizer_analyzer in Content Optimizer 8
Same name and namespace in other branches
- 6.2 contentoptimizer.module \contentoptimizer_analyzer()
- 7.2 contentoptimizer.module \contentoptimizer_analyzer()
Implementation of hook_contentanalysis_analyzer() via custom define callback
Analyzes body, title, meta keywords and descriptions. Calculates stats for each section, e.g. char count, word count, etc. Compares stats with SEO guidelines
@rerturn array SEO analysis
1 string reference to 'contentoptimizer_analyzer'
- contentoptimizer_contentanalysis_analyzer_info in ./
contentoptimizer.module - Implementation of hook_contentalalysis_analyzer_info()
File
- ./
contentoptimizer.module, line 479 - Analyzes content for search engine optimization recommendations
Code
function contentoptimizer_analyzer($context, $analysis, $params) {
$settings = $context['analyzers']['seo']['settings'];
$a = contentoptimizer_contentanalysis_analyzer_info();
$form = contentoptimizer_settings_form_elements($settings, $a['seo']);
$a = array();
$stats = array();
$keyword = '';
$analysis['#status'] = 'complete';
if (isset($context['inputs']['analyzer_options']['seo']['keyword'])) {
$keyword = check_plain(strtolower($context['inputs']['analyzer_options']['seo']['keyword']));
}
if (!$keyword && isset($context['nid']) && $context['nid'] && $settings['seo_use_kwresearch_keyword'] && module_exists('kwresearch')) {
$keyword = kwresearch_load_top_page_keyword_by_page($context['nid']);
}
if ($context['aid']) {
if ($keyword) {
contentoptimizer_set_keyword($context['aid'], $keyword);
}
else {
$keyword = contentoptimizer_get_keyword($context['aid']);
}
}
$keyword = strtolower($keyword);
$msg = '<div>Keyword: <span class="kwresearch_keyword">@keyword</span></div>';
$analysis['content'][] = contentanalysis_format_content(t($msg, array(
'@keyword' => $keyword,
)), -5);
if (!$keyword) {
$msg = t('No targeted keyword phrase was submitted for analysis. Input a keyword for more targeted recommendations.');
if ($settings['seo_keyword_not_set'] >= 0) {
$severity = 'status';
if ($settings['seo_keyword_not_set'] == 1) {
$severity = 'warning';
}
elseif ($settings['seo_keyword_not_set'] == 0) {
$severity = 'error';
}
$analysis['messages'][] = contentoptimizer_format_message($msg, $severity, $analysis, 'seo_keyword_not_set');
if ($settings['seo_keyword_not_set'] <= 1) {
$analysis['#status'] = $severity;
}
}
else {
$analysis['messages'][] = contentanalysis_format_message($msg, 'warning');
}
}
// analyze body
$body = strtolower($context['body']);
$body_notags = strtolower($context['body_notags']);
$stats['body'] = contentoptimizer_calc_stats($body_notags, $keyword);
$analysis['body']['stats'] = contentoptimizer_format_stats($stats['body']);
//dsm($settings);
$body_words_min = $settings['seo_body_length'][0];
$body_words_max = $settings['seo_body_length'][1];
$body_words_min_warning = $settings['seo_body_length_warning'][0];
$body_words_max_warning = $settings['seo_body_length_warning'][1];
$body_freq_min = $settings['seo_keyword_body_freq'][0];
$body_freq_max = $settings['seo_keyword_body_freq'][1];
$body_freq_min_warning = $settings['seo_keyword_body_freq_warning'][0];
$body_freq_max_warning = $settings['seo_keyword_body_freq_warning'][1];
$body_prominence_min = $settings['seo_keyword_body_prominence'][0];
$body_prominence_min_warning = $settings['seo_keyword_body_prominence_warning'][0];
$words = $stats['body']['word_count'];
$freq = $stats['body']['keyword_count'];
$prominence = $stats['body']['keyword_prominence'];
$params = array(
'%min_words' => $body_words_min,
'%max_words' => $body_words_max,
'%min_words_pluralized' => format_plural($body_words_min, '1 word', '@count words'),
'%max_words_pluralized' => format_plural($body_words_max, '1 word', '@count words'),
'%min_freq' => $body_freq_min,
'%max_freq' => $body_freq_max,
'%min_freq_pluralized' => format_plural($body_freq_min, '1 time', '@count times'),
'%max_freq_pluralized' => format_plural($body_freq_max, '1 time', '@count times'),
'%min_prominence' => $body_prominence_min,
'%words' => $words,
'%words_pluralized' => format_plural($words, '1 word', '@count words'),
'%freq' => $freq,
'%freq_pluralized' => format_plural($freq, '1 time', '@count times'),
'%prominence' => $prominence,
'@keyword' => $keyword,
);
$analysis['body']['messages'] = array();
// turn off analysis if settings range at max
if ($body_words_min != $form['seo_body_length']['#min'] || $body_words_max != $form['seo_body_length']['#max']) {
if ($words < $body_words_min) {
$msg = t('You body contains %words_pluralized. At least %min_words to %max_words words is recommended. Consider increasing the number of words.', $params);
$analysis['body']['messages'][] = contentoptimizer_format_message($msg, $words < $body_words_min_warning ? 'error' : 'warning', $analysis, 'seo_body_length');
}
elseif ($words > $body_words_max) {
$msg = t('You body contains %words_pluralized. No more than %min_words to %max_words words is recommended. Consider reducing the number of words.', $params);
$analysis['body']['messages'][] = contentoptimizer_format_message($msg, $words > $body_words_max_warning ? 'error' : 'warning', $analysis, 'seo_body_length');
}
}
if ($keyword) {
if ($body_freq_min != $form['seo_keyword_body_freq']['#min'] || $body_freq_max != $form['seo_keyword_body_freq']['#max']) {
if ($freq < $body_freq_min) {
$msg = t('The targed keyword "@keyword" occurs in the body %freq_pluralized. At least %min_freq to %max_freq times is recommended. Consider increasing the number of keyword occurences in your body copy.', $params);
$analysis['body']['messages'][] = contentoptimizer_format_message($msg, $freq < $body_freq_min_warning ? 'error' : 'warning', $analysis, 'seo_keyword_body_freq');
}
elseif ($freq > $body_freq_max) {
$msg = t('The targed keyword "@keyword" occurs in the body %freq_pluralized. No more than %min_freq to %max_freq times is recommended. Consider reducing the number of keyword occurences in your body copy.', $params);
$analysis['body']['messages'][] = contentoptimizer_format_message($msg, $freq > $body_freq_max_warning ? 'error' : 'warning', $analysis, 'seo_keyword_body_freq');
}
}
if ($freq && $prominence < $body_prominence_min) {
$msg = t('Your keyword prominence is less that %prominence% in the body. Consider increasing your keyword\'s prominence by moving occurences closer to the beginning of your copy.');
$analysis['body']['messages'][] = contentoptimizer_format_message($msg, $prominence < $body_prominence_min_warning ? 'error' : 'warning', $analysis, 'seo_keyword_body_prominence');
}
}
if (count($analysis['body']['messages']) > 0) {
foreach ($analysis['body']['messages'] as $msg) {
$analysis['body']['#status'] = $analysis['body']['#status'] != 'error' ? $msg['#status'] : 'error';
$analysis['#status'] = $analysis['#status'] != 'error' ? $msg['#status'] : 'error';
}
}
else {
if ($keyword) {
$analysis['body']['messages'][] = contentanalysis_format_message(t('Optimized'), 'complete');
$analysis['body']['#status'] = 'complete';
$analysis['#status'] = 'complete';
}
else {
$analysis['body']['#status'] = 'status';
}
}
// only analyze body if content is directly inputed without a full page
if (is_null($context['aid']) && $context['form_id'] == 'contentanalysis_page_analyzer') {
return $analysis;
}
// Analyze page title
$check_meta = TRUE;
if (!module_exists('metatag')) {
$check_meta = FALSE;
$msg = t('The !link module is not installed. We recommend installing it to enable editing of page meta information.', array(
'!link' => l(t('Meta tags'), 'http://drupal.org/project/metatag', array(
'attributes' => array(
'target' => '_blank',
),
)),
));
$analysis['messages'][] = contentanalysis_format_message($msg, 'warning');
}
/*
if (!$check_meta && !module_exists('page_title')) {
$msg = t('The !link module is not installed. We recommend installing it to enable editing of page meta information.',
array(
'!link' => l(t('Page title'), 'http://drupal.org/project/page_title', array('attributes' => array('target' => '_blank'))),
)
);
$analysis['messages'][] = contentanalysis_format_message($msg, 'warning');
}
*/
$title_chars_min = $settings['seo_meta_title_length_chars'][0];
$title_chars_max = $settings['seo_meta_title_length_chars'][1];
$title_chars_min_warning = $settings['seo_meta_title_length_chars_warning'][0];
$title_chars_max_warning = $settings['seo_meta_title_length_chars_warning'][1];
$title_words_min = $settings['seo_meta_title_length'][0];
$title_words_max = $settings['seo_meta_title_length'][1];
$title_words_min_warning = $settings['seo_meta_title_length_warning'][0];
$title_words_max_warning = $settings['seo_meta_title_length_warning'][1];
$title_freq_min = $settings['seo_keyword_meta_title_freq'][0];
$title_freq_max = $settings['seo_keyword_meta_title_freq'][1];
$title_freq_min_warning = $settings['seo_keyword_meta_title_freq_warning'][0];
$title_freq_max_warning = $settings['seo_keyword_meta_title_freq_warning'][1];
$page_title_raw = $context['meta_title'] ? $context['meta_title'] : $context['page_title'];
$page_title = strtolower($page_title_raw);
$analysis['page_title']['messages'] = array();
if (isset($context['inputs']['title']) && $page_title_raw != $context['inputs']['title']) {
$msg = '<strong>' . t('Page title: ') . '</strong>' . $page_title_raw;
//$msg .= '<br/>' . t('Node title: ') . $context['inputs']['title'];
//$msg .= '<br/>' . t('Meta title: ') . $context['inputs']['meta_title'];
$analysis['page_title']['content'][] = contentanalysis_format_content($msg, -5);
}
$stats['page_title'] = contentoptimizer_calc_stats($page_title, $keyword);
$analysis['page_title']['stats'] = contentoptimizer_format_stats($stats['page_title']);
$chars = $stats['page_title']['char_count'];
$words = $stats['page_title']['word_count'];
$freq = $stats['page_title']['keyword_count'];
$prominence = $stats['body']['keyword_prominence'];
$params = array(
'%min_words' => $title_words_min,
'%max_words' => $title_words_max,
'%min_words_pluralized' => format_plural($title_words_min, '1 word', '@count words'),
'%max_words_pluralized' => format_plural($title_words_max, '1 word', '@count words'),
'%min_chars' => $title_chars_min,
'%max_chars' => $title_chars_max,
'%min_chars_pluralized' => format_plural($title_chars_min, '1 character', '@count characters'),
'%max_chars_pluralized' => format_plural($title_chars_max, '1 character', '@count characters'),
'%min_freq' => $title_freq_min,
'%max_freq' => $title_freq_max,
'%min_freq_pluralized' => format_plural($title_freq_min, '1 time', '@count times'),
'%max_freq_pluralized' => format_plural($title_freq_max, '1 time', '@count times'),
'%words' => $words,
'%words_pluralized' => format_plural($words, '1 word', '@count words'),
'%chars' => $chars,
'%chars_pluralized' => format_plural($chars, '1 character', '@count characters'),
'%freq' => $freq,
'%freq_pluralized' => format_plural($freq, '1 time', '@count times'),
'%prominence' => $prominence,
'@keyword' => $keyword,
);
$words_enabled = $title_words_min != $form['seo_meta_title_length']['#min'] || $title_words_max != $form['seo_meta_title_length']['#max'];
$chars_enabled = $title_chars_min != $form['seo_meta_title_length_chars']['#min'] || $title_chars_max != $form['seo_meta_title_length_chars']['#max'];
//dsm("$title_chars_min != " . $form['seo_meta_title_length_chars']['#min'] . " || $title_chars_max != " . $form['seo_meta_title_length_chars']['#max']);
//dsm("$title_words_min != " . $form['seo_meta_title_length']['#min'] . " || $title_words_max != " . $form['seo_meta_title_length']['#max']);
//dsm("$words_enable $chars_enable && ($words > $title_words_max)");
if ($chars_enabled && $chars > $title_chars_max) {
$msg = t('Your page title contains %chars_pluralized. No more than %min_chars_pluralized to %max_chars_pluralized is recommended. Consider reducing the length of your page title.', $params);
$analysis['page_title']['messages'][] = contentoptimizer_format_message($msg, $chars > $title_chars_max_warning ? 'error' : 'warning', $analysis, 'seo_meta_title_length');
}
elseif ($words_enabled && $words > $title_words_max) {
$msg = t('Your page title contains %words_pluralized. No more than %min_words_pluralized to %max_words_pluralized is recommended. Consider reducing the number of words in your page title.', $params);
$analysis['page_title']['messages'][] = contentoptimizer_format_message($msg, $words > $title_words_max_warning ? 'error' : 'warning', $analysis, 'seo_meta_title_length');
}
elseif ($words_enabled && $words < $title_words_min || $chars_enabled && $chars < $title_chars_min) {
$msg = t('Your page title contains %chars_pluralized. It can be up to %max_chars_pluralized. Consider adding more keyword rich content to your title.', $params);
$analysis['page_title']['messages'][] = contentoptimizer_format_message($msg, $words < $title_words_min_warning || $chars < $title_chars_min_warning ? 'error' : 'warning', $analysis, 'seo_meta_title_length');
}
if ($keyword) {
if ($title_freq_min != $form['seo_keyword_meta_title_freq']['#min'] || $title_freq_max != $form['seo_keyword_meta_title_freq']['#max']) {
if ($freq < $title_freq_min) {
$msg = t('The targed keyword "@keyword" occurs in the page title %freq_pluralized. At least %min_freq_pluralized is recommended. Consider adding targeted keywords to your title.', $params);
$analysis['page_title']['messages'][] = contentoptimizer_format_message($msg, $freq < $title_freq_min_warning ? 'error' : 'warning', $analysis, 'seo_keyword_meta_title_freq');
}
elseif ($freq > $title_freq_max) {
$msg = t('The targed keyword "@keyword" occurs in the page title %freq_pluralized. No more than %max_freq_pluralized is recommended. Consider reducing the number of times the targeted keywords in your title.', $params);
$analysis['page_title']['messages'][] = contentoptimizer_format_message($msg, $freq < $title_freq_max_warning ? 'error' : 'warning', $analysis, 'seo_keyword_meta_title_freq');
}
}
if ($freq && $prominence < $body_prominence_min) {
$msg = t('Your keyword prominence is less that %prominence% in the page title. Consider increasing your keyword\'s prominence by moving occurences closer to the beginning of your title.');
$analysis['body']['messages'][] = contentoptimizer_format_message($msg, $prominence < $body_prominence_min_warning ? 'error' : 'warning', $analysis, 'seo_keyword_meta_title_prominence');
}
}
if (count($analysis['page_title']['messages']) > 0) {
foreach ($analysis['page_title']['messages'] as $msg) {
$analysis['page_title']['#status'] = $analysis['page_title']['#status'] != 'error' ? $msg['#status'] : 'error';
$analysis['#status'] = $analysis['#status'] != 'error' ? $msg['#status'] : 'error';
}
}
else {
if ($keyword) {
$analysis['page_title']['messages'][] = contentanalysis_format_message(t('Optimized'), 'complete');
$analysis['page_title']['#status'] = 'complete';
if ($analysis['#status'] != 'warning' && $analysis['#status'] != 'error') {
$analysis['#status'] = 'complete';
}
}
else {
$analysis['page_title']['#status'] = 'status';
}
}
// analyze meta description
if ($check_meta && $context['meta_description'] != -1) {
$meta_description = strtolower(strip_tags($context['meta_description']));
$stats['meta_description'] = contentoptimizer_calc_stats($meta_description, $keyword);
$analysis['meta_description']['stats'] = contentoptimizer_format_stats($stats['meta_description']);
//$meta_description_words_min = $settings['seo_meta_description_length'][0];
//$meta_description_words_max = $settings['seo_meta_description_length'][0];
$meta_description_chars_min = $settings['seo_meta_description_length_chars'][0];
$meta_description_chars_max = $settings['seo_meta_description_length_chars'][1];
$meta_description_chars_min_warning = $settings['seo_meta_description_length_chars_warning'][0];
$meta_description_chars_max_warning = $settings['seo_meta_description_length_chars_warning'][1];
$meta_description_freq_min = $settings['seo_keyword_meta_description_freq'][0];
$meta_description_freq_max = $settings['seo_keyword_meta_description_freq'][1];
$meta_description_freq_min_warning = $settings['seo_keyword_meta_description_freq_warning'][0];
$meta_description_freq_max_warning = $settings['seo_keyword_meta_description_freq_warning'][1];
$chars = $stats['meta_description']['char_count'];
$words = $stats['meta_description']['word_count'];
$freq = $stats['meta_description']['keyword_count'];
$params = array(
//'%min_words' => $meta_description_words_min,
//'%max_words' => $meta_description_words_max,
//'%min_words_pluralized' => format_plural($meta_description_words_min, '1 word', '@count words'),
//'%max_words_pluralized' => format_plural($meta_description_words_max, '1 word', '@count words'),
'%min_chars' => $meta_description_chars_min,
'%max_chars' => $meta_description_chars_max,
'%min_chars_pluralized' => format_plural($meta_description_chars_min, '1 character', '@count characters'),
'%max_chars_pluralized' => format_plural($meta_description_chars_max, '1 character', '@count characters'),
'%min_freq' => $meta_description_freq_min,
'%max_freq' => $meta_description_freq_max,
'%min_freq_pluralized' => format_plural($meta_description_freq_min, '1 time', '@count times'),
'%max_freq_pluralized' => format_plural($meta_description_freq_max, '1 time', '@count times'),
'%words' => $words,
'%words_pluralized' => format_plural($words, '1 word', '@count words'),
'%chars' => $chars,
'%chars_pluralized' => format_plural($chars, '1 character', '@count characters'),
'%freq' => $freq,
'%freq_pluralized' => format_plural($freq, '1 time', '@count times'),
'@keyword' => $keyword,
);
$ret['meta_description']['messages'] = array();
if ($meta_description_chars_min != $form['seo_meta_description_length_chars']['#min'] || $meta_description_chars_max != $form['seo_meta_description_length_chars']['#max']) {
if ($chars < $meta_description_chars_min) {
$msg = t('You meta description contains %chars_pluralized. At least %min_chars to %max_chars characters is recommended. Consider increasing the length.', $params);
$analysis['meta_description']['messages'][] = contentoptimizer_format_message($msg, $chars < $meta_description_chars_min_warning ? 'error' : 'warning', $analysis, 'seo_meta_description_length');
}
elseif ($chars > $meta_description_chars_max) {
$msg = t('You meta description contains %chars_pluralized. No more than %min_chars to %max_chars characters is recommended. Consider reducing the length.', $params);
$analysis['meta_description']['messages'][] = contentoptimizer_format_message($msg, $chars < $meta_description_chars_min_warning ? 'error' : 'warning', $analysis, 'seo_meta_description_length');
}
}
if ($keyword) {
if ($meta_description_freq_min != $form['seo_keyword_meta_description_freq']['#min'] || $meta_description_freq_max != $form['seo_keyword_meta_description_freq']['#max']) {
if ($freq < $meta_description_freq_min) {
$msg = t('The targed keyword "@keyword" occurs in the meta description %freq_pluralized. At least %min_freq to %max_freq times is recommended. Consider increasing the number of keyword occurences in your meta description list.', $params);
$analysis['meta_description']['messages'][] = contentoptimizer_format_message($msg, $freq < $meta_description_freq_min_warning ? 'error' : 'warning', $analysis, 'seo_keyword_meta_description_freq');
}
elseif ($freq > $meta_description_freq_max) {
$msg = t('The targed keyword "@keyword" occurs in the meta description %freq_pluralized. No more than %min_freq to %max_freq times is recommended. Consider reducing the number of keyword occurences in your meta description list.', $params);
$analysis['meta_description']['messages'][] = contentoptimizer_format_message($msg, $freq > $meta_description_freq_max_warning ? 'error' : 'warning', $analysis, 'seo_keyword_meta_description_freq');
}
}
}
if (!$settings['seo_meta_description_dont_inherit_status']) {
if (count($analysis['meta_description']['messages']) > 0) {
foreach ($analysis['meta_description']['messages'] as $msg) {
$analysis['meta_description']['#status'] = $analysis['meta_description']['#status'] != 'error' ? $msg['#status'] : 'error';
$analysis['#status'] = $analysis['#status'] != 'error' ? $msg['#status'] : 'error';
}
}
else {
$analysis['meta_description']['messages'][] = contentanalysis_format_message(t('Optimized'), 'complete');
$analysis['meta_description']['#status'] = 'complete';
}
}
}
// analyze meta keywords
if ($check_meta && $context['meta_keywords'] != -1) {
$meta_keywords = strtolower($context['meta_keywords']);
$stats['meta_keywords'] = contentoptimizer_calc_stats($meta_keywords, $keyword);
if (!$meta_keywords) {
$stats['meta_keywords']['phrase_count'] = 0;
}
else {
$meta_keyword_segs = explode(',', $meta_keywords);
$stats['meta_keywords']['phrase_count'] = count($meta_keyword_segs);
}
$analysis['meta_keywords']['stats'] = contentoptimizer_format_stats($stats['meta_keywords']);
$words = format_plural($stats['meta_keywords']['word_count'], '1 word', '@count words');
$phrases = format_plural($stats['meta_keywords']['phrase_count'], '1 phrase', '@count phrases');
$freq = format_plural($stats['meta_keywords']['keyword_count'], '1 time', '@count times');
$meta_keywords_words_min = $settings['seo_meta_keywords_length'][0];
$meta_keywords_words_max = $settings['seo_meta_keywords_length'][1];
$meta_keywords_words_min_warning = $settings['seo_meta_keywords_length_warning'][0];
$meta_keywords_words_max_warning = $settings['seo_meta_keywords_length_warning'][1];
$meta_keywords_phrases_min = $settings['seo_meta_keywords_length_phrases'][0];
$meta_keywords_phrases_max = $settings['seo_meta_keywords_length_phrases'][1];
$meta_keywords_phrases_min_warning = $settings['seo_meta_keywords_length_phrases_warning'][0];
$meta_keywords_phrases_max_warning = $settings['seo_meta_keywords_length_phrases_warning'][1];
$meta_keywords_freq_min = $settings['seo_keyword_meta_keywords_freq'][0];
$meta_keywords_freq_max = $settings['seo_keyword_meta_keywords_freq'][1];
$meta_keywords_freq_min_warning = $settings['seo_keyword_meta_keywords_freq_warning'][0];
$meta_keywords_freq_max_warning = $settings['seo_keyword_meta_keywords_freq_warning'][1];
$words = $stats['meta_keywords']['word_count'];
$phrases = $stats['meta_keywords']['phrase_count'];
$freq = $stats['meta_keywords']['keyword_count'];
$params = array(
'%min_words' => $meta_keywords_words_min,
'%max_words' => $meta_keywords_words_max,
'%min_words_pluralized' => format_plural($meta_keywords_words_min, '1 word', '@count words'),
'%max_words_pluralized' => format_plural($meta_keywords_words_max, '1 word', '@count words'),
'%min_phrases' => $meta_keywords_phrases_min,
'%max_phrases' => $meta_keywords_phrases_max,
'%min_phrases_pluralized' => format_plural($meta_keywords_phrases_min, '1 character', '@count characters'),
'%max_phrases_pluralized' => format_plural($meta_keywords_phrases_max, '1 character', '@count characters'),
'%min_freq' => $meta_keywords_freq_min,
'%max_freq' => $meta_keywords_freq_max,
'%min_freq_pluralized' => format_plural($meta_keywords_freq_min, '1 time', '@count times'),
'%max_freq_pluralized' => format_plural($meta_keywords_freq_max, '1 time', '@count times'),
'%words' => $words,
'%words_pluralized' => format_plural($words, '1 word', '@count words'),
'%phrases' => $chars,
'%phrases_pluralized' => format_plural($phrases, '1 phrase', '@count phrases'),
'%freq' => $freq,
'%freq_pluralized' => format_plural($freq, '1 time', '@count times'),
'@keyword' => $keyword,
);
$length_alert = FALSE;
$analysis['meta_keywords']['messages'] = array();
if ($meta_keywords_words_min != $form['seo_meta_keywords_length']['#min'] || $meta_keywords_words_max != $form['seo_meta_keywords_length']['#max']) {
if ($words < $meta_keywords_words_min) {
$msg = t('You meta keywords contains %words_pluralized. At least %min_words to %max_words words is recommended. Consider increasing the number of words.', $params);
$analysis['meta_keywords']['messages'][] = contentoptimizer_format_message($msg, $words < $meta_keywords_words_min_warning ? 'error' : 'warning', $analysis, 'seo_meta_keywords_length');
$length_alert = TRUE;
}
elseif ($words > $meta_keywords_words_max) {
$msg = t('You meta keywords contains %words_pluralized. No more than %min_words to %max_words words is recommended. Consider reducing the number of words.', $params);
$analysis['meta_keywords']['messages'][] = contentoptimizer_format_message($msg, $words > $meta_keywords_words_max_warning ? 'error' : 'warning', $analysis, 'seo_meta_keywords_length');
$length_alert = TRUE;
}
}
if (!$length_alert && ($meta_keywords_phrases_min != $form['seo_meta_keywords_length_phrases']['#min'] || $meta_keywords_phrases_max != $form['seo_meta_keywords_length_phrases']['#max'])) {
if ($phrases < $meta_keywords_phrases_min) {
$msg = t('You meta keywords contains %phrases_pluralized. At least %min_phrases to %max_phrases phrases is recommended. Consider increasing the number of phrases.', $params);
$analysis['meta_keywords']['messages'][] = contentoptimizer_format_message($msg, $phrases < $meta_keywords_phrases_min_warning ? 'error' : 'warning', $analysis, 'seo_meta_keywords_length_phrases');
}
elseif ($phrases > $meta_keywords_phrases_max) {
$msg = t('You meta keywords contains %phrases_pluralized. No more than %min_phrases to %max_phrases phrases is recommended. Consider reducing the number of phrases.', $params);
$analysis['meta_keywords']['messages'][] = contentoptimizer_format_message($msg, $phrases > $meta_keywords_phrases_max_warning ? 'error' : 'warning', $analysis, 'seo_meta_keywords_length_phrases');
}
}
if ($keyword) {
if ($meta_keywords_freq_min != $form['seo_keyword_meta_keywords_freq']['#min'] || $meta_keywords_freq_max != $form['seo_keyword_meta_keywords_freq']['#max']) {
if ($freq < $meta_keywords_freq_min) {
$msg = t('The targed keyword "@keyword" occurs in the meta keywords %freq_pluralized. At least %min_freq to %max_freq times is recommended. Consider increasing the number of keyword occurences in your meta keywords list.', $params);
$analysis['meta_keywords']['messages'][] = contentoptimizer_format_message($msg, $freq < $meta_keywords_freq_min_warning ? 'error' : 'warning', $analysis, 'seo_keyword_meta_keywords_freq');
}
elseif ($freq > $meta_keywords_freq_max) {
$msg = t('The targed keyword "@keyword" occurs in the meta keywords %freq_pluralized. No more than %min_freq to %max_freq times is recommended. Consider reducing the number of keyword occurences in your meta keywords list.', $params);
$analysis['meta_keywords']['messages'][] = contentoptimizer_format_message($msg, $freq > $meta_keywords_freq_max_warning ? 'error' : 'warning', $analysis, 'seo_keyword_meta_keywords_freq');
}
}
}
if (!$settings['seo_meta_keywords_dont_inherit_status']) {
if (count($analysis['meta_keywords']['messages']) > 0) {
foreach ($analysis['meta_keywords']['messages'] as $msg) {
$analysis['meta_keywords']['#status'] = $analysis['meta_keywords']['#status'] != 'error' ? $msg['#status'] : 'error';
$analysis['#status'] = $analysis['#status'] != 'error' ? $msg['#status'] : 'error';
}
}
else {
$analysis['meta_keywords']['messages'][] = contentanalysis_format_message(t('Optimized'), 'complete');
$analysis['meta_keywords']['#status'] = 'complete';
}
}
}
// add stats data for insight reports
/*
$analysis['#data'] = array(
'stats' => $stats,
);
*/
// save data for intel stats
if (!empty($context['nid']) && module_exists('intel')) {
$intel_attr = (object) array(
'entity_type' => 'node',
'entity_id' => $context['nid'],
);
$intel_attr->attr_key = 'cw';
$intel_attr->value = $stats['body']['word_count'];
intel_entity_attr_save($intel_attr);
$intel_attr->attr_key = 'ctw';
$intel_attr->value = $stats['page_title']['word_count'];
intel_entity_attr_save($intel_attr);
$intel_attr->attr_key = 'ctc';
$intel_attr->value = $stats['page_title']['char_count'];
intel_entity_attr_save($intel_attr);
}
/* functionality centralized to intel
contentanalysis_stat_save($context['aid'], 'seo', 'body_word_count', $stats['body']['word_count']);
contentanalysis_stat_save($context['aid'], 'seo', 'title_word_count', $stats['page_title']['word_count']);
contentanalysis_stat_save($context['aid'], 'seo', 'title_char_count', $stats['page_title']['char_count']);
*/
return $analysis;
}