wp_version = $wp_version;
$this->log_file = dirname(__FILE__) . '/all_in_one_seo_pack.log';
if ($aioseop_options['aiosp_do_log']) {
$this->do_log = true;
} else {
$this->do_log = false;
}
// $this->upgrade_filename = dirname(__FILE__) . '/' . $this->upgrade_filename;
// $this->upgrade_folder = dirname(__FILE__);
}
/**
* Convert a string to lower case
* Compatible with mb_strtolower(), an UTF-8 friendly replacement for strtolower()
*/
function strtolower($str) {
global $UTF8_TABLES;
return strtr($str, $UTF8_TABLES['strtolower']);
}
/**
* Convert a string to upper case
* Compatible with mb_strtoupper(), an UTF-8 friendly replacement for strtoupper()
*/
function strtoupper($str) {
global $UTF8_TABLES;
return strtr($str, $UTF8_TABLES['strtoupper']);
}
function template_redirect() {
global $wp_query;
global $aioseop_options;
$post = $wp_query->get_queried_object();
if( $this->aioseop_mrt_exclude_this_page()){
return;
}
if (is_feed()) {
return;
}
if (is_single() || is_page()) {
$aiosp_disable = htmlspecialchars(stripcslashes(get_post_meta($post->ID, '_aioseop_disable', true)));
if ($aiosp_disable) {
return;
}
}
if ($aioseop_options['aiosp_rewrite_titles']) {
ob_start(array($this, 'output_callback_for_title'));
}
}
function aioseop_mrt_exclude_this_page(){
global $aioseop_options;
$currenturl = trim($_SERVER['REQUEST_URI'],'/');
/* echo " ";
echo $aioseop_options['aiosp_ex_pages'];
echo " ";
*/
$excludedstuff = explode(',',$aioseop_options['aiosp_ex_pages']);
foreach($excludedstuff as $exedd){
//echo $exedd;
$exedd = trim($exedd);
if($exedd){
if(stristr($currenturl, $exedd)){
return true;
}
}
}
return false;
}
function output_callback_for_title($content) {
return $this->rewrite_title($content);
}
//
//CHECK IF ARRAY EXISTS IN DB, IF SO, GET ARRAY, ADD EVERYTHING, CHECK FOR ISSET?
//
function init() {
if (function_exists('load_plugin_textdomain')) {
if ( !defined('WP_PLUGIN_DIR') ) {
load_plugin_textdomain('all_in_one_seo_pack', str_replace( ABSPATH, '', dirname(__FILE__)));
} else {
load_plugin_textdomain('all_in_one_seo_pack', false, dirname(plugin_basename(__FILE__)));
}
}
/*
if (function_exists('load_plugin_textdomain')) {
load_plugin_textdomain('all_in_one_seo_pack', WP_PLUGIN_DIR . '/all-in-one-seo-pack');
}
*/
}
function is_static_front_page() {
global $wp_query;
global $aioseop_options;
$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 get_base() {
return '/'.end(explode('/', str_replace(array('\\','/all_in_one_seo_pack.php'),array('/',''),__FILE__)));
}
function seo_mrt_admin_head() {
$home = get_settings('siteurl');
$stylesheet = WP_PLUGIN_URL . '/all-in-one-seo-pack/style.css';
echo ' ';
}
function wp_head() {
if (is_feed()) {
return;
}
global $wp_query;
global $aioseop_options;
$post = $wp_query->get_queried_object();
$meta_string = null;
if($this->is_static_posts_page()){
$title = strip_tags( apply_filters( 'single_post_title', $post->post_title ) );
}
//echo("wp_head() " . wp_title('', false) . " is_home() => " . is_home() . ", is_page() => " . is_page() . ", is_single() => " . is_single() . ", is_static_front_page() => " . $this->is_static_front_page() . ", is_static_posts_page() => " . $this->is_static_posts_page());
if (is_single() || is_page()) {
$aiosp_disable = htmlspecialchars(stripcslashes(get_post_meta($post->ID, '_aioseop_disable', true)));
if ($aiosp_disable) {
return;
}
}
if( $this->aioseop_mrt_exclude_this_page()==TRUE ){
return;
}
if ($aioseop_options['aiosp_rewrite_titles']) {
// make the title rewrite as short as possible
if (function_exists('ob_list_handlers')) {
$active_handlers = ob_list_handlers();
} else {
$active_handlers = array();
}
if (sizeof($active_handlers) > 0 &&
strtolower($active_handlers[sizeof($active_handlers) - 1]) ==
strtolower('All_in_One_SEO_Pack::output_callback_for_title')) {
ob_end_flush();
} else {
$this->log("another plugin interfering?");
// if we get here there *could* be trouble with another plugin :(
$this->ob_start_detected = true;
if (function_exists('ob_list_handlers')) {
foreach (ob_list_handlers() as $handler) {
$this->log("detected output handler $handler");
}
}
}
}
/*
echo trim($_SERVER['REQUEST_URI'],'/');
$currenturl = trim($_SERVER['REQUEST_URI'],'/');
echo " ";
echo $aioseop_options['aiosp_ex_pages'];
echo " ";
$excludedstuff = explode(',',$aioseop_options['aiosp_ex_pages']);
foreach($excludedstuff as $exedd){
echo $exedd;
//echo " substring: ". stristr($currenturl,trim($exedd)) . " ";
if(stristr($currenturl, trim($exedd))){
echo " match, should not display ";
}else{
echo " ( " . $exedd . " was not found in " . $currenturl . " ) - no match ";
}
}
//print_r($excludedstuff);
*/
echo "\n\n";
if ((is_home() && $aioseop_options['aiosp_home_keywords'] && !$this->is_static_posts_page()) || $this->is_static_front_page()) {
$keywords = trim($this->internationalize($aioseop_options['aiosp_home_keywords']));
} elseif($this->is_static_posts_page() && !$aioseop_options['aiosp_dynamic_postspage_keywords']){ // and if option = use page set keywords instead of keywords from recent posts
//$keywords = "posts keyyysss" . stripcslashes(get_post_meta($post->ID,'keywords',true));
$keywords = stripcslashes($this->internationalize(get_post_meta($post->ID, "_aioseop_keywords", true)));
// $keywords = $this->get_unique_keywords($keywords);
}else {
$keywords = $this->get_all_keywords();
}
if (is_single() || is_page() || $this->is_static_posts_page()) {
if ($this->is_static_front_page()) {
$description = trim(stripcslashes($this->internationalize($aioseop_options['aiosp_home_description'])));
} else {
$description = $this->get_post_description($post);
$description = apply_filters('aioseop_description',$description);
}
} else if (is_home()) {
$description = trim(stripcslashes($this->internationalize($aioseop_options['aiosp_home_description'])));
} else if (is_category()) {
$description = $this->internationalize(category_description());
}
if (isset($description) && (strlen($description) > $this->minimum_description_length) && !(is_home() && is_paged())) {
$description = trim(strip_tags($description));
$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";
} else {
$meta_string = '';
}
// description format
$description_format = $aioseop_options['aiosp_description_format'];
if (!isset($description_format) || empty($description_format)) {
$description_format = "%description%";
}
$description = str_replace('%description%', $description, $description_format);
$description = str_replace('%blog_title%', get_bloginfo('name'), $description);
$description = str_replace('%blog_description%', get_bloginfo('description'), $description);
$description = str_replace('%wp_title%', $this->get_original_title(), $description);
//$description = html_entity_decode($description, ENT_COMPAT, get_bloginfo('charset'));
if($aioseop_options['aiosp_can'] && is_attachment()){
$url = $this->aiosp_mrt_get_url($wp_query);
if ($url) {
preg_match_all('/(\d+)/', $url, $matches);
if (is_array($matches)){
$uniqueDesc = join('',$matches[0]);
}
}
$description .= ' ' . $uniqueDesc;
}
$meta_string .= sprintf(" ", $description);
}
$keywords = apply_filters('aioseop_keywords',$keywords);
if (isset ($keywords) && !empty($keywords) && !(is_home() && is_paged())) {
if (isset($meta_string)) {
$meta_string .= "\n";
}
$meta_string .= sprintf(" ", $keywords);
}
if (function_exists('is_tag')) {
$is_tag = is_tag();
}
if ((is_category() && $aioseop_options['aiosp_category_noindex']) ||
(!is_category() && is_archive() &&!$is_tag && $aioseop_options['aiosp_archive_noindex']) ||
($aioseop_options['aiosp_tags_noindex'] && $is_tag)) {
if (isset($meta_string)) {
$meta_string .= "\n";
}
$meta_string .= ' ';
}
$page_meta = stripcslashes($aioseop_options['aiosp_page_meta_tags']);
$post_meta = stripcslashes($aioseop_options['aiosp_post_meta_tags']);
$home_meta = stripcslashes($aioseop_options['aiosp_home_meta_tags']);
if (is_page() && isset($page_meta) && !empty($page_meta) || $this->is_static_posts_page()) {
if (isset($meta_string)) {
$meta_string .= "\n";
}
echo "\n$page_meta";
}
if (is_single() && isset($post_meta) && !empty($post_meta)) {
if (isset($meta_string)) {
$meta_string .= "\n";
}
$meta_string .= "$post_meta";
}
if (is_home() && !empty($home_meta)) {
if (isset($meta_string)) {
$meta_string .= "\n";
}
$meta_string .= "$home_meta";
}
if ($meta_string != null) {
echo "$meta_string\n";
}
if($aioseop_options['aiosp_can']){
$url = $this->aiosp_mrt_get_url($wp_query);
if ($url) {
$url = apply_filters('aioseop_canonical_url',$url);
echo "".' '."\n";
}
}
echo "\n";
}
// Thank you, Yoast de Valk, for much of this code.
function aiosp_mrt_get_url($query) {
global $aioseop_options;
if ($query->is_404 || $query->is_search) {
return false;
}
$haspost = count($query->posts) > 0;
$has_ut = function_exists('user_trailingslashit');
if (get_query_var('m')) {
$m = preg_replace('/[^0-9]/', '', get_query_var('m'));
switch (strlen($m)) {
case 4:
$link = get_year_link($m);
break;
case 6:
$link = get_month_link(substr($m, 0, 4), substr($m, 4, 2));
break;
case 8:
$link = get_day_link(substr($m, 0, 4), substr($m, 4, 2),
substr($m, 6, 2));
break;
default:
return false;
}
} elseif (($query->is_single || $query->is_page) && $haspost) {
$post = $query->posts[0];
$link = get_permalink($post->ID);
$link = $this->yoast_get_paged($link);
/* if ($page && $page > 1) {
$link = trailingslashit($link) . "page/". "$page";
if ($has_ut) {
$link = user_trailingslashit($link, 'paged');
} else {
$link .= '/';
}
}
if ($query->is_page && ('page' == get_option('show_on_front')) &&
$post->ID == get_option('page_on_front'))
{
$link = trailingslashit($link);
}*/
} elseif ($query->is_author && $haspost) {
global $wp_version;
if ($wp_version >= '2') {
$author = get_userdata(get_query_var('author'));
if ($author === false)
return false;
$link = get_author_link(false, $author->ID,
$author->user_nicename);
} else {
global $cache_userdata;
$userid = get_query_var('author');
$link = get_author_link(false, $userid,
$cache_userdata[$userid]->user_nicename);
}
} elseif ($query->is_category && $haspost) {
$link = get_category_link(get_query_var('cat'));
$link = $this->yoast_get_paged($link);
} else if ($query->is_tag && $haspost) {
$tag = get_term_by('slug',get_query_var('tag'),'post_tag');
if (!empty($tag->term_id)) {
$link = get_tag_link($tag->term_id);
}
$link = $this->yoast_get_paged($link);
} elseif ($query->is_day && $haspost) {
$link = get_day_link(get_query_var('year'),
get_query_var('monthnum'),
get_query_var('day'));
} elseif ($query->is_month && $haspost) {
$link = get_month_link(get_query_var('year'),
get_query_var('monthnum'));
} elseif ($query->is_year && $haspost) {
$link = get_year_link(get_query_var('year'));
} elseif ($query->is_home) {
if ((get_option('show_on_front') == 'page') &&
($pageid = get_option('page_for_posts')))
{
$link = get_permalink($pageid);
$link = $this->yoast_get_paged($link);
$link = trailingslashit($link);
} else {
$link = get_option('home');
$link = $this->yoast_get_paged($link);
$link = trailingslashit($link); }
} else {
return false;
}
return $link;
}
function yoast_get_paged($link) {
$page = get_query_var('paged');
if ($page && $page > 1) {
$link = trailingslashit($link) ."page/". "$page";
if ($has_ut) {
$link = user_trailingslashit($link, 'paged');
} else {
$link .= '/';
}
}
return $link;
}
function get_post_description($post) {
global $aioseop_options;
$description = trim(stripcslashes($this->internationalize(get_post_meta($post->ID, "_aioseop_description", true))));
if (!$description) {
$description = $this->trim_excerpt_without_filters_full_length($this->internationalize($post->post_excerpt));
if (!$description && $aioseop_options["aiosp_generate_descriptions"]) {
$description = $this->trim_excerpt_without_filters($this->internationalize($post->post_content));
}
}
// "internal whitespace trim"
$description = preg_replace("/\s\s+/", " ", $description);
return $description;
}
function replace_title($content, $title) {
$title = trim(strip_tags($title));
$title_tag_start = "
";
$title_tag_end = " ";
$len_start = strlen($title_tag_start);
$len_end = strlen($title_tag_end);
$title = stripcslashes(trim($title));
$start = strpos($content, $title_tag_start);
$end = strpos($content, $title_tag_end);
$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 {
// this breaks some sitemap plugins (like wpg2)
//$header = $content . "$title ";
$header = $content;
}
return $header;
}
function internationalize($in) {
if (function_exists('langswitch_filter_langs_with_message')) {
$in = langswitch_filter_langs_with_message($in);
}
if (function_exists('polyglot_filter')) {
$in = polyglot_filter($in);
}
if (function_exists('qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage')) {
$in = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($in);
}
$in = apply_filters('localization', $in);
return $in;
}
/** @return The original title as delivered by WP (well, in most cases) */
function get_original_title() {
global $wp_query;
global $aioseop_options;
if (!$wp_query) {
return null;
}
$post = $wp_query->get_queried_object();
// the_search_query() is not suitable, it cannot just return
global $s;
$title = null;
if (is_home()) {
$title = get_option('blogname');
} else if (is_single()) {
$title = $this->internationalize(wp_title('', false));
} else if (is_search() && isset($s) && !empty($s)) {
if (function_exists('attribute_escape')) {
$search = attribute_escape(stripcslashes($s));
} else {
$search = wp_specialchars(stripcslashes($s), true);
}
$search = $this->capitalize($search);
$title = $search;
} else if (is_category() && !is_feed()) {
$category_description = $this->internationalize(category_description());
$category_name = ucwords($this->internationalize(single_cat_title('', false)));
$title = $category_name;
} else if (is_page()) {
$title = $this->internationalize(wp_title('', false));
} 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 = $this->internationalize(wp_title('', false));
}
if ($tag) {
$title = $tag;
}
} else if (is_archive()) {
$title = $this->internationalize(wp_title('', false));
} else if (is_404()) {
$title_format = $aioseop_options['aiosp_404_title_format'];
$new_title = str_replace('%blog_title%', $this->internationalize(get_bloginfo('name')), $title_format);
$new_title = str_replace('%blog_description%', $this->internationalize(get_bloginfo('description')), $new_title);
$new_title = str_replace('%request_url%', $_SERVER['REQUEST_URI'], $new_title);
$new_title = str_replace('%request_words%', $this->request_as_words($_SERVER['REQUEST_URI']), $new_title);
$title = $new_title;
}
return trim($title);
}
function paged_title($title) {
// the page number if paged
global $paged;
global $aioseop_options;
// simple tagging support
global $STagging;
if (is_paged() || (isset($STagging) && $STagging->is_tag_view() && $paged)) {
$part = $this->internationalize($aioseop_options['aiosp_paged_format']);
if (isset($part) || !empty($part)) {
$part = " " . trim($part);
$part = str_replace('%page%', $paged, $part);
$this->log("paged_title() [$title] [$part]");
$title .= $part;
}
}
return $title;
}
function rewrite_title($header) {
global $aioseop_options;
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;
global $STagging;
if (is_home() && !$this->is_static_posts_page()) {
$title = $this->internationalize($aioseop_options['aiosp_home_title']);
if (empty($title)) {
$title = $this->internationalize(get_option('blogname'));
}
$title = $this->paged_title($title);
$header = $this->replace_title($header, $title);
} else if (is_attachment()) {
$title = get_the_title($post->post_parent).' '.$post->post_title.' – '.get_option('blogname');
$header = $this->replace_title($header,$title);
} else if (is_single()) {
// we're not in the loop :(
$authordata = get_userdata($post->post_author);
$categories = get_the_category();
$category = '';
if (count($categories) > 0) {
$category = $categories[0]->cat_name;
}
$title = $this->internationalize(get_post_meta($post->ID, "_aioseop_title", true));
if (!$title) {
$title = $this->internationalize(get_post_meta($post->ID, "title_tag", true));
if (!$title) {
$title = $this->internationalize(wp_title('', false));
}
}
$title_format = $aioseop_options['aiosp_post_title_format'];
$new_title = str_replace('%blog_title%', $this->internationalize(get_bloginfo('name')), $title_format);
$new_title = str_replace('%blog_description%', $this->internationalize(get_bloginfo('description')), $new_title);
$new_title = str_replace('%post_title%', $title, $new_title);
$new_title = str_replace('%category%', $category, $new_title);
$new_title = str_replace('%category_title%', $category, $new_title);
$new_title = str_replace('%post_author_login%', $authordata->user_login, $new_title);
$new_title = str_replace('%post_author_nicename%', $authordata->user_nicename, $new_title);
$new_title = str_replace('%post_author_firstname%', ucwords($authordata->first_name), $new_title);
$new_title = str_replace('%post_author_lastname%', ucwords($authordata->last_name), $new_title);
$title = $new_title;
$title = trim($title);
$title = apply_filters('aioseop_title_single',$title);
$header = $this->replace_title($header, $title);
} else if (is_search() && isset($s) && !empty($s)) {
if (function_exists('attribute_escape')) {
$search = attribute_escape(stripcslashes($s));
} else {
$search = wp_specialchars(stripcslashes($s), true);
}
$search = $this->capitalize($search);
$title_format = $aioseop_options['aiosp_search_title_format'];
$title = str_replace('%blog_title%', $this->internationalize(get_bloginfo('name')), $title_format);
$title = str_replace('%blog_description%', $this->internationalize(get_bloginfo('description')), $title);
$title = str_replace('%search%', $search, $title);
$header = $this->replace_title($header, $title);
} else if (is_category() && !is_feed()) {
$category_description = $this->internationalize(category_description());
if($aioseop_options['aiosp_cap_cats']){
$category_name = ucwords($this->internationalize(single_cat_title('', false)));
}else{
$category_name = $this->internationalize(single_cat_title('', false));
}
//$category_name = ucwords($this->internationalize(single_cat_title('', false)));
$title_format = $aioseop_options['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%', $this->internationalize(get_bloginfo('name')), $title);
$title = str_replace('%blog_description%', $this->internationalize(get_bloginfo('description')), $title);
$title = $this->paged_title($title);
$header = $this->replace_title($header, $title);
} else if (is_page() || $this->is_static_posts_page()) {
// we're not in the loop :(
$authordata = get_userdata($post->post_author);
if ($this->is_static_front_page()) {
if ($this->internationalize($aioseop_options['aiosp_home_title'])) {
//home title filter
$home_title = $this->internationalize($aioseop_options['aiosp_home_title']);
$home_title = apply_filters('aioseop_home_page_title',$home_title);
$header = $this->replace_title($header, $home_title);
}
} else {
$title = $this->internationalize(get_post_meta($post->ID, "_aioseop_title", true));
if (!$title) {
$title = $this->internationalize(wp_title('', false));
}
$title_format = $aioseop_options['aiosp_page_title_format'];
$new_title = str_replace('%blog_title%', $this->internationalize(get_bloginfo('name')), $title_format);
$new_title = str_replace('%blog_description%', $this->internationalize(get_bloginfo('description')), $new_title);
$new_title = str_replace('%page_title%', $title, $new_title);
$new_title = str_replace('%page_author_login%', $authordata->user_login, $new_title);
$new_title = str_replace('%page_author_nicename%', $authordata->user_nicename, $new_title);
$new_title = str_replace('%page_author_firstname%', ucwords($authordata->first_name), $new_title);
$new_title = str_replace('%page_author_lastname%', ucwords($authordata->last_name), $new_title);
$title = trim($new_title);
$title = apply_filters('aioseop_title_page',$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 = $this->internationalize(wp_title('', false));
}
if ($tag) {
$tag = $this->capitalize($tag);
$title_format = $aioseop_options['aiosp_tag_title_format'];
$title = str_replace('%blog_title%', $this->internationalize(get_bloginfo('name')), $title_format);
$title = str_replace('%blog_description%', $this->internationalize(get_bloginfo('description')), $title);
$title = str_replace('%tag%', $tag, $title);
$title = $this->paged_title($title);
$header = $this->replace_title($header, $title);
}
} else if (isset($STagging) && $STagging->is_tag_view()) { // simple tagging support
$tag = $STagging->search_tag;
if ($tag) {
$tag = $this->capitalize($tag);
$title_format = $aioseop_options['aiosp_tag_title_format'];
$title = str_replace('%blog_title%', $this->internationalize(get_bloginfo('name')), $title_format);
$title = str_replace('%blog_description%', $this->internationalize(get_bloginfo('description')), $title);
$title = str_replace('%tag%', $tag, $title);
$title = $this->paged_title($title);
$header = $this->replace_title($header, $title);
}
} else if (is_archive()) {
$date = $this->internationalize(wp_title('', false));
$title_format = $aioseop_options['aiosp_archive_title_format'];
$new_title = str_replace('%blog_title%', $this->internationalize(get_bloginfo('name')), $title_format);
$new_title = str_replace('%blog_description%', $this->internationalize(get_bloginfo('description')), $new_title);
$new_title = str_replace('%date%', $date, $new_title);
$title = trim($new_title);
$title = $this->paged_title($title);
$header = $this->replace_title($header, $title);
} else if (is_404()) {
$title_format = $aioseop_options['aiosp_404_title_format'];
$new_title = str_replace('%blog_title%', $this->internationalize(get_bloginfo('name')), $title_format);
$new_title = str_replace('%blog_description%', $this->internationalize(get_bloginfo('description')), $new_title);
$new_title = str_replace('%request_url%', $_SERVER['REQUEST_URI'], $new_title);
$new_title = str_replace('%request_words%', $this->request_as_words($_SERVER['REQUEST_URI']), $new_title);
$new_title = str_replace('%404_title%', $this->internationalize(wp_title('', false)), $new_title);
$header = $this->replace_title($header, $new_title);
}
return $header;
}
/**
* @return User-readable nice words for a given request.
*/
function request_as_words($request) {
$request = htmlspecialchars($request);
$request = str_replace('.html', ' ', $request);
$request = str_replace('.htm', ' ', $request);
$request = str_replace('.', ' ', $request);
$request = str_replace('/', ' ', $request);
$request_a = explode(' ', $request);
$request_new = array();
foreach ($request_a as $token) {
$request_new[] = ucwords(trim($token));
}
$request = implode(' ', $request_new);
return $request;
}
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 = preg_replace( '|\[(.+?)\](.+?\[/\\1\])?|s', '', $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(stripcslashes($text));
}
function trim_excerpt_without_filters_full_length($text) {
$text = str_replace(']]>', ']]>', $text);
$text = preg_replace( '|\[(.+?)\](.+?\[/\\1\])?|s', '', $text );
$text = strip_tags($text);
return trim(stripcslashes($text));
}
/**
* @return comma-separated list of unique keywords
*/
function get_all_keywords() {
global $posts;
global $aioseop_options;
if (is_404()) {
return null;
}
// if we are on synthetic pages
if (!is_home() && !is_page() && !is_single() &&!$this->is_static_front_page() && !$this->is_static_posts_page()) {
return null;
}
$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 = (is_attachment())?($post->post_parent):($post->ID); // if attachment then use parent post id
$keywords_i = stripcslashes($this->internationalize(get_post_meta($id, "_aioseop_keywords", true)));
//$id = $post->ID;
//$keywords_i = stripcslashes($this->internationalize(get_post_meta($post->ID, "_aioseop_keywords", true)));
$keywords_i = str_replace('"', '', $keywords_i);
if (isset($keywords_i) && !empty($keywords_i)) {
$traverse = explode(',', $keywords_i);
foreach ($traverse as $keyword) {
$keywords[] = $keyword;
}
}
// WP 2.3 tags
if ($aioseop_options['aiosp_use_tags_as_keywords']){
if (function_exists('get_the_tags')) {
//$tags = get_the_tags($post->ID);
$tags = get_the_tags($id);
if ($tags && is_array($tags)) {
foreach ($tags as $tag) {
$keywords[] = $this->internationalize($tag->name);
}
}
}
}
// Ultimate Tag Warrior integration
global $utw;
if ($utw) {
$tags = $utw->GetTagsForPost($post);
if (is_array($tags)) {
foreach ($tags as $tag) {
$tag = $tag->tag;
$tag = str_replace('_',' ', $tag);
$tag = str_replace('-',' ',$tag);
$tag = stripcslashes($tag);
$keywords[] = $tag;
}
}
}
// autometa
$autometa = stripcslashes(get_post_meta($id, 'autometa', true));
//$autometa = stripcslashes(get_post_meta($post->ID, "autometa", true));
if (isset($autometa) && !empty($autometa)) {
$autometa_array = explode(' ', $autometa);
foreach ($autometa_array as $e) {
$keywords[] = $e;
}
}
if ($aioseop_options['aiosp_use_categories'] && !is_page()) {
$categories = get_the_category($id);
//$categories = get_the_category($post->ID);
foreach ($categories as $category) {
$keywords[] = $this->internationalize($category->cat_name);
}
}
}
}
}
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 = stripcslashes(get_post_meta($post->ID, "_aioseop_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_unique_keywords($keywords) {
$small_keywords = array();
foreach ($keywords as $word) {
if (function_exists('mb_strtolower'))
$small_keywords[] = mb_strtolower($word, get_bloginfo('charset'));
else
$small_keywords[] = $this->strtolower($word);
}
$keywords_ar = array_unique($small_keywords);
return implode(',', $keywords_ar);
}
function get_url($url) {
if (function_exists('file_get_contents')) {
$file = file_get_contents($url);
} else {
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$file = curl_exec($curl);
curl_close($curl);
}
return $file;
}
function log($message) {
if ($this->do_log) {
error_log(date('Y-m-d H:i:s') . " " . $message . "\n", 3, $this->log_file);
}
}
function download_newest_version() {
$success = true;
$file_content = $this->get_url($this->upgrade_url);
if ($file_content === false) {
$this->upgrade_error = sprintf(__("Could not download distribution (%s)"), $this->upgrade_url);
$success = false;
} else if (strlen($file_content) < 100) {
$this->upgrade_error = sprintf(__("Could not download distribution (%s): %s"), $this->upgrade_url, $file_content);
$success = false;
} else {
$this->log(sprintf("filesize of download ZIP: %d", strlen($file_content)));
$fh = @fopen($this->upgrade_filename, 'w');
$this->log("fh is $fh");
if (!$fh) {
$this->upgrade_error = sprintf(__("Could not open %s for writing"), $this->upgrade_filename);
$this->upgrade_error .= " ";
$this->upgrade_error .= sprintf(__("Please make sure %s is writable"), $this->upgrade_folder);
$success = false;
} else {
$bytes_written = @fwrite($fh, $file_content);
$this->log("wrote $bytes_written bytes");
if (!$bytes_written) {
$this->upgrade_error = sprintf(__("Could not write to %s"), $this->upgrade_filename);
$success = false;
}
}
if ($success) {
fclose($fh);
}
}
return $success;
}
function install_newest_version() {
$success = $this->download_newest_version();
if ($success) {
$success = $this->extract_plugin();
unlink($this->upgrade_filename);
}
return $success;
}
function extract_plugin() {
if (!class_exists('PclZip')) {
require_once ('pclzip.lib.php');
}
$archive = new PclZip($this->upgrade_filename);
$files = $archive->extract(PCLZIP_OPT_STOP_ON_ERROR, PCLZIP_OPT_REPLACE_NEWER, PCLZIP_OPT_REMOVE_ALL_PATH, PCLZIP_OPT_PATH, $this->upgrade_folder);
$this->log("files is $files");
if (is_array($files)) {
$num_extracted = sizeof($files);
$this->log("extracted $num_extracted files to $this->upgrade_folder");
$this->log(print_r($files, true));
return true;
} else {
$this->upgrade_error = $archive->errorInfo();
return false;
}
}
/** crude approximization of whether current user is an admin */
function is_admin() {
return current_user_can('level_8');
}
function is_directory_writable($directory) {
$filename = $directory . '/' . 'tmp_file_' . time();
$fh = @fopen($filename, 'w');
if (!$fh) {
return false;
}
$written = fwrite($fh, "test");
fclose($fh);
unlink($filename);
if ($written) {
return true;
} else {
return false;
}
}
function is_upgrade_directory_writable() {
//return $this->is_directory_writable($this->upgrade_folder);
// let's assume it is
return true;
}
function post_meta_tags($id) {
$awmp_edit = $_POST["aiosp_edit"];
$nonce = $_POST['nonce-aioseop-edit'];
// if (!wp_verify_nonce($nonce, 'edit-aioseop-nonce')) die ( 'Security Check - If you receive this in error, log out and back in to WordPress');
if (isset($awmp_edit) && !empty($awmp_edit) && wp_verify_nonce($nonce, 'edit-aioseop-nonce')) {
$keywords = $_POST["aiosp_keywords"];
$description = $_POST["aiosp_description"];
$title = $_POST["aiosp_title"];
$aiosp_meta = $_POST["aiosp_meta"];
$aiosp_disable = $_POST["aiosp_disable"];
$aiosp_titleatr = $_POST["aiosp_titleatr"];
$aiosp_menulabel = $_POST["aiosp_menulabel"];
delete_post_meta($id, '_aioseop_keywords');
delete_post_meta($id, '_aioseop_description');
delete_post_meta($id, '_aioseop_title');
delete_post_meta($id, '_aioseop_titleatr');
delete_post_meta($id, '_aioseop_menulabel');
if ($this->is_admin()) {
delete_post_meta($id, '_aioseop_disable');
}
//delete_post_meta($id, 'aiosp_meta');
if (isset($keywords) && !empty($keywords)) {
add_post_meta($id, '_aioseop_keywords', $keywords);
}
if (isset($description) && !empty($description)) {
add_post_meta($id, '_aioseop_description', $description);
}
if (isset($title) && !empty($title)) {
add_post_meta($id, '_aioseop_title', $title);
}
if (isset($aiosp_titleatr) && !empty($aiosp_titleatr)) {
add_post_meta($id, '_aioseop_titleatr', $aiosp_titleatr);
}
if (isset($aiosp_menulabel) && !empty($aiosp_menulabel)) {
add_post_meta($id, '_aioseop_menulabel', $aiosp_menulabel);
}
if (isset($aiosp_disable) && !empty($aiosp_disable) && $this->is_admin()) {
add_post_meta($id, '_aioseop_disable', $aiosp_disable);
}
/*
if (isset($aiosp_meta) && !empty($aiosp_meta)) {
add_post_meta($id, 'aiosp_meta', $aiosp_meta);
}
*/
}
}
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($wpdb->prepare("update $this->table_categories
set meta_title='$title', meta_keywords='$keywords'
where category_id=$id"));
} else {
$wpdb->query($wpdb->prepare("insert into $this->table_categories(meta_title, meta_keywords, category_id)
values ('$title', '$keywords', $id"));
}
//$wpdb->query($wpdb->prepare("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);
}
*/
}
}
/**
* @deprecated This was for the feature of dedicated meta tags for categories which never went mainstream.
*/
function edit_category_form() {
global $post;
$keywords = stripcslashes(get_post_meta($post->ID, '_aioseop_keywords', true));
$title = stripcslashes(get_post_meta($post->ID, '_aioseop_title', true));
$description = stripcslashes(get_post_meta($post->ID, '_aioseop_description', true));
?>
ID;
}
$keywords = htmlspecialchars(stripcslashes(get_post_meta($post_id, '_aioseop_keywords', true)));
$title = htmlspecialchars(stripcslashes(get_post_meta($post_id, '_aioseop_title', true)));
$description = htmlspecialchars(stripcslashes(get_post_meta($post_id, '_aioseop_description', true)));
$aiosp_meta = htmlspecialchars(stripcslashes(get_post_meta($post_id, '_aioseop_meta', true)));
$aiosp_disable = htmlspecialchars(stripcslashes(get_post_meta($post_id, '_aioseop_disable', true)));
$aiosp_titleatr = htmlspecialchars(stripcslashes(get_post_meta($post_id, '_aioseop_titleatr', true)));
$aiosp_menulabel = htmlspecialchars(stripcslashes(get_post_meta($post_id, '_aioseop_menulabel', true)));
?>
wp_version, 0, 3) >= '2.5') { ?>
wp_version, 0, 3) >= '2.5') { ?>
wp_version, 0, 3) == '1.5') {
$file = 'all-in-one-seo-pack/all_in_one_seo_pack.php';
}
//add_management_page(__('All in One SEO Title', 'all_in_one_seo_pack'), __('All in One SEO', 'all_in_one_seo_pack'), 10, $file, array($this, 'management_panel'));
add_submenu_page('options-general.php', __('All in One SEO', 'all_in_one_seo_pack'), __('All in One SEO', 'all_in_one_seo_pack'), 10, $file, array($this, 'options_panel'));
}
function management_panel() {
$message = null;
$base_url = "edit.php?page=" . __FILE__;
//echo($base_url);
$type = $_REQUEST['type'];
if (!isset($type)) {
$type = "posts";
}
?>
1,
"aiosp_donate"=>0,
"aiosp_home_title"=>null,
"aiosp_home_description"=>'',
"aiosp_home_keywords"=>null,
"aiosp_max_words_excerpt"=>'something',
"aiosp_rewrite_titles"=>1,
"aiosp_post_title_format"=>'%post_title% | %blog_title%',
"aiosp_page_title_format"=>'%page_title% | %blog_title%',
"aiosp_category_title_format"=>'%category_title% | %blog_title%',
"aiosp_archive_title_format"=>'%date% | %blog_title%',
"aiosp_tag_title_format"=>'%tag% | %blog_title%',
"aiosp_search_title_format"=>'%search% | %blog_title%',
"aiosp_description_format"=>'%description%',
"aiosp_404_title_format"=>'Nothing found for %request_words%',
"aiosp_paged_format"=>' - Part %page%',
"aiosp_use_categories"=>0,
"aiosp_dynamic_postspage_keywords"=>1,
"aiosp_category_noindex"=>1,
"aiosp_archive_noindex"=>1,
"aiosp_tags_noindex"=>0,
"aiosp_cap_cats"=>1,
"aiosp_generate_descriptions"=>1,
"aiosp_debug_info"=>null,
"aiosp_post_meta_tags"=>'',
"aiosp_page_meta_tags"=>'',
"aiosp_home_meta_tags"=>'',
"aiosp_enabled" =>0,
"aiosp_use_tags_as_keywords" =>1,
"aiosp_do_log"=>null);
update_option('aioseop_options', $res_aioseop_options);
}
// update options
if ($_POST['action'] && $_POST['action'] == 'aiosp_update' && $_POST['Submit']!='') {
$nonce = $_POST['nonce-aioseop'];
if (!wp_verify_nonce($nonce, 'aioseop-nonce')) die ( 'Security Check - If you receive this in error, log out and back in to WordPress');
$message = __("All in One SEO Options Updated.", 'all_in_one_seo_pack');
$aioseop_options['aiosp_can'] = $_POST['aiosp_can'];
$aioseop_options['aiosp_donate'] = $_POST['aiosp_donate'];
$aioseop_options['aiosp_home_title'] = $_POST['aiosp_home_title'];
$aioseop_options['aiosp_home_description'] = $_POST['aiosp_home_description'];
$aioseop_options['aiosp_home_keywords'] = $_POST['aiosp_home_keywords'];
$aioseop_options['aiosp_max_words_excerpt'] = $_POST['aiosp_max_words_excerpt'];
$aioseop_options['aiosp_rewrite_titles'] = $_POST['aiosp_rewrite_titles'];
$aioseop_options['aiosp_post_title_format'] = $_POST['aiosp_post_title_format'];
$aioseop_options['aiosp_page_title_format'] = $_POST['aiosp_page_title_format'];
$aioseop_options['aiosp_category_title_format'] = $_POST['aiosp_category_title_format'];
$aioseop_options['aiosp_archive_title_format'] = $_POST['aiosp_archive_title_format'];
$aioseop_options['aiosp_tag_title_format'] = $_POST['aiosp_tag_title_format'];
$aioseop_options['aiosp_search_title_format'] = $_POST['aiosp_search_title_format'];
$aioseop_options['aiosp_description_format'] = $_POST['aiosp_description_format'];
$aioseop_options['aiosp_404_title_format'] = $_POST['aiosp_404_title_format'];
$aioseop_options['aiosp_paged_format'] = $_POST['aiosp_paged_format'];
$aioseop_options['aiosp_use_categories'] = $_POST['aiosp_use_categories'];
$aioseop_options['aiosp_dynamic_postspage_keywords'] = $_POST['aiosp_dynamic_postspage_keywords'];
$aioseop_options['aiosp_category_noindex'] = $_POST['aiosp_category_noindex'];
$aioseop_options['aiosp_archive_noindex'] = $_POST['aiosp_archive_noindex'];
$aioseop_options['aiosp_tags_noindex'] = $_POST['aiosp_tags_noindex'];
$aioseop_options['aiosp_generate_descriptions'] = $_POST['aiosp_generate_descriptions'];
$aioseop_options['aiosp_cap_cats'] = $_POST['aiosp_cap_cats'];
$aioseop_options['aiosp_debug_info'] = $_POST['aiosp_debug_info'];
$aioseop_options['aiosp_post_meta_tags'] = $_POST['aiosp_post_meta_tags'];
$aioseop_options['aiosp_page_meta_tags'] = $_POST['aiosp_page_meta_tags'];
$aioseop_options['aiosp_home_meta_tags'] = $_POST['aiosp_home_meta_tags'];
$aioseop_options['aiosp_ex_pages'] = $_POST['aiosp_ex_pages'];
$aioseop_options['aiosp_do_log'] = $_POST['aiosp_do_log'];
$aioseop_options['aiosp_enabled'] = $_POST['aiosp_enabled'];
$aioseop_options['aiosp_use_tags_as_keywords'] = $_POST['aiosp_use_tags_as_keywords'];
update_option('aioseop_options', $aioseop_options);
if (function_exists('wp_cache_flush')) {
wp_cache_flush();
}
} /*elseif ($_POST['aiosp_upgrade']) {
$message = __("Upgraded to newest version. Please revisit the options page to make sure you see the newest version.", 'all_in_one_seo_pack');
$success = $this->install_newest_version();
if (!$success) {
$message = __("Upgrade failed", 'all_in_one_seo_pack');
if (isset($this->upgrade_error) && !empty($this->upgrade_error)) {
$message .= ": " . $this->upgrade_error;
} else {
$message .= ".";
}
}
}*/
?>
by
Michael Torbert of
Semper Fi Web Design
version ", 'all_in_one_seo_pack') ?>
|
|
|
|
get_item_quantity(3);
// Build an array of all the items, starting with element 0 (first element).
$rss_items = $rss->get_items(0, $maxitems);
?>
get_item_quantity(3);
// Build an array of all the items, starting with element 0 (first element).
$rss_items = $rss->get_items(0, $maxitems);
?>
items)){
$items = array_slice($rss->items, 0, $maxitems);
?>
No items';
else
foreach ( $items as $item ) : ?>
'
title=''>
items)){
$items = array_slice($rss->items, 0, $maxitems);
?>
No items';
else
foreach ( $items as $item ) : ?>
'
title=''>
get_var("SELECT COUNT(*) FROM $wpdb->postmeta WHERE meta_key = 'keywords'");
$somecount = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->postmeta WHERE meta_key = 'title'") + $somecount;
$somecount = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->postmeta WHERE meta_key = 'description'") + $somecount;
$somecount = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->postmeta WHERE meta_key = 'aiosp_meta'") + $somecount;
$somecount = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->postmeta WHERE meta_key = 'aiosp_disable'") + $somecount;
if($somecount > 0){
echo "
Your database meta needs to be updated. " . $somecount . " old fields remaining (Back up your database before updating.)
";
}
if(!get_option('aioseop_options')){
echo "
Your database options need to be updated. (Back up your database before updating.)
";
}
?>