.
*/
class All_in_One_SEO_Pack {
var $version = "1.2.7.6";
/**
* Max numbers of chars in auto-generated description.
*/
var $maximum_description_length = 160;
/**
* Minimum number of chars an excerpt should be so that it can be used
* as description. Touch only if you know what you're doing.
*/
var $minimum_description_length = 1;
var $table_prefix = "aiosp_";
var $table_categries;
var $db_version = '0.1';
var $ob_start_detected = false;
var $title_start = -1;
var $title_end = -1;
var $orig_title = '';
function template_redirect() {
if (is_feed()) {
return;
}
if (get_option('aiosp_debug_info')) {
$this->debug = true;
}
if (get_option('aiosp_rewrite_titles')) {
ob_start(array($this, 'output_callback_for_title'));
}
}
function output_callback_for_title($content) {
return $this->rewrite_title($content);
}
function init() {
if(function_exists('load_plugin_textdomain')) {
load_plugin_textdomain('all_in_one_seo_pack', 'wp-content/plugins/all-in-one-seo-pack');
}
//$this->db_install();
}
function is_static_front_page() {
global $wp_query;
$post = $wp_query->get_queried_object();
return get_option('show_on_front') == 'page' && is_page() && $post->ID == get_option('page_on_front');
}
function is_static_posts_page() {
global $wp_query;
$post = $wp_query->get_queried_object();
return get_option('show_on_front') == 'page' && is_home() && $post->ID == get_option('page_for_posts');
}
function wp_head() {
if (is_feed()) {
return;
}
if (get_option('aiosp_rewrite_titles')) {
// make the title rewrite as short as possible
$active_handlers = ob_list_handlers();
if (sizeof($active_handlers) > 0 && $active_handlers[sizeof($active_handlers) - 1] == 'All_in_One_SEO_Pack::output_callback_for_title') {
ob_end_flush();
} else {
// if we get here there *could* be trouble with another plugin :(
$this->ob_start_detected = true;
}
}
global $wp_query;
$post = $wp_query->get_queried_object();
$meta_string = null;
echo "\n";
if ((is_home() && !$this->is_static_posts_page() && get_option('aiosp_home_keywords')) || $this->is_static_front_page()) {
$keywords = trim(get_option('aiosp_home_keywords'));
} else {
$keywords = $this->get_all_keywords();
}
if (is_single() || is_page()) {
if ($this->is_static_front_page()) {
$description = trim(stripslashes(get_option('aiosp_home_description')));
} else {
$description = $this->get_post_description($post);
}
} else if (is_home()) {
if ($this->is_static_posts_page()) {
$description = $this->get_post_description(get_post(get_option('page_for_posts')));
} else {
$description = trim(stripslashes(get_option('aiosp_home_description')));
}
} else if (is_category()) {
$description = category_description();
}
if (isset($description) && strlen($description) > $this->minimum_description_length) {
$description = str_replace('"', '', $description);
// replace newlines on mac / windows?
$description = str_replace("\r\n", ' ', $description);
// maybe linux uses this alone
$description = str_replace("\n", ' ', $description);
if (isset($meta_string)) {
$meta_string .= "\n";
}
$meta_string .= sprintf("", $description);
}
if (isset ($keywords) && !empty($keywords)) {
if (isset($meta_string)) {
$meta_string .= "\n";
}
$meta_string .= sprintf("", $keywords);
}
if (function_exists('is_tag')) {
$is_tag = is_tag();
}
if ((is_category() && get_option('aiosp_category_noindex')) ||
(!is_category() && is_archive() &&!$is_tag && get_option('aiosp_archive_noindex')) ||
(get_option('aiosp_tags_noindex') && $is_tag)) {
if (isset($meta_string)) {
$meta_string .= "\n";
}
$meta_string = '';
}
if ($meta_string != null) {
echo "$meta_string\n";
}
}
function get_post_description($post) {
$description = trim(stripslashes(get_post_meta($post->ID, "description", true)));
if (!$description) {
$description = $this->trim_excerpt_without_filters_full_length($post->post_excerpt);
if (!$description && get_option("aiosp_generate_descriptions")) {
$description = $this->trim_excerpt_without_filters($post->post_content);
}
}
return $description;
}
function replace_title($content, $title) {
$title_tag_start = "
";
$title_tag_end = "";
$len_start = strlen($title_tag_start);
$len_end = strlen($title_tag_end);
$title = stripslashes(trim($title));
$start = strpos($content, "");
$end = strpos($content, "");
$this->title_start = $start;
$this->title_end = $end;
$this->orig_title = $title;
if ($start && $end) {
$header = substr($content, 0, $start + $len_start) . $title . substr($content, $end);
} else {
$header = $content . "$title";
}
return $header;
}
function rewrite_title($header) {
global $wp_query;
if (!$wp_query) {
$header .= "\n";
return $header;
}
$post = $wp_query->get_queried_object();
// the_search_query() is not suitable, it cannot just return
global $s;
if (is_home()) {
if ($this->is_static_posts_page()) {
$title = get_post_meta(get_option('page_for_posts'), "title", true);
if (!$title) {
$title = wp_title('', false);
}
$title_format = get_option('aiosp_page_title_format');
$new_title = str_replace('%blog_title%', get_bloginfo('name'), $title_format);
$new_title = str_replace('%page_title%', $title, $new_title);
$new_title = str_replace('%blog_description%', get_bloginfo('description'), $new_title);
$title = trim($new_title);
$header = $this->replace_title($header, $title);
} else {
if (get_option('aiosp_home_title')) {
$header = $this->replace_title($header, get_option('aiosp_home_title'));
}
}
} else if (is_single()) {
$categories = get_the_category();
$category = '';
if (count($categories) > 0) {
$category = $categories[0]->cat_name;
}
$title = get_post_meta($post->ID, "title", true);
if (!$title) {
$title = get_post_meta($post->ID, "title_tag", true);
if (!$title) {
$title = wp_title('', false);
}
}
$title_format = get_option('aiosp_post_title_format');
$new_title = str_replace('%blog_title%', get_bloginfo('name'), $title_format);
$new_title = str_replace('%blog_description%', get_bloginfo('description'), $new_title);
$new_title = str_replace('%post_title%', $title, $new_title);
$new_title = str_replace('%category%', $category, $new_title);
$title = $new_title;
$title = trim($title);
$header = $this->replace_title($header, $title);
} else if (is_search() && isset($s) && !empty($s)) {
if (function_exists('attribute_escape')) {
$search = attribute_escape(stripslashes($s));
} else {
$search = wp_specialchars(stripslashes($s), true);
}
$search = $this->capitalize($search);
$title_format = get_option('aiosp_search_title_format');
$title = str_replace('%blog_title%', get_bloginfo('name'), $title_format);
$title = str_replace('%blog_description%', get_bloginfo('description'), $title);
$title = str_replace('%search%', $search, $title);
$header = $this->replace_title($header, $title);
} else if (is_category() && !is_feed()) {
$category_description = category_description();
$category_name = ucwords(single_cat_title('', false));
$title_format = get_option('aiosp_category_title_format');
$title = str_replace('%category_title%', $category_name, $title_format);
$title = str_replace('%category_description%', $category_description, $title);
$title = str_replace('%blog_title%', get_bloginfo('name'), $title);
$title = str_replace('%blog_description%', get_bloginfo('description'), $title);
$header = $this->replace_title($header, $title);
} else if (is_page()) {
if ($this->is_static_front_page()) {
if (get_option('aiosp_home_title')) {
$header = $this->replace_title($header, get_option('aiosp_home_title'));
}
} else {
$title = get_post_meta($post->ID, "title", true);
if (!$title) {
$title = wp_title('', false);
}
$title_format = get_option('aiosp_page_title_format');
$new_title = str_replace('%blog_title%', get_bloginfo('name'), $title_format);
$new_title = str_replace('%blog_description%', get_bloginfo('description'), $new_title);
$new_title = str_replace('%page_title%', $title, $new_title);
$title = trim($new_title);
$header = $this->replace_title($header, $title);
}
} else if (function_exists('is_tag') && is_tag()) {
global $utw;
if ($utw) {
$tags = $utw->GetCurrentTagSet();
$tag = $tags[0]->tag;
$tag = str_replace('-', ' ', $tag);
} else {
// wordpress > 2.3
$tag = wp_title('', false);
}
if ($tag) {
$tag = $this->capitalize($tag);
$title_format = get_option('aiosp_tag_title_format');
$title = str_replace('%blog_title%', get_bloginfo('name'), $title_format);
$title = str_replace('%blog_description%', get_bloginfo('description'), $title);
$title = str_replace('%tag%', $tag, $title);
$header = $this->replace_title($header, $title);
}
} else if (is_archive()) {
$date = wp_title('', false);
$title_format = get_option('aiosp_archive_title_format');
$new_title = str_replace('%blog_title%', get_bloginfo('name'), $title_format);
$new_title = str_replace('%blog_description%', get_bloginfo('description'), $new_title);
$new_title = str_replace('%date%', $date, $new_title);
$title = trim($new_title);
$header = $this->replace_title($header, $title);
}
return $header;
}
function capitalize($s) {
$s = trim($s);
$tokens = explode(' ', $s);
while (list($key, $val) = each($tokens)) {
$tokens[$key] = trim($tokens[$key]);
$tokens[$key] = strtoupper(substr($tokens[$key], 0, 1)) . substr($tokens[$key], 1);
}
$s = implode(' ', $tokens);
return $s;
}
function trim_excerpt_without_filters($text) {
$text = str_replace(']]>', ']]>', $text);
$text = strip_tags($text);
$max = $this->maximum_description_length;
if ($max < strlen($text)) {
while($text[$max] != ' ' && $max > $this->minimum_description_length) {
$max--;
}
}
$text = substr($text, 0, $max);
return trim(stripslashes($text));
}
function trim_excerpt_without_filters_full_length($text) {
$text = str_replace(']]>', ']]>', $text);
$text = strip_tags($text);
return trim(stripslashes($text));
}
/**
* @return comma-separated list of unique keywords
*/
function get_all_keywords() {
global $posts;
$keywords = array();
if (is_array($posts)) {
foreach ($posts as $post) {
if ($post) {
if (get_option('aiosp_use_categories') && !is_page()) {
$categories = get_the_category($post->ID);
foreach ($categories as $category) {
$keywords[] = $category->cat_name;
}
}
// Ultimate Tag Warrior integration
global $utw;
if ($utw) {
$tags = $utw->GetTagsForPost($post);
foreach ($tags as $tag) {
$tag = $tag->tag;
$tag = str_replace('_',' ', $tag);
$tag = str_replace('-',' ',$tag);
$tag = stripslashes($tag);
$keywords[] = $tag;
}
}
// WP 2.3 tags
if (function_exists('get_tags')) {
$tags = get_tags();
foreach ($tags as $tag) {
$keywords[] = $tag->name;
}
}
// custom field keywords
$keywords_a = $keywords_i = null;
$description_a = $description_i = null;
$id = $post->ID;
$keywords_i = stripslashes(get_post_meta($post->ID, "keywords", true));
$keywords_i = str_replace('"', '', $keywords_i);
if (isset($keywords_i) && !empty($keywords_i)) {
$keywords[] = $keywords_i;
}
}
}
}
return $this->get_unique_keywords($keywords);
}
function get_meta_keywords() {
global $posts;
$keywords = array();
if (is_array($posts)) {
foreach ($posts as $post) {
if ($post) {
// custom field keywords
$keywords_a = $keywords_i = null;
$description_a = $description_i = null;
$id = $post->ID;
$keywords_i = stripslashes(get_post_meta($post->ID, "keywords", true));
$keywords_i = str_replace('"', '', $keywords_i);
if (isset($keywords_i) && !empty($keywords_i)) {
$keywords[] = $keywords_i;
}
}
}
}
return $this->get_unique_keywords($keywords);
}
function db_install() {
global $wpdb;
$this->table_categories = $wpdb->prefix . $this->table_prefix . "categories";
if(get_option('aiosp_db_version') != $this->db_version) {
$sql = "CREATE TABLE $this->table_categories (
ID bigint(20) NOT NULL auto_increment,
category_id bigint(20) NOT NULL default '0',
meta_title text NOT NULL,
meta_description text NOT NULL,
meta_keywords text NOT NULL,
PRIMARY KEY (ID),
KEY category_id (category_id));";
require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
dbDelta($sql);
update_option('aiosp_db_version', $this->db_version);
}
}
function get_unique_keywords($keywords) {
$keywords_ar = array_unique($keywords);
return implode(',', $keywords_ar);
}
function post_meta_tags($id) {
$awmp_edit = $_POST["aiosp_edit"];
if (isset($awmp_edit) && !empty($awmp_edit)) {
$keywords = $_POST["aiosp_keywords"];
$description = $_POST["aiosp_description"];
$title = $_POST["aiosp_title"];
delete_post_meta($id, 'keywords');
delete_post_meta($id, 'description');
delete_post_meta($id, 'title');
if (isset($keywords) && !empty($keywords)) {
add_post_meta($id, 'keywords', $keywords);
}
if (isset($description) && !empty($description)) {
add_post_meta($id, 'description', $description);
}
if (isset($title) && !empty($title)) {
add_post_meta($id, 'title', $title);
}
}
}
function edit_category($id) {
global $wpdb;
$id = $wpdb->escape($id);
$awmp_edit = $_POST["aiosp_edit"];
if (isset($awmp_edit) && !empty($awmp_edit)) {
$keywords = $wpdb->escape($_POST["aiosp_keywords"]);
$title = $wpdb->escape($_POST["aiosp_title"]);
$old_category = $wpdb->get_row("select * from $this->table_categories where category_id=$id", OBJECT);
if ($old_category) {
$wpdb->query("update $this->table_categories
set meta_title='$title', meta_keywords='$keywords'
where category_id=$id");
} else {
$wpdb->query("insert into $this->table_categories(meta_title, meta_keywords, category_id)
values ('$title', '$keywords', $id");
}
//$wpdb->query("insert into $this->table_categories")
/*
delete_post_meta($id, 'keywords');
delete_post_meta($id, 'description');
delete_post_meta($id, 'title');
if (isset($keywords) && !empty($keywords)) {
add_post_meta($id, 'keywords', $keywords);
}
if (isset($description) && !empty($description)) {
add_post_meta($id, 'description', $description);
}
if (isset($title) && !empty($title)) {
add_post_meta($id, 'title', $title);
}
*/
}
}
function edit_category_form() {
global $post;
$keywords = stripslashes(get_post_meta($post->ID, 'keywords', true));
$title = stripslashes(get_post_meta($post->ID, 'title', true));
$description = stripslashes(get_post_meta($post->ID, 'description', true));
?>
ID;
}
$keywords = htmlspecialchars(stripslashes(get_post_meta($post_id, 'keywords', true)));
$title = htmlspecialchars(stripslashes(get_post_meta($post_id, 'title', true)));
$description = htmlspecialchars(stripslashes(get_post_meta($post_id, 'description', true)));
?>
ID, 'keywords', true)));
$description = htmlspecialchars(stripslashes(get_post_meta($post->ID, 'description', true)));
$title = htmlspecialchars(stripslashes(get_post_meta($post->ID, 'title', true)));
?>
version. " .
'Should I upgrade?', 'all_in_one_seo_pack') ?>
Help', 'all_in_one_seo_pack') ?>
| FAQ', 'all_in_one_seo_pack') ?>
| Feedback', 'all_in_one_seo_pack') ?>