Multi Keyword Statistics Instruction Page .The multi-keyword-statistics-Plugin checks the content of a post or a page for keyword-density (single words and optionally 2- and 3-word phrases; for each the 1-10 most commonly used can be displayed). It can update its informations automatically while the author is writing his content in a variable interval (every 1-10 seconds) or manually by clicking on a button. The script comes with english and german stopwords , which optionally can be filtered out before calculating the keyword-densities. Moreover the commonest keywords are extracted in a list as a meta-keyword suggestion. Based on this list a description can be created and automatically set.
Version: 4.7.14
Author: akshara
Author URI: http://www.111waystomakemoney.com/
*/
/*
Copyright (C) 2009-2010 akshara, (webmaster AT multi-keyword-statistics DOT net)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
$ks_plugin_version = '4.7.14';
// Language
$ks_plugin_dir = basename (dirname (__FILE__));
load_plugin_textdomain ('multi-keyword-statistics', 'wp-content/plugins/' . $ks_plugin_dir, $ks_plugin_dir );
// get plugins configuration
function keyword_statistics_get_plugin_configuration () {
global $wp_version;
if (substr ($wp_version, 0, 3) >= '2.7')
// WP 2.7+
$options = get_option ('keyword_statistics_configuration');
else {
$options = array ();
$options['version'] = get_option ('ks_version');
$options['testmode'] = get_option ('ks_testmode');
$options['default_language'] = get_option ('ks_default_language');
$options['set_language_meta'] = get_option ('ks_set_language_meta');
$options['filter_stopwords'] = get_option ('ks_filter_stopwords');
$options['max_list_items'] = get_option ('ks_max_list_items');
$options['automatic_update'] = get_option ('ks_automatic_update');
$options['update_interval'] = get_option ('ks_update_interval');
$options['2word_phrases'] = get_option ('ks_2word_phrases');
$options['3word_phrases'] = get_option ('ks_3word_phrases');
$options['meta_keywords_count'] = get_option ('ks_meta_keywords_count');
$options['max_keywords_count'] = get_option ('ks_max_keywords_count');
$options['max_keywords_length'] = get_option ('ks_keywords_length');
$options['index_aggregated'] = get_option ('ks_index_aggregated');
$options['follow_aggregated'] = get_option ('ks_follow_aggregated');
$options['noodp'] = get_option ('ks_noodp');
$options['noydir'] = get_option ('ks_noydir');
$options['noarchive'] = get_option ('ks_noarchive');
$options['dont_serve_metadata'] = get_option ('ks_dont_serve_metadata');
$options['serve_title'] = get_option ('ks_serve_title');
$options['serve_meta_robots'] = get_option ('ks_serve_meta_robots');
$options['serve_meta_keywords'] = get_option ('ks_serve_meta_keywords');
$options['serve_meta_description'] = get_option ('ks_serve_meta_description');
$options['serve_meta_canonical'] = get_option ('ks_serve_meta_canonical');
$options['words_from_posts_in_aggregated_description'] = get_option ('ks_words_from_posts_in_aggregated_description');
$options['max_title_length'] = get_option ('ks_max_title_length');
$options['min_description_length'] = get_option ('ks_min_description_length');
$options['max_description_length'] = get_option ('ks_max_description_length');
$options['automatic_meta_data_update'] = get_option ('ks_automatic_meta_data_update');
$options['min_words'] = get_option ('ks_min_words');
$options['hide_fields_authors_cant_change'] = get_option ('ks_hide_fields_authors_cant_change');
$options['hide_fields_authors_cant_change_from_admin'] = get_option ('ks_hide_fields_authors_cant_change_from_admin');
$options['authors_can_change_content_language'] = get_option ('ks_authors_can_change_content_language');
$options['authors_can_disable_stopword_filter'] = get_option ('ks_authors_can_disable_stopword_filter');
$options['authors_can_set_individual_title'] = get_option ('ks_authors_can_set_individual_title');
$options['authors_can_edit_keywords'] = get_option ('ks_authors_can_edit_keywords');
$options['authors_can_edit_description'] = get_option ('ks_authors_can_edit_description');
$options['authors_can_control_robots'] = get_option ('ks_authors_can_control_robots');
}
return $options;
}
// update plugins configuration
function keyword_statistics_set_plugin_configuration ($options) {
global $wp_version;
if (substr ($wp_version, 0, 3) >= '2.7')
update_option ('keyword_statistics_configuration', $options);
else
foreach ($options as $key => $value)
update_option ('ks_' . $key, $value);
}
// get the canonical url of a page, post or various content aggregations including pagination
function ks_canonical ($urlstruct) {
$p = '';
if (is_array ($urlstruct)) {
$home = get_option ('siteurl') != get_option ('home') ? get_option ('home') : get_option ('siteurl');
$has_permalink_structure = get_option ('permalink_structure') ? true : false;
$permalink = get_option ('permalink_structure');
switch ($urlstruct['type']) {
case 'home': $p = $home . '/';
// if postlist is set to a page url in configuration, we have to use that url for canonical
if (get_option ('show_on_front') == 'page' && get_option ('page_for_posts') != '')
$p = get_permalink (get_option ('page_for_posts'));
break;
case 'tag':
case 'category': $p = $home;
if ($has_permalink_structure)
$p .= ($urlstruct['type'] == 'category' ? (get_option ('category_base') ? '/' . get_option ('category_base') : substr ($permalink, 0, strpos ($permalink, '%')) . 'category') :
(get_option ('tag_base') ? '/' . get_option ('tag_base') : substr ($permalink, 0, strpos ($permalink, '%')) . 'tag'));
if (is_int ($urlstruct['id']) || is_string ($urlstruct['name']))
$p .= '/' . ($urlstruct['type'] == 'category' ? ($has_permalink_structure ? $urlstruct['name'] . (strrpos ($permalink, '/') == strlen ($permalink) - 1 ? '/' : '') : '?cat=' . $urlstruct['id']) :
($has_permalink_structure ? $urlstruct['name'] . (strrpos ($permalink, '/') == strlen ($permalink) - 1 ? '/' : '') : '?tag=' . $urlstruct['name']));
else
$p = '';
break;
case 'author': $p = $home;
if ($has_permalink_structure)
$p .= substr ($permalink, 0, strpos ($permalink, '%')) . 'author';
if (is_int ($urlstruct['id']) || is_string ($urlstruct['name']))
$p .= '/' . ($has_permalink_structure ? $urlstruct['name'] . (strrpos ($permalink, '/') == strlen ($permalink) - 1 ? '/' : '') : '?author=' . $urlstruct['id']);
else
$p = '';
break;
case 'page':
case 'post': $p = get_permalink ($urlstruct['id']) . (get_option ('show_on_front') == 'page' && get_option ('page_on_front') == $urlstruct['id'] ? '/' : '');
break;
case 'archive': if ($urlstruct['year'] && $urlstruct['month'] && $urlstruct['day'])
$p = get_day_link ($urlstruct['year'], $urlstruct['month'], $urlstruct['day']);
else if ($urlstruct['year'] && $urlstruct['month'])
$p = get_month_link ($urlstruct['year'], $urlstruct['month']);
else if ($urlstruct['year'])
$p = get_year_link ($urlstruct['year']);
break;
}
if (isset ($urlstruct['page']) && is_int ($urlstruct['page']))
$p .= !get_option ('permalink_structure') ? (strpos ($p, '?') != false ? '&paged=' : '?paged=') . $urlstruct['page'] : ((strrpos ($permalink, '/') == strlen ($permalink) - 1 && $urlstruct['type'] != 'home') || $urlstruct['type'] == 'home' ? '' : '/') . 'page/' . $urlstruct['page'] . (strrpos ($permalink, '/') == strlen ($permalink) - 1 ? '/' : '');
}
return $p;
}
// replace variables in a string
function ks_replace_variables ($s, $v = NULL) {
global $wp_query;
if (preg_match_all ('/%([^%]+)%/', $s, $matches)) {
$matches = array_unique ($matches[1]);
$replacement = '';
foreach ($matches as $key)
switch ($key) {
case 'blogname':
$s = preg_replace ('/%blogname%/', get_option ('blogname'), $s);
break;
case 'siteurl':
$replacement = preg_match ('/http[s]?:\/\/(.*)/', get_option ('siteurl') != get_option ('home') ? get_option ('home') : get_option ('siteurl'), $res) ? $res[1] : '';
$s = preg_replace ('/%siteurl%/', $replacement, $s);
break;
case 'category_name':
if (is_category ()) {
$category_info = get_category ($wp_query->query_vars['cat']);
$replacement = $category_info->slug;
}
else if ($v['category_name'])
$replacement = $v['category_name'];
$s = preg_replace ('/%category_name%/', $replacement, $s);
break;
case 'tag_name':
if ($wp_query->query['tag']) {
$replacement = $wp_query->query['tag'];
}
else if ($v['tag_name'])
$replacement = $v['tag_name'];
$s = preg_replace ('/%tag_name%/', $replacement, $s);
break;
case 'author_name':
if ($wp_query->query['author']) {
$user_data = get_userdata ($wp_query->query['author']);
$replacement = $user_data->user_login;
}
else if ($v['author_name'])
$replacement = $v['author_name'];
$s = preg_replace ('/%author_name%/', $replacement, $s);
break;
case 'archive_date':
if ($wp_query->query['m'])
$replacement = $wp_query->query['m'];
else if ($v['m'])
$replacement = $v['m'];
if (strlen ($replacement) == 4)
$replacement = __('Archive of', 'multi-keyword-statistics') . ' ' . $replacement;
else if (strlen ($replacement) == 6)
$replacement = __('Archive of', 'multi-keyword-statistics') . ' ' . date_i18n ('F/Y', mktime (0, 0, 0, intval (substr ($replacement, 4)), 1, intval (substr ($replacement, 0, 4))));
else if (strlen ($replacement) == 8)
$replacement = __('Archive of', 'multi-keyword-statistics') . ' ' . date_i18n (isset ($v['date_format']) ? $v['date_format'] : get_option ('date_format'), mktime (0, 0, 0, intval (substr ($replacement, 4, 2)), intval (substr ($replacement, 6)), intval (substr ($replacement, 0, 4))));
$s = preg_replace ('/%archive_date%/', $replacement, $s);
break;
case 'search_query':
if ($wp_query->query['s'])
$replacement = $wp_query->query['s'];
else if ($v['s'])
$replacement = $v['s'];
$s = preg_replace ('/%search_query%/', $replacement, $s);
break;
case 'pagination':
if (isset ($wp_query->query_vars['paged']) && $wp_query->query_vars['paged'] > 0)
$replacement = __('– page', 'multi-keyword-statistics') . ' ' . $wp_query->query_vars['paged'];
else if (intval ($v['paged']) > 1)
$replacement = __('– page', 'multi-keyword-statistics') . ' ' . $v['paged'];
$s = preg_replace ('/%pagination%/', $replacement, $s);
break;
}
}
// drop all other variables which could not be replaced in a particular
// section or the plugin doesn't know
$s = preg_replace ('/%[^%]+%/', '', $s);
return $s;
}
// putting meta keywords, language, robots, description and canonical url into header
function keyword_statistics_add_meta_tags () {
global $post, $posts, $wp_query, $ks_plugin_version;
$options = keyword_statistics_get_plugin_configuration ();
if ($options['dont_serve_metadata'] && !$options['testmode']) {
// nothing to do here if no meta information has to be inserted
echo "\n\n";
return;
}
echo "\n') . "\n";
if (is_404 ())
$meta['robots'] = 'noindex,nofollow';
else if (is_page () || is_single ()) {
// get meta data for post or page
$meta = get_post_meta ($post->ID, 'ks_metadata', true);
//$meta['canonical'] = get_permalink ($post->ID) . (get_option ('show_on_front') == 'page' && get_option ('page_on_front') == $post->ID ? '/' : '');
$meta['canonical'] = ks_canonical (array ('type' => is_page () ? 'page' : 'post', 'id' => $post->ID));
}
else if ((get_option ('show_on_front') == 'posts' || (get_option ('show_on_front') == 'page' && get_option ('page_on_front') == 0) || get_option ('page_for_posts') != '' || is_category () || /*is_tag ()*/ $wp_query->query['tag'] || $wp_query->query['year'] || $wp_query->query['author_name']) && $wp_query->post_count > 0) {
$isAggregation = TRUE;
if (is_category ()) {
if (!$wp_query->query_vars['paged'] || ($wp_query->query_vars['paged'] && $options['category_first'] == 0)) {
if ($options['category_title'])
$meta['title'] = $options['category_title'];
if ($options['category_keywords'])
$meta['keywords'] = $options['category_keywords'];
if ($options['category_description'])
$meta['description'] = $options['category_description'];
$meta['robots'] = $options['category_index'] != 'default' ? $options['category_index'] : ($options['index_aggregated'] ? 'index' : 'noindex');
$meta['robots'] .= ',' . ($options['category_follow'] != 'default' ? $options['category_follow'] : ($options['follow_aggregated'] ? 'follow' : 'nofollow'));
}
}
else if ($wp_query->query['tag']) {
if (!$wp_query->query_vars['paged'] || ($wp_query->query_vars['paged'] && $options['tag_first'] == 0)) {
if ($options['tag_title'])
$meta['title'] = $options['tag_title'];
if ($options['tag_keywords'])
$meta['keywords'] = $options['tag_keywords'];
if ($options['tag_description'])
$meta['description'] = $options['tag_description'];
$meta['robots'] = $options['tag_index'] != 'default' ? $options['tag_index'] : ($options['index_aggregated'] ? 'index' : 'noindex');
$meta['robots'] .= ',' . ($options['tag_follow'] != 'default' ? $options['tag_follow'] : ($options['follow_aggregated'] ? 'follow' : 'nofollow'));
}
}
else if ($wp_query->query['author_name'] || $wp_query->query['author']) {
if (!$wp_query->query_vars['paged'] || ($wp_query->query_vars['paged'] && $options['author_first'] == 0)) {
if ($options['author_title'])
$meta['title'] = $options['author_title'];
if ($options['author_keywords'])
$meta['keywords'] = $options['author_keywords'];
if ($options['author_description'])
$meta['description'] = $options['author_description'];
$meta['robots'] = $options['author_index'] != 'default' ? $options['author_index'] : ($options['index_aggregated'] ? 'index' : 'noindex');
$meta['robots'] .= ',' . ($options['author_follow'] != 'default' ? $options['author_follow'] : ($options['follow_aggregated'] ? 'follow' : 'nofollow'));
}
}
else if ($wp_query->query['year']) {
if (!$wp_query->query_vars['paged'] || ($wp_query->query_vars['paged'] && $options['archive_first'] == 0)) {
if ($options['archive_title'])
$meta['title'] = $options['archive_title'];
if ($options['archive_keywords'])
$meta['keywords'] = $options['archive_keywords'];
if ($options['archive_description'])
$meta['description'] = $options['archive_description'];
$meta['robots'] = $options['archive_index'] != 'default' ? $options['archive_index'] : ($options['index_aggregated'] ? 'index' : 'noindex');
$meta['robots'] .= ',' . ($options['archive_follow'] != 'default' ? $options['archive_follow'] : ($options['follow_aggregated'] ? 'follow' : 'nofollow'));
}
}
else if ($wp_query->query['s']) {
if (!$wp_query->query_vars['paged'] || ($wp_query->query_vars['paged'] && $options['search_first'] == 0)) {
if ($options['search_title'])
$meta['title'] = $options['search_title'];
if ($options['search_keywords'])
$meta['keywords'] = $options['search_keywords'];
if ($options['search_description'])
$meta['description'] = $options['search_description'];
$meta['robots'] = $options['search_index'] != 'default' ? $options['search_index'] : ($options['index_aggregated'] ? 'index' : 'noindex');
$meta['robots'] .= ',' . ($options['search_follow'] != 'default' ? $options['search_follow'] : ($options['follow_aggregated'] ? 'follow' : 'nofollow'));
}
}
else if (!$wp_query->query_vars['paged'] || ($wp_query->query_vars['paged'] && $options['home_first'] == 0)) {
if ($options['home_title'])
$meta['title'] = $options['home_title'];
if ($options['home_keywords'])
$meta['keywords'] = $options['home_keywords'];
if ($options['home_description'])
$meta['description'] = $options['home_description'];
$meta['robots'] = $options['home_index'] != 'default' ? $options['home_index'] : ($options['index_aggregated'] ? 'index' : 'noindex');
$meta['robots'] .= ',' . ($options['home_follow'] != 'default' ? $options['home_follow'] : ($options['follow_aggregated'] ? 'follow' : 'nofollow'));
}
// replace variables used in meta informations
if ($meta['title']) {
// if we have already integrated pagination in aggregations meta strings, we don't need to add it automatically
$hasPagination = strlen (strstr ($meta['title'], '%pagination%')) > 0 ? TRUE : FALSE;
$meta['title'] = ks_replace_variables ($meta['title']);
}
if ($meta['keywords'])
//$meta['keywords'] = ks_replace_variables ($meta['keywords']);
$meta['keywords'] = preg_replace ('/,+/', ',', preg_replace ('/ *, */', ',', preg_replace ('/ +/', ' ', preg_replace ('/,+/', ',', ks_replace_variables ($meta['keywords'])))));
if ($meta['description'])
$meta['description'] = ks_replace_variables ($meta['description']);
// generate meta data for several content aggregations (category-, tag-, author- and archive-views)
// get language, keywords and descriptions of aggregated posts
$keys = array ();
$descriptions = array ();
// for counting the posts and pages with the same language
$same_language = 1;
for ($i = 0; $i < count ($posts); $i++) {
$k = get_post_meta ($posts[$i]->ID, 'ks_metadata', true);
if ($i == 0)
// let's take the language of the first post
$meta['lang'] = trim ($k['lang']);
else
// is the post or page written in the same language as the first one?
$same_language += trim ($k['lang']) == $meta['lang'] ? 1 : 0;
if ($k['keywords'])
array_push ($keys, explode (',', $k['keywords']));
if ($k['description'])
// ony get the first words from description of each post - they should be the most important ones
array_push ($descriptions, trim (preg_replace ('/^(([^\s]+\s){' . $options['words_from_posts_in_aggregated_description'] . '}).*/', '$1', $k['description'])));
}
// we only set keywords and description if all posts are written in the same language
// to prevent language mixes in meta informations
if ($same_language == count ($posts)) {
// get mixed list of the most important keywords
$j = 0;
$keywords = !$meta['keywords'] ? array () : explode (',', $meta['keywords']);
do {
$pushed = false;
for ($i = 0; $i < count ($keys); $i++)
if (count ($keywords) < $options['max_keywords_count'] && $keys[$i][$j]) {
array_push ($keywords, $keys[$i][$j]);
$pushed = true;
}
$j++;
} while (count ($keywords) < $options['max_keywords_count'] && $pushed);
$meta['keywords'] = implode (',', $keywords);
if (!$meta['description']) {
// generate description-tag from post-descriptions
$description = implode ('...', $descriptions);
if (strlen ($description) > $options['max_description_length'])
$meta['description'] = substr ($description, 0, $options['max_description_length']);
$meta['description'] = substr ($meta['description'], 0, strrpos ($meta['description'], ' '));
}
}
else
// drop language from metadata if posts are in different languages
unset ($meta['lang']);
// set robots-tag as configured
if (!$meta['robots'])
$meta['robots'] = ($options['index_aggregated'] ? 'index' : 'noindex') . ',' . ($options['follow_aggregated'] ? 'follow' : 'nofollow');
// canonical url
$canstruct = array ('type' => 'home');
if (is_category ()) {
$category_info = get_category ($wp_query->query_vars['cat']);
$canstruct = array ('type' => 'category', 'id' => $wp_query->query_vars['cat'], 'name' => $wp_query->query['category_name'] ? $wp_query->query['category_name'] : $category_info->slug);
}
else if ($wp_query->query['tag'])
$canstruct = array ('type' => 'tag', 'name' => $wp_query->query['tag']);
else if ($wp_query->query['author_name'] || $wp_query->query['author']) {
$user_data = get_userdata ($wp_query->query['author']);
$canstruct = array ('type' => 'author', 'id' => $wp_query->query['author'], 'name' => $wp_query->query['author_name'] ? $wp_query->query['author_name'] : $user_data->user_login);
}
else if (($wp_query->query['year'] && $wp_query->query['monthnum'] && $wp_query->query['day']) || strlen ($wp_query->query['m']) == 8)
$canstruct = array ('type' => 'archive', 'year' => $wp_query->query['year'] ? $wp_query->query['year'] : substr ($wp_query->query['m'], 0, 4), 'month' => $wp_query->query['monthnum'] ? $wp_query->query['monthnum'] : substr ($wp_query->query['m'], 4, 2), 'day' => $wp_query->query['day'] ? $wp_query->query['day'] : substr ($wp_query->query['m'], 6, 2));
else if (($wp_query->query['year'] && $wp_query->query['monthnum']) || strlen ($wp_query->query['m']) == 6)
$canstruct = array ('type' => 'archive', 'year' => $wp_query->query['year'] ? $wp_query->query['year'] : substr ($wp_query->query['m'], 0, 4), 'month' => $wp_query->query['monthnum'] ? $wp_query->query['monthnum'] : substr ($wp_query->query['m'], 4, 2));
else if ($wp_query->query['year'] || strlen ($wp_query->query['m']) == 4)
$canstruct = array ('type' => 'archive', 'year' => $wp_query->query['year'] ? $wp_query->query['year'] : substr ($wp_query->query['m'], 0, 4));
// pagination
if ($wp_query->query_vars['paged'])
$canstruct = array_merge ($canstruct, array ('page' => $wp_query->query_vars['paged']));
$meta['canonical'] = ks_canonical ($canstruct);
} else if ($wp_query->post_count == 0) {
// tags, categories and search with no posts
$meta['robots'] = 'noindex,nofollow';
}
// drop old title-tag from output-buffer
// if author has set one for a particular page or post this one will be inserted
// moreover we append the page number if we are not on the first page
if (($meta['title'] || $wp_query->query_vars['paged']) && !$options['testmode'] && $options['serve_title']) {
$buffer = substr (ob_get_contents (), 0, stripos (ob_get_contents (), '
')) . substr (stristr (ob_get_contents (), ' '), 8);
// append page number to the title
if ($wp_query->query_vars['paged']) {
$start = stripos (ob_get_contents (), '') + 7;
$end = stripos (ob_get_contents (), ' ');
if (!$meta['title'])
$meta['title'] = substr (ob_get_contents (), $start, ($end - $start));
// if title in aggregations has no pagination we add it automatically
if (!$hasPagination)
$meta['title'] .= ' ' . __('– page', 'multi-keyword-statistics') . ' ' . $wp_query->query_vars['paged'];
}
ob_clean ();
ob_start ();
echo $buffer;
}
if ($meta['title'] && ($options['sitewide_title_predecessor'] || $options['sitewide_title_successor']))
$meta['title'] = ks_replace_variables ($options['sitewide_title_predecessor']) . $meta['title'] . ks_replace_variables ($options['sitewide_title_successor']);
if ($options['sitewide_keywords_predecessor'] && $meta['keywords']) {
if (!is_page () && !is_single ()) {
$kc = explode (',', $options['sitewide_keywords_predecessor']);
$keywords = array_merge ($kc, array_splice (explode (',', $meta['keywords']), 0, -count ($kc)));
$meta['keywords'] = implode (',', $keywords);
}
else
$meta['keywords'] = $options['sitewide_keywords_predecessor'] . ',' . $meta['keywords'];
}
if ($options['sitewide_keywords_successor'] && $meta['keywords']) {
if (!is_page () && !is_single ()) {
$kc = explode (',', $options['sitewide_keywords_successor']);
$keywords = array_merge (array_splice (explode (',', $meta['keywords']), 0, -count ($kc)), $kc);
$meta['keywords'] = implode (',', $keywords);
}
else
$meta['keywords'] = $meta['keywords'] . ',' . $options['sitewide_keywords_successor'];
}
if ($meta['description'] && ($options['sitewide_description_predecessor'] || $options['sitewide_description_successor']))
$meta['description'] = ks_replace_variables ($options['sitewide_description_predecessor']) . $meta['description'] . ks_replace_variables ($options['sitewide_description_successor']);
// Append sitewide settings for ODP, Yahoo! Directory and archiving
// If robots is not already definded in the meta-array we should do this
// to prevent problems with string assignment operator.
if (!$meta['robots'])
$meta['robots'] = '';
// in some cases PHP seems to have a problem with using concatenated assignment operators on associative arrays
$meta['robots'] = $meta['robots'] . ($options['noodp'] ? (strlen (trim ($meta['robots'])) > 0 ? ',' : '') . 'noodp' : '');
$meta['robots'] = $meta['robots'] . ($options['noarchive'] ? (strlen (trim ($meta['robots'])) > 0 ? ',' : '') . 'noarchive' : '');
$meta['robots'] = $meta['robots'] . ($options['noydir'] ? (strlen (trim ($meta['robots'])) > 0 ? ',' : '') . 'noydir' : '');
echo ($options['serve_title'] == 1 && strlen ($meta['title']) > 0 ? '' . $meta['title'] . ' ' . "\n" : '') .
($options['serve_meta_keywords'] == 1 && strlen (trim ($meta['keywords'])) > 0 ? ' 0 && $options['set_language_meta'] == 1 ? ' lang="' . $meta['lang'] . '"' : '') . ' content="' . $meta['keywords'] . '" />' . "\n" : '') .
($options['serve_meta_description'] == 1 && strlen (trim ($meta['description'])) > 0 ? ' 0 && $options['set_language_meta'] == 1 ? ' lang="' . $meta['lang'] . '"' : '') . ' content="' . $meta['description'] . '" />' . "\n" : '') .
($options['set_language_meta'] == 1 ? (strlen ($meta['lang']) > 0 ? ' ' . "\n" . ' ' . "\n" : '') : '').
($options['serve_meta_robots'] == 1 && strlen (trim ($meta['robots'])) > 0 ? ' ' . "\n" : '') .
($options['serve_meta_canonical'] == 1 && strlen ($meta['canonical']) > 0 ? ' ' . "\n" : '') .
($options['testmode'] ? '' : '\n";
}
add_action ('wp_head', 'keyword_statistics_add_meta_tags');
// Remove action for canonical url generation added in WP versions 2.9+
// The plugin does this not only for pages and posts but also for all kinds of content aggregations
remove_action ( 'wp_head', 'rel_canonical' );
// update the metadata
function keyword_statistics_update_metadata () {
global $post;
// don't change meta informations if we are autosaving
if (!isset ($_POST['autosave'])) {
// in quick edit mode we have to leave already defined metadata (if there are some)
if (!isset ($_POST['kslang']))
// let's get out here without doing anything with meta informations
return;
if (!wp_verify_nonce ($_POST['ks_update_meta_nonce'], 'ks_update_meta_nonce'))
die (__('Nonce verification failed:', 'multi-keyword-statistics') . ' ' . __('Error while updating the meta informations for the post!', 'multi-keyword-statistics'));
$robots = (!isset ($_POST['ksrobotindex']) ? 'noindex' : ($_POST['ksrobotindex'] == 'index' || $_POST['ksrobotindex'] == 'ks_ri' ? 'index' : 'noindex')) . ',' .
(!isset ($_POST['ksrobotfollow']) ? 'nofollow' : ($_POST['ksrobotfollow'] == 'follow' || $_POST['ksrobotfollow'] == 'ks_rf' ? 'follow' : 'nofollow'));
//if (!function_exists ('apply_filters'))
$meta = array ('lang' => trim (htmlspecialchars (strip_tags ($_POST['kslang']))),
'keywords' => preg_replace ('/,+/', ',', preg_replace ('/ *, */', ',', preg_replace ('/ +/', ' ', preg_replace ('/,+/', ',', trim (htmlspecialchars (strip_tags ($_POST['kskeywords'])), ' ,'))))),
'keywords_autoupdate' => $_POST['keywords_autoupdate'] ? 1 : 0,
'description' => trim (htmlspecialchars (strip_tags ($_POST['ksdescription']))),
'description_autoupdate' => $_POST['description_autoupdate'] ? 1 : 0,
'title' => trim (htmlspecialchars (strip_tags ($_POST['kstitle']))),
'robots' => $robots);
/*else
max length, if autoupdate is activated
$meta = array ('lang' => $_POST['kslang'],
'keywords' => apply_filters ('the_title_rss', $_POST['kskeywords']),
'keywords_autoupdate' => $_POST['keywords_autoupdate'],
'description' => apply_filters ('the_title_rss', $_POST['ksdescription']),
'description_autoupdate' => $_POST['description_autoupdate'],
'title' => apply_filters ('the_title_rss', $_POST['kstitle']),
'robots' => $robots);*/
add_post_meta ($_POST['post_ID'], 'ks_metadata', $meta, true) or update_post_meta ($_POST['post_ID'], 'ks_metadata', $meta);
}
}
add_action ('save_post', 'keyword_statistics_update_metadata');
// Plugin options
function init_keyword_statistics_settings () {
global $ks_plugin_version;
if (function_exists ('register_setting')) {
// for WP 2.7+
if (!get_option('keyword_statistics_configuration')) {
// set default or import configuration
$default_configuration = array (
'version' => get_option('ks_version') ? get_option('ks_version') : $ks_plugin_version,
'testmode' => get_option('ks_testmode') ? get_option('ks_testmode') : 0,
'default_language' => get_option('ks_default_language') ? get_option('ks_default_language') : 'en',
'set_language_meta' => get_option('ks_set_language_meta') ? get_option('ks_set_language_meta') : 0,
'filter_stopwords' => get_option('ks_filter_stopwords') ? get_option('ks_filter_stopwords') : 1,
'max_list_items' => get_option('ks_max_list_items') ? get_option('ks_max_list_items') : 5,
'automatic_update' => get_option('ks_automatic_update') ? get_option('ks_automatic_update') : 1,
'update_interval' => get_option('ks_update_interval') ? get_option('ks_update_interval') : 5,
'2word_phrases' => get_option('ks_2word_phrases') ? get_option('ks_2word_phrases') : 1,
'3word_phrases' => get_option('ks_3word_phrases') ? get_option('ks_3word_phrases') : 1,
'meta_keywords_count' => get_option('ks_meta_keywords_count') ? get_option('ks_meta_keywords_count') : 8,
'max_keywords_count' => get_option('ks_max_keywords_count') ? get_option('ks_max_keywords_count') : 12,
'max_keywords_length' => get_option('ks_max_keywords_length') ? get_option('ks_keywords_length') : 80,
'index_aggregated' => get_option('ks_index_aggregated') ? get_option('ks_index_aggregated') : 0,
'follow_aggregated' => get_option('ks_follow_aggregated') ? get_option('ks_follow_aggregated') : 1,
'noodp' => get_option('ks_noodp') ? get_option('ks_noodp') : 1,
'noydir' => get_option('ks_noydir') ? get_option('ks_noydir') : 1,
'noarchive' => get_option('ks_noarchive') ? get_option('ks_noarchive') : 1,
'dont_serve_metadata' => get_option('ks_dont_serve_metadata') ? get_option('ks_dont_serve_metadata') : 0,
'serve_title' => get_option('ks_serve_title') ? get_option('ks_serve_title') : 1,
'serve_meta_robots' => get_option('ks_serve_meta_robots') ? get_option('ks_serve_meta_robots') : 1,
'serve_meta_keywords' => get_option('ks_serve_meta_keywords') ? get_option('ks_serve_meta_keywords') : 1,
'serve_meta_description' => get_option('ks_serve_meta_description') ? get_option('ks_serve_meta_description') : 1,
'serve_meta_canonical' => get_option('ks_serve_meta_canonical') ? get_option('ks_serve_meta_canonical') : 1,
'words_from_posts_in_aggregated_description' => get_option('ks_words_from_posts_in_aggregated_description') ? get_option('ks_words_from_posts_in_aggregated_description') : 4,
'max_title_length' => get_option('ks_max_title_length') ? get_option('ks_max_title_length') : 60,
'min_description_length' => get_option('ks_min_description_length') ? get_option('ks_min_description_length') : 80,
'max_description_length' => get_option('ks_max_description_length') ? get_option('ks_max_description_length') : 160,
'automatic_meta_data_update' => get_option('ks_automatic_meta_data_update') ? get_option('ks_automatic_meta_data_update') : 1,
'min_words' => get_option('ks_min_words') ? get_option('ks_min_words') : 50,
'hide_fields_authors_cant_change' => get_option('ks_hide_fields_authors_cant_change') ? get_option('ks_hide_fields_authors_cant_change') : 1,
'hide_fields_authors_cant_change_from_admin' => get_option('ks_hide_fields_authors_cant_change_from_admin') ? get_option('ks_hide_fields_authors_cant_change_from_admin') : 0,
'authors_can_change_content_language' => get_option('ks_authors_can_change_content_language') ? get_option('ks_authors_can_change_content_language') : 0,
'authors_can_disable_stopword_filter' => get_option('ks_authors_can_disable_stopword_filter') ? get_option('ks_authors_can_disable_stopword_filter') : 0,
'authors_can_set_individual_title' => get_option('ks_authors_can_set_individual_title') ? get_option('ks_authors_can_set_individual_title') : 1,
'authors_can_edit_keywords' => get_option('ks_authors_can_edit_keywords') ? get_option('ks_authors_can_edit_keywords') : 0,
'authors_can_edit_description' => get_option('ks_authors_can_edit_description') ? get_option('ks_authors_can_edit_description') : 0,
'authors_can_control_robots' => get_option('ks_authors_can_control_robots') ? get_option('ks_authors_can_control_robots') : 0,
'home_first' => get_option('ks_home_first') ? get_option('ks_home_first') : 0,
'category_first' => get_option('ks_category_first') ? get_option('ks_category_first') : 0,
'tag_first' => get_option('ks_tag_first') ? get_option('ks_tag_first') : 0,
'archive_first' => get_option('ks_archive_first') ? get_option('ks_archive_first') : 0,
'author_first' => get_option('ks_author_first') ? get_option('ks_author_first') : 0,
'search_first' => get_option('ks_search_first') ? get_option('ks_search_first') : 0,
'home_index' => get_option('ks_home_index') ? get_option('ks_home_index') : 'default',
'category_index' => get_option('ks_category_index') ? get_option('ks_category_index') : 'default',
'tag_index' => get_option('ks_tag_index') ? get_option('ks_tag_index') : 'default',
'archive_index' => get_option('ks_archive_index') ? get_option('ks_archive_index') : 'default',
'author_index' => get_option('ks_author_index') ? get_option('ks_author_index') : 'default',
'search_index' => get_option('ks_search_index') ? get_option('ks_search_index') : 'default',
'home_follow' => get_option('ks_home_follow') ? get_option('ks_home_follow') : 'default',
'category_follow' => get_option('ks_category_follow') ? get_option('ks_category_follow') : 'default',
'tag_follow' => get_option('ks_tag_follow') ? get_option('ks_tag_follow') : 'default',
'archive_follow' => get_option('ks_archive_follow') ? get_option('ks_archive_follow') : 'default',
'author_follow' => get_option('ks_author_follow') ? get_option('ks_author_follow') : 'default',
'search_follow' => get_option('ks_search_follow') ? get_option('ks_search_follow') : 'default'
);
add_option ('keyword_statistics_configuration', $default_configuration);
// drop older configurations
delete_option ('ks_version');
delete_option ('ks_testmode');
delete_option ('ks_default_language');
delete_option ('ks_set_language_meta');
delete_option ('ks_filter_stopwords');
delete_option ('ks_max_list_items');
delete_option ('ks_automatic_update');
delete_option ('ks_update_interval');
delete_option ('ks_2word_phrases');
delete_option ('ks_3word_phrases');
delete_option ('ks_meta_keywords_count');
delete_option ('ks_max_keywords_count');
delete_option ('ks_keywords_length');
delete_option ('ks_index_aggregated');
delete_option ('ks_follow_aggregated');
delete_option ('ks_noodp');
delete_option ('ks_noydir');
delete_option ('ks_noarchive');
delete_option ('ks_dont_serve_metadata');
delete_option ('ks_serve_title');
delete_option ('ks_serve_meta_robots');
delete_option ('ks_serve_meta_keywords');
delete_option ('ks_serve_meta_description');
delete_option ('ks_serve_meta_canonical');
delete_option ('ks_words_from_posts_in_aggregated_description');
delete_option ('ks_max_title_length');
delete_option ('ks_min_description_length');
delete_option ('ks_max_description_length');
delete_option ('ks_automatic_meta_data_update');
delete_option ('ks_min_words');
delete_option ('ks_hide_fields_authors_cant_change');
delete_option ('ks_hide_fields_authors_cant_change_from_admin');
delete_option ('ks_authors_can_change_content_language');
delete_option ('ks_authors_can_disable_stopword_filter');
delete_option ('ks_authors_can_set_individual_title');
delete_option ('ks_authors_can_edit_keywords');
delete_option ('ks_authors_can_edit_description');
delete_option ('ks_authors_can_control_robots');
delete_option ('ks_home_first');
delete_option ('ks_category_first');
delete_option ('ks_tag_first');
delete_option ('ks_archive_first');
delete_option ('ks_author_first');
delete_option ('ks_search_first');
delete_option ('ks_home_index');
delete_option ('ks_category_index');
delete_option ('ks_tag_index');
delete_option ('ks_archive_index');
delete_option ('ks_author_index');
delete_option ('ks_search_index');
delete_option ('ks_home_follow');
delete_option ('ks_category_follow');
delete_option ('ks_tag_follow');
delete_option ('ks_archive_follow');
delete_option ('ks_author_follow');
delete_option ('ks_search_follow');
}
register_setting ('plugin_options', 'keyword_statistics_configuration');
}
else {
// and for older versions
if (!get_option('ks_default_language')) {
add_option ('ks_version', $ks_plugin_version);
add_option ('ks_testmode', 0);
add_option ('ks_default_language', 'en');
add_option ('ks_set_language_meta', 0);
add_option ('ks_filter_stopwords', 1);
add_option ('ks_max_list_items', 5);
add_option ('ks_automatic_update', 1);
add_option ('ks_update_interval', 5);
add_option ('ks_2word_phrases', 1);
add_option ('ks_3word_phrases', 1);
add_option ('ks_meta_keywords_count', 8);
add_option ('ks_max_keywords_count', 12);
add_option ('ks_keywords_length', 80);
add_option ('ks_index_aggregated', 0);
add_option ('ks_follow_aggregated', 1);
add_option ('ks_noodp', 1);
add_option ('ks_noydir', 1);
add_option ('ks_noarchive', 1);
add_option ('ks_dont_serve_metadata', 0);
add_option ('ks_serve_title', 1);
add_option ('ks_serve_meta_robots', 1);
add_option ('ks_serve_meta_keywords', 1);
add_option ('ks_serve_meta_description', 1);
add_option ('ks_serve_meta_canonical', 1);
add_option ('ks_words_from_posts_in_aggregated_description', 4);
add_option ('ks_max_title_length', 60);
add_option ('ks_min_description_length', 80);
add_option ('ks_max_description_length', 160);
add_option ('ks_automatic_meta_data_update', 1);
add_option ('ks_hide_fields_authors_cant_change', 1);
add_option ('ks_hide_fields_authors_cant_change_from_admin', 0);
add_option ('ks_min_words', 50);
add_option ('ks_authors_can_change_content_language', 0);
add_option ('ks_authors_can_disable_stopword_filter', 0);
add_option ('ks_authors_can_set_individual_title', 1);
add_option ('ks_authors_can_edit_keywords', 0);
add_option ('ks_authors_can_edit_description', 0);
add_option ('ks_authors_can_control_robots', 0);
add_option ('ks_home_first', 0);
add_option ('ks_category_first', 0);
add_option ('ks_tag_first', 0);
add_option ('ks_archive_first', 0);
add_option ('ks_author_first', 0);
add_option ('ks_search_first', 0);
add_option ('ks_home_index', 'default');
add_option ('ks_category_index', 'default');
add_option ('ks_tag_index', 'default');
add_option ('ks_archive_index', 'default');
add_option ('ks_author_index', 'default');
add_option ('ks_search_index', 'default');
add_option ('ks_home_follow', 'default');
add_option ('ks_category_follow', 'default');
add_option ('ks_tag_follow', 'default');
add_option ('ks_archive_follow', 'default');
add_option ('ks_author_follow', 'default');
add_option ('ks_search_follow', 'default');
}
}
// add new options to the configuration without changing the way the plugin acted in the past
$options = keyword_statistics_get_plugin_configuration ();
// new option in 1.2.5
if (!$options['min_words'])
if (function_exists ('register_setting')) {
$options['min_words'] = 50;
update_option ('keyword_statistics_configuration', $options);
}
else
add_option ('ks_min_words', 50);
// new option in 1.2.7
if (substr ($options['version'], 0, 5) < '1.2.7')
if (function_exists ('register_setting')) {
$options['serve_meta_robots'] = 1;
update_option ('keyword_statistics_configuration', $options);
}
else
add_option ('ks_serve_meta_robots', 1);
// new option in 1.2.9
if (substr ($options['version'], 0, 5) < '1.2.9')
if (function_exists ('register_setting')) {
$options['dont_serve_metadata'] = 0;
update_option ('keyword_statistics_configuration', $options);
}
else
add_option ('ks_dont_serve_metadata', 0);
// new option in 1.3.1
if (substr ($options['version'], 0, 5) < '1.3.1')
if (function_exists ('register_setting')) {
$options['testmode'] = 0;
update_option ('keyword_statistics_configuration', $options);
}
else
add_option ('ks_testmode', 0);
// new options in 1.3.5
if (substr ($options['version'], 0, 5) < '1.3.5')
if (function_exists ('register_setting')) {
$options['serve_meta_keywords'] = 1;
$options['serve_meta_description'] = 1;
update_option ('keyword_statistics_configuration', $options);
}
else {
add_option ('ks_serve_meta_keywords', 1);
add_option ('ks_serve_meta_description', 1);
}
// new options in 1.3.7
if (substr ($options['version'], 0, 5) < '1.3.7')
if (function_exists ('register_setting')) {
$options['serve_meta_canonical'] = 1;
update_option ('keyword_statistics_configuration', $options);
}
else
add_option ('ks_serve_meta_canonical', 1);
// new options in 1.3.9
if (substr ($options['version'], 0, 5) < '1.3.9')
if (function_exists ('register_setting')) {
$options['serve_title'] = 1;
update_option ('keyword_statistics_configuration', $options);
}
else
add_option ('ks_serve_title', 1);
// new option in 1.4.3
if (!$options['max_title_length'])
if (function_exists ('register_setting')) {
$options['max_title_length'] = 60;
update_option ('keyword_statistics_configuration', $options);
}
else
add_option ('ks_max_title_length', 60);
// new option in 1.4.5
if (!$options['max_keywords_length'])
if (function_exists ('register_setting')) {
$options['max_keywords_count'] = 12;
$options['max_keywords_length'] = 80;
update_option ('keyword_statistics_configuration', $options);
}
else {
add_option ('ks_max_keywords_count', 12);
add_option ('ks_max_keywords_length', 80);
}
// new options since 1.5.8
if (!isset ($options['home_index'])) {
$options['home_first'] = $options['category_first'] = $options['tag_first'] = $options['archive_first'] = $options['author_first'] = $options['search_first'] = 0;
$options['home_index'] = $options['category_index'] = $options['tag_index'] = $options['archive_index'] = $options['author_index'] = $options['search_index'] = 'default';
$options['home_follow'] = $options['category_follow'] = $options['tag_follow'] = $options['archive_follow'] = $options['author_follow'] = $options['search_follow'] = 'default';
keyword_statistics_set_plugin_configuration ($options);
}
// initialize the metadata for content aggregations integrated in 1.5.8
if (!isset ($options['home_title'])) {
$options['home_title'] = $options['category_title'] = $options['tag_title'] = $options['archive_title'] = $options['author_title'] = $options['search_title'] = '';
$options['home_description'] = $options['category_description'] = $options['tag_description'] = $options['archive_description'] = $options['author_description'] = $options['search_description'] = '';
$options['home_keywords'] = $options['category_keywords'] = $options['tag_keywords'] = $options['archive_keywords'] = $options['author_keywords'] = $options['search_keywords'] = '';
keyword_statistics_set_plugin_configuration ($options);
}
// since 1.6.1: initialization of new sitewide meta informations
if (!isset ($options['sitewide_title_predecessor'])) {
$options['sitewide_title_predecessor'] = $options['sitewide_title_successor'] = '';
$options['sitewide_keywords_predecessor'] = $options['sitewide_keywords_successor'] = '';
$options['sitewide_description_predecessor'] = $options['sitewide_description_successor'] = '';
keyword_statistics_set_plugin_configuration ($options);
}
// if there is still no version information or we are running a new one we set the current
if (!isset ($options['version']) || $options['version'] != $ks_plugin_version)
if (function_exists ('register_setting')) {
$options['version'] = $ks_plugin_version;
update_option ('keyword_statistics_configuration', $options);
}
else
add_option ('ks_version', $ks_plugin_version);
}
if (is_admin ()) {
add_action ('admin_init', 'init_keyword_statistics_settings');
}
function is_author_not_admin () {
global $current_user;
$rval = isset ($current_user->caps['author']) && $current_user->caps['author'] == 1 && (!isset ($current_user->caps['administrator']) || $current_user->caps['administrator'] != 1);
return $rval;
}
function is_contributor () {
global $current_user;
return isset ($current_user->caps['contributor']) && $current_user->caps['contributor'] == 1 && (!isset ($current_user->caps['administrator']) || $current_user->caps['administrator'] != 1);
}
// Plugin Output
function post_keyword_statistics () {
global $post;
$meta = get_post_meta ($post->ID, 'ks_metadata', true);
$options = keyword_statistics_get_plugin_configuration (); ?>
var ks_updateInterval = window.setInterval (\'updateTextInfo()\', ' . $options['update_interval'] . '000);' ?>
/>
' .
'' .
'
' .
__('Multi Keyword Statistics', 'multi-keyword-statistics') . " " .
'';
post_keyword_statistics ();
echo "
";
}
function keyword_statistics () {
if (function_exists ('add_meta_box')) {
// only works with WP 2.5+
add_meta_box ('keywordstatbox', __('Multi Keyword Statistics', 'multi-keyword-statistics'), 'post_keyword_statistics', 'post', 'normal', 'core');
add_meta_box ('keywordstatbox', __('Multi Keyword Statistics', 'multi-keyword-statistics'), 'post_keyword_statistics', 'page', 'normal', 'core');
} else {
// older versions
add_action ('dbx_post_advanced', 'post_keyword_statistics_div');
add_action ('dbx_page_advanced', 'post_keyword_statistics_div');
}
}
add_action ('admin_menu', 'keyword_statistics');
// add pages for plugins additional options
function ks_additional_options_menu () {
// create a new submenu for the different options
add_menu_page (__('Multi Keyword Statistics', 'multi-keyword-statistics'), __('Multi Keyword Statistics', 'multi-keyword-statistics'), 'administrator', 'ks-additional-menu');
// sitewide predecessors and successors for title, description and keywords
add_submenu_page ('ks-additional-menu', __('Sitewide Meta', 'multi-keyword-statistics'), __('Sitewide Meta', 'multi-keyword-statistics'), 'administrator', 'ks-additional-menu', 'ks_additional_options_sitewide_meta');
// metadata for aggregations
add_submenu_page ('ks-additional-menu', __('Aggregations Meta', 'multi-keyword-statistics'), __('Aggregations Meta', 'multi-keyword-statistics'), 'administrator', 'ks-additional-menu-aggregation-meta', 'ks_additional_options_aggregation_meta');
// configuration for serving metadata
add_submenu_page ('ks-additional-menu', __('Metadata Delivery', 'multi-keyword-statistics'), __('Metadata Delivery', 'multi-keyword-statistics'), 'administrator', 'ks-additional-menu-metadata', 'ks_additional_options_metadata');
// automatic metadata generation
add_submenu_page ('ks-additional-menu', __('Metadata Generation', 'multi-keyword-statistics'), __('Metadata Generation', 'multi-keyword-statistics'), 'administrator', 'ks-additional-menu-metadata-generation', 'ks_additional_options_metadata_generation');
// sitewide default settings for controlling robots
add_submenu_page ('ks-additional-menu', __('Robots Default', 'multi-keyword-statistics'), __('Robots Default', 'multi-keyword-statistics'), 'administrator', 'ks-additional-menu-robots', 'ks_additional_options_robots');
// keyword density checker
add_submenu_page ('ks-additional-menu', __('Keyword Density Checker', 'multi-keyword-statistics'), __('Keyword Density Checker', 'multi-keyword-statistics'), 'administrator', 'ks-additional-menu-keyword-density-checker', 'ks_additional_options_keyword_density_checker');
// settings for displaying or allowing authors and contributors to change various fields
add_submenu_page ('ks-additional-menu', __('Authors', 'multi-keyword-statistics'), __('Authors', 'multi-keyword-statistics'), 'administrator', 'ks-additional-menu-authors', 'ks_additional_options_authors');
}
// integrate additionals options menu
add_action('admin_menu', 'ks_additional_options_menu');
// sitewide predecessor and successor for titles, keywords and descriptioms
function ks_additional_options_sitewide_meta () {
$types = array ('title' => __('titles', 'multi-keyword-statistics'),
'keywords' => __('keywords', 'multi-keyword-statistics'),
'description' => __('descriptions', 'multi-keyword-statistics'));
$options = keyword_statistics_get_plugin_configuration ();
if (isset ($_POST['ks_update_options']) && $_POST['ks_update_options'] == 1) {
if (!wp_verify_nonce ($_POST['ks_sitewide_meta_nonce'], 'ks_sitewide_meta_nonce')) {
$err = 1;
$errmsg = __('Nonce verification failed:', 'multi-keyword-statistics') . ' ' . __('Error while saving sitewide meta informations!', 'multi-keyword-statistics');
}
else {
// check values
foreach ($_POST as $key => $value) {
if (preg_match ('/^ks_(' . implode ('|', array_keys ($types)) . ')_(predecessor|successor)$/', $key, $matches)) {
$value = stripslashes ($value);
// fields we can't replace should be removed
$value = preg_replace ('/%(category_name|tag_name|author_name|archive_date|search_query|pagination)%/', '', $value);
switch ($matches[1]) {
case 'title':
if (strlen ($value) > $options['max_title_length']) {
$err = 1;
$errmsg = __('Too many characters used at the title-tag! See configuration at', 'multi-keyword-statistics');
$errmsg .= ' ' . __('Metadata Generation', 'multi-keyword-statistics') . ' . ';
$errmsg .= __('There you can define the maximum number of characters allowed for the title-tag.', 'multi-keyword-statistics');
}
break;
case 'keywords':
// trim whitespaces and not needed commas
$value = trim (preg_replace ('/[,]+/', ',', $value), ', ');
if (count (explode (',', $value)) > intval ($options['max_keywords_count']) || strlen ($value) > $options['max_keywords_length']) {
$err = 1;
$errmsg = __('Too many characters and/or keywords/phrases used at the keywords tag! At', 'multi-keyword-statistics');
$errmsg .= ' ' . __('Metadata Generation', 'multi-keyword-statistics') . ' ';
$errmsg .= __('you can change the configuration options.', 'multi-keyword-statistics');
}
break;
case 'description':
if (strlen ($value) > $options['max_description_length']) {
$err = 1;
$errmsg = __('The description you entered is too long. Have a look at', 'multi-keyword-statistics');
$errmsg .= ' ' . __('Metadata Generation', 'multi-keyword-statistics') . ' ';
$errmsg .= __('if you want to change the maximum number of characters for the description fields.', 'multi-keyword-statistics');
}
break;
}
// update value in options array
$options['sitewide_' . $matches[1] . '_' . $matches[2]] = htmlspecialchars (strip_tags ($value));
}
}
}
// show status message
if (!isset ($err)) {
// update options in database if there was no input error
keyword_statistics_set_plugin_configuration ($options);
?>
__('home', 'multi-keyword-statistics'),
'category' => __('categories', 'multi-keyword-statistics'),
'tag' => __('tags', 'multi-keyword-statistics'),
'archive' => __('archives', 'multi-keyword-statistics'),
'author' => __('authors', 'multi-keyword-statistics'),
'search' => __('search results', 'multi-keyword-statistics'));
$options = keyword_statistics_get_plugin_configuration ();
if (isset ($_POST['ks_update_options']) && $_POST['ks_update_options'] == 1) {
if (!wp_verify_nonce ($_POST['ks_aggregation_meta_nonce'], 'ks_aggregation_meta_nonce')) {
$err = 1;
$errmsg = __('Nonce verification failed:', 'multi-keyword-statistics') . ' ' . __('Error while attempting to save aggregations meta information!', 'multi-keyword-statistics');
}
else {
foreach (array_keys ($aggregations) as $key) {
$options[$key . '_first'] = 0;
$options[$key . '_index'] = $options[$key . '_follow'] = 'default';
}
// check posted options
foreach ($_POST as $key => $value) {
if (preg_match ('/^ks_(' . implode ('|', array_keys ($aggregations)) . ')_(title|keywords|description|index|follow|first)$/', $key, $matches)) {
$value = stripslashes ($value);
switch ($matches[2]) {
case 'title':
$cvalue = $options['sitewide_title_predecessor'] . $value . $options['sitewide_title_successor'];
if (strlen ($cvalue) > $options['max_title_length']) {
$err = 1;
$errmsg = __('At section', 'multi-keyword-statistics') . ' "' . __('Metadata for', 'multi-keyword-statistics') . ' ' . __($aggregations[$matches[1]], 'multi-keyword-statistics') . '": ' . __('The title is containing too many characters!', 'multi-keyword-statistics');
$errmsg .= ' ' . __('The options for setting the maximum length of this field you\'ll find at', 'multi-keyword-statistics');
$errmsg .= ' ' . __('Metadata Generation', 'multi-keyword-statistics') . ' .';
}
break;
case 'keywords':
// trim whitespaces and not needed commas
$value = trim (preg_replace ('/[,]+/', ',', $value), ', ');
$cvalue = (strlen ($options['sitewide_keywords_predecessor']) != 0 ? $options['sitewide_keywords_predecessor'] . ',' : '') . $value . (strlen ($options['sitewide_keywords_successor']) != 0 ? ',' . $options['sitewide_keywords_successor'] : '');
if (count (explode (',', $cvalue)) > intval ($options['max_keywords_count']) || strlen ($cvalue) > $options['max_keywords_length']) {
$err = 1;
$errmsg = __('At section', 'multi-keyword-statistics') . ' "' . __('Metadata for', 'multi-keyword-statistics') . ' ' . __($aggregations[$matches[1]], 'multi-keyword-statistics') . '": ' . __('Keywords field is containing too many characters or too many keywords/phrases are included!', 'multi-keyword-statistics');
$errmsg .= ' ' . __('You can change these settings at', 'multi-keyword-statistics');
$errmsg .= ' ' . __('Metadata Generation', 'multi-keyword-statistics') . ' .';
}
break;
case 'description':
$cvalue = $options['sitewide_description_predecessor'] . $value . $options['sitewide_description_successor'];
if (strlen ($cvalue) > $options['max_description_length']) {
$err = 1;
$errmsg = __('At section', 'multi-keyword-statistics') . ' "' . __('Metadata for', 'multi-keyword-statistics') . ' ' . __($aggregations[$matches[1]], 'multi-keyword-statistics') . '": ' . __('The description is containing too many characters!', 'multi-keyword-statistics');
$errmsg .= ' ' . __('The options for setting the maximum length of this field you\'ll find at', 'multi-keyword-statistics');
$errmsg .= ' ' . __('Metadata Generation', 'multi-keyword-statistics') . ' .';
}
break;
case 'index':
case 'follow':
case 'first':
break;
}
// update value in options array
$options[$matches[1] . '_' . $matches[2]] = htmlspecialchars (strip_tags ($value));
}
}
}
// show status message
if (!isset ($err)) {
// update options in database if there was no input error
keyword_statistics_set_plugin_configuration ($options); ?>
For Instructions Visit:Plugin Page
%blogname%
any of the fields.', 'multi-keyword-statistics') ?>
%siteurl%
any of the fields above.', 'multi-keyword-statistics') ?>
%category_name%
'count', 'number' => 1)); if (is_array ($categories) && count ($categories) > 0) $var_category = ks_replace_variables ('%category_name%', array ('category_name' => $categories[key ($categories)]->name)); else $var_category = __('No categories assigned!', 'multi-keyword-statistics'); echo $var_category ?>
category meta fields.', 'multi-keyword-statistics') ?>
%tag_name%
'count', 'number' => 1)); if (is_array ($tags) && count ($tags) > 0) $var_tag = ks_replace_variables ('%tag_name%', array ('tag_name' => $tags[key ($tags)]->name)); else $var_tag = __('No tags assigned!', 'multi-keyword-statistics'); echo $var_tag ?>
tag views.', 'multi-keyword-statistics') ?>
%author_name%
'Will Writer')); echo $var_author ?>
author meta definitions.', 'multi-keyword-statistics') ?>
%archive_date%
'20100226')); echo $var_archive ?>
archive meta definitions and will be replaced only on archive-views of your blog.', 'multi-keyword-statistics') ?>
%search_query%
__('how to use variables', 'multi-keyword-statistics'))); echo $var_search_query ?>
search results.', 'multi-keyword-statistics') ?>
%pagination%
3)); echo $var_pagination ?>
any field above.', 'multi-keyword-statistics') ?>
$value) {
switch ($key) {
case 'ks_authors_can_change_content_language':
$options['authors_can_change_content_language'] = 1;
break;
case 'ks_authors_can_disable_stopword_filter':
$options['authors_can_disable_stopword_filter'] = 1;
break;
case 'ks_authors_can_set_individual_title':
$options['authors_can_set_individual_title'] = 1;
break;
case 'ks_authors_can_edit_keywords':
$options['authors_can_edit_keywords'] = 1;
break;
case 'ks_authors_can_edit_description':
$options['authors_can_edit_description'] = 1;
break;
case 'ks_authors_can_control_robots':
$options['authors_can_control_robots'] = 1;
break;
case 'ks_hide_fields_authors_cant_change':
$options['hide_fields_authors_cant_change'] = 1;
break;
case 'ks_hide_fields_authors_cant_change_from_admin':
$options['hide_fields_authors_cant_change_from_admin'] = 1;
break;
}
}
}
// show status message
if (!isset ($err)) {
// update options in database if there was no input error
keyword_statistics_set_plugin_configuration ($options);
?>
$value) {
switch ($key) {
case 'ks_noodp':
$options['noodp'] = 1;
break;
case 'ks_noydir':
$options['noydir'] = 1;
break;
case 'ks_noarchive':
$options['noarchive'] = 1;
break;
case 'ks_index_aggregated':
$options['index_aggregated'] = 1;
break;
case 'ks_follow_aggregated':
$options['follow_aggregated'] = 1;
break;
}
}
}
// show status message
if (!isset ($err)) {
// update options in database if there was no input error
keyword_statistics_set_plugin_configuration ($options);
?>
$value) {
switch ($key) {
case 'ks_serve_title':
$options['serve_title'] = 1;
break;
case 'ks_serve_meta_robots':
$options['serve_meta_robots'] = 1;
break;
case 'ks_serve_meta_keywords':
$options['serve_meta_keywords'] = 1;
break;
case 'ks_serve_meta_description':
$options['serve_meta_description'] = 1;
break;
case 'ks_serve_meta_canonical':
$options['serve_meta_canonical'] = 1;
break;
case 'ks_dont_serve_metadata':
$options['dont_serve_metadata'] = 1;
break;
case 'ks_testmode':
$options['testmode'] = 1;
break;
}
}
}
// show status message
if (!isset ($err)) {
// update options in database if there was no input error
keyword_statistics_set_plugin_configuration ($options);
?>
$value) {
switch ($key) {
case 'ks_set_language_meta':
$options['set_language_meta'] = 1;
break;
case 'ks_filter_stopwords':
$options['filter_stopwords'] = 1;
break;
case 'ks_automatic_update':
$options['automatic_update'] = 1;
break;
case 'ks_2word_phrases':
$options['2word_phrases'] = 1;
break;
case 'ks_3word_phrases':
$options['3word_phrases'] = 1;
break;
case 'ks_max_list_items':
case 'ks_update_interval':
case 'ks_min_words':
if (preg_match ('/[0-9]+/', $value))
$options[substr ($key, 3)] = $value;
else {
$err = 1;
//$errmsg = __('', 'multi-keyword-statistics');
}
break;
case 'ks_default_language':
if (preg_match ('/[a-z-]+/', $key))
$options['default_language'] = $value;
else {
$err = 1;
//$errmsg = __('', 'multi-keyword-statistics');
}
break;
}
}
}
// show status message
if (!isset ($err)) {
// update options in database if there was no input error
keyword_statistics_set_plugin_configuration ($options);
?>
$value) {
switch ($key) {
case 'ks_automatic_meta_data_update':
$options['automatic_meta_data_update'] = 1;
break;
case 'ks_words_from_posts_in_aggregated_description':
case 'ks_max_title_length':
case 'ks_max_keywords_count':
case 'ks_meta_keywords_count':
case 'ks_max_keywords_length':
case 'ks_min_description_length':
case 'ks_max_description_length':
if (preg_match ('/[0-9]+/', $value))
$options[substr ($key, 3)] = $value;
else {
$err = 1;
//$errmsg = __('', 'multi-keyword-statistics');
}
break;
}
}
}
// show status message
if (!isset ($err)) {
// update options in database if there was no input error
keyword_statistics_set_plugin_configuration ($options);
?>
ID, 'ks_metadata', true);
$options = keyword_statistics_get_plugin_configuration ();?>