get_var('SELECT cat_ID FROM '.$wpdb->categories.' WHERE category_nicename="'.$category_nicename.'"');
return $name;
}
}
if(!function_exists('get_comment_count'))
{
function get_comment_count($post_ID)
{
global $wpdb;
return $wpdb->get_var('SELECT count(*) FROM '.$wpdb->comments.' WHERE comment_post_ID = '.$post_ID);
}
}
if(!function_exists('link_exists'))
{
function link_exists($linkname)
{
global $wpdb;
return $wpdb->get_var('SELECT link_id FROM '.$wpdb->links.' WHERE link_name = "'.$wpdb->escape($linkname).'"');
}
}
if(!function_exists('find_comment_parent'))
{
function find_comment_parent($haystack, $needle)
{
ini_set('display_errors', true);
foreach($haystack as $h)
{
if($h[0] == $needle)
return $h[1];
}
}
}
if(!function_exists('get_cat_by_name'))
{
function get_cat_by_name($cat_name)
{
global $wpdb;
return $wpdb->get_var("SELECT term_id from ".$wpdb->terms." WHERE name = '$cat_name'");
}
}
// dobschat - 2008/11/08
function set_tags_from_s9y($item, $key, $post_id) {
if(!empty($item)) { wp_set_post_tags($post_id, $item, TRUE); }
}
// --
/**
The Main Importer Class
**/
class Serendipity_Import extends WP_Importer {
function connect_s9ydb() {
$s9ydb = new wpdb(get_option('s9yuser'),
get_option('s9ypass'),
get_option('s9yname'),
get_option('s9yhost'));
$s9ydb->set_charset($s9ydb->dbh, get_option('s9ycharset'));
set_magic_quotes_runtime(0);
return $s9ydb;
}
function header()
{
echo '
';
echo '
'.__('Import Serendipity').'
';
echo '
'.__('Steps may take a few minutes depending on the size of your database. Please be patient.').'
';
}
function footer()
{
echo '
';
}
function greet()
{
echo '
'.__('Howdy! This importer allows you to extract posts from any Serendipity 9 into your blog. This has not been tested on previous versions of Serendipity. Mileage may vary.').'
';
echo '
'.__('Your Serendipity Configuration settings are as follows:').'
';
echo '';
}
function get_s9y_cats()
{
global $wpdb;
// General Housekeeping
$s9ydb = $this->connect_s9ydb();
$prefix = get_option('spre');
// Get Categories
return $s9ydb->get_results('SELECT A.*, B.category_name AS parentname
FROM '.$prefix.'category A
LEFT JOIN '.$prefix.'category B ON A.parentid = B.categoryid
ORDER BY A.parentid, A.categoryid',
ARRAY_A);
}
function get_s9y_users()
{
global $wpdb;
// General Housekeeping
$s9ydb = $this->connect_s9ydb();
// Get Users
return $s9ydb->get_results('SELECT
username,
realname,
email,
userlevel
FROM '.$prefix.'authors', ARRAY_A);
}
function get_s9y_posts($start=0)
{
// General Housekeeping
$s9ydb = $this->connect_s9ydb();
$prefix = get_option('spre');
// Get Posts
// dobschat - 2008/11/08 - added "author"
$posts = $s9ydb->get_results('SELECT
id,
timestamp,
authorid,
author,
last_modified,
title,
body,
extended,
isdraft
FROM '.$prefix.'entries LIMIT '.$start.',100', ARRAY_A);
return $posts;
}
// Christian Harms - 2012/08/01 -- reading geotags from serendipity_event_geotag
function get_s9y_geotags()
{
global $wpdb;
// General Housekeeping
$s9ydb = $this->connect_s9ydb();
$prefix = get_option('spre');
// Get only the geo_tags stored in the entryproperties table
return $s9ydb->get_results('SELECT entryid, property, value
FROM '.$prefix.'entryproperties', ARRAY_A);
}
function get_s9y_comments()
{
global $wpdb;
// General Housekeeping
$s9ydb = $this->connect_s9ydb();
$prefix = get_option('spre');
// Get Comments
return $s9ydb->get_results('SELECT * FROM '.$prefix.'comments', ARRAY_A);
}
function get_s9y_cat_assoc($post_id)
{
global $wpdb;
// General Housekeeping
$s9ydb = $this->connect_s9ydb();
$prefix = get_option('spre');
return $s9ydb->get_results("select * from ".$prefix."category, ".$prefix."entrycat, ".$prefix."entries where ".$prefix."entries.id = ".$prefix."entrycat.entryid and ".$prefix."category.categoryid=".$prefix."entrycat.categoryid and ".$prefix."entries.id =$post_id;");
}
// dobschat - 2008/11/08 - added function to get the tags from s9y
function get_s9y_tag_assoc($post_id)
{
global $wpdb;
// General Housekeeping
$s9ydb = $this->connect_s9ydb();
$prefix = get_option('spre');
return $s9ydb->get_results("select ".$prefix."entrytags.tag AS tag from ".$prefix."entrytags, ".$prefix."entries where ".$prefix."entries.id = ".$prefix."entrytags.entryid and ".$prefix."entries.id =$post_id;", ARRAY_N);
}
// -----
function cat2wp($categories='')
{
// General Housekeeping
global $wpdb;
$count = 0;
$s9ycat2wpcat = array();
// Do the Magic
if(is_array($categories))
{
echo '
';
return true;
}// End if(is_array($users)
echo __('No Users to Import!');
return false;
}// End function user2wp()
function posts2wp($posts='')
{
// General Housekeeping
global $wpdb;
$count = 0;
$s9yposts2wpposts = get_option('s9yposts2wpposts');
if ( !$s9yposts2wpposts ) $s9yposts2wpposts = array();
$cats = array();
// Do the Magic
if(is_array($posts))
{
echo '
';
return true;
}
echo __('No Comments to Import!');
return false;
}
function import_categories()
{
// Category Import
$cats = $this->get_s9y_cats();
$this->cat2wp($cats);
add_option('s9y_cats', $cats);
echo '';
}
function import_users()
{
// User Import
$users = $this->get_s9y_users();
$this->users2wp($users);
echo '';
}
function import_posts()
{
// Post Import
// Process 100 posts per load, and reload between runs
$start = $_REQUEST["start"];
if ( !$start ) $start = 0;
$posts = $this->get_s9y_posts($start);
if ( count($posts) != 0 )
$this->posts2wp($posts);
if ( count($posts) == 100 )
{
echo "Reloading: More work to do.";
$url = "admin.php?import=serendipity&step=3&start=".($start+100);
?>
';
printf('', __('Import Comments'));
echo '';
}
function import_comments()
{
// Comment Import
$comments = $this->get_s9y_comments();
$this->comments2wp($comments);
echo '';
}
// Christian Harms - 2012/08/01 -- import geo tags as postmeta for WP Geo pluglin
function import_geotags()
{
//read all tags
$tags = $this->get_s9y_geotags();
$this->geotags2wp($tags);
echo '';
}
function cleanup_s9yimport()
{
delete_option('spre');
delete_option('s9y_cats');
delete_option('s9yid2wpid');
delete_option('s9ycat2wpcat');
delete_option('s9yposts2wpposts');
delete_option('s9ycm2wpcm');
delete_option('s9ylinks2wplinks');
delete_option('s9yuser');
delete_option('s9ypass');
delete_option('s9yname');
delete_option('s9yhost');
delete_option('s9ygeotags2wp');
$this->tips();
}
function tips()
{
echo '
'.__('Welcome to WordPress. We hope (and expect!) that you will find this platform incredibly rewarding! As a new WordPress user coming from serendipity, there are some things that we would like to point out. Hopefully, they will help your transition go as smoothly as possible.').'
';
echo '
'.__('Users').'
';
echo '
'.__('You have already setup WordPress and have been assigned an administrative login and password. Forget it. You didn\'t have that login in serendipity, why should you have it here? Instead we have taken care to import all of your users into our system. Unfortunately there is one downside. Because both WordPress and serendipity uses a strong encryption hash with passwords, it is impossible to decrypt it and we are forced to assign temporary passwords to all your users.') . ' ' . __( 'Every user has the same username, but their passwords are reset to password123. It is strongly recommended that you change passwords immediately.') .'
';
echo '
'.__('Preserving Authors').'
';
echo '
'.__('Secondly, we have attempted to preserve post authors. If you are the only author or contributor to your blog, then you are safe. In most cases, we are successful in this preservation endeavor. However, if we cannot ascertain the name of the writer due to discrepancies between database tables, we assign it to you, the administrative user.').'
';
echo '
'.__('WordPress Resources').'
';
echo '
'.__('Finally, there are numerous WordPress resources around the internet. Some of them are:').'