db_set_active(‘older’);

$to_import = db_query(«SELECT * FROM `obixc_easyblog_tag`»);

$tax_array = array();
while ($tax = $to_import->fetchAssoc()) {
$tax_array[] = $tax;
}

db_set_active();

$vocabulary = taxonomy_vocabulary_machine_name_load(‘tags’);
$tax_relation = array();
foreach($tax_array as $tax){
$tax[‘title’] = str_replace(«#»,»»,$tax[‘title’]);
$taxonomies = taxonomy_get_term_by_name($tax[‘title’],’tags’);
if(count($taxonomies) > 0){
foreach($taxonomies as $taxs){
$tax_relation[$tax[‘id’]] = $taxs->tid;
}
}
else{
$term = new stdClass();
$term->vid = $vocabulary->vid;
$term->name = $tax[‘title’];
$term->vocabulary_machine_name = $tax[‘alias’];
$term = taxonomy_term_save($term);

$taxonomies = taxonomy_get_term_by_name($tax[‘title’],’tags’);

foreach($taxonomies as $taxs){
$tax_relation[$tax[‘id’]] = $taxs->tid;
}
}
}

db_set_active(‘older’);

$to_import = db_query(«SELECT * FROM `obixc_easyblog_category`»);

$tax_array = array();
while ($tax = $to_import->fetchAssoc()) {
$tax_array[$tax[‘id’]] = $tax;
}
db_set_active();

$vocabulary = taxonomy_vocabulary_machine_name_load(‘categor_a_blog’);

$categories_relation = array();
foreach($tax_array as $tax){
$tax[‘title’] = str_replace(«#»,»»,$tax[‘title’]);
$taxonomies = taxonomy_get_term_by_name($tax[‘title’],’categor_a_blog’);
if(count($taxonomies) > 0){
foreach($taxonomies as $taxs){
$categories_relation[$tax[‘id’]] = $taxs->tid;
}
}
else{
$term = new stdClass();
$term->vid = $vocabulary->vid;
$term->name = $tax[‘title’];
$term->vocabulary_machine_name = $tax[‘alias’];
if(intval($tax[‘parent_id’]) > 0){
$parent_array = array();
$parent_term = taxonomy_get_term_by_name($tax_array[$tax[‘parent_id’]][‘alias’],$vocabulary->vid);
foreach($parent_term as $parent){
$parent_array[] = $parent->tid;
}
$term->parent = $parent_array;
}
taxonomy_term_save($term);

$taxonomies = taxonomy_get_term_by_name($tax[‘title’],’categor_a_blog’);

foreach($taxonomies as $taxs){
$categories_relation[$tax[‘id’]] = $taxs->tid;
}
}
}

db_set_active(‘older’);

$to_import = db_query(»
SELECT `buser`.`avatar`, `juser`.*
FROM `obixc_easyblog_users` AS `buser`
INNER JOIN `obixc_users` AS `juser` ON `buser`.`id` = `juser`.`id`»);

$users_array = array();
while ($userss = $to_import->fetchAssoc()) {
$users_array[$userss[‘id’]] = $userss;
}

db_set_active();

$users_relation = array();
foreach($users_array as $userss){
$accounts = user_load_by_name($userss[‘username’]);
if($accounts !== False){
$users_relation[$userss[‘id’]] = $accounts->uid;
continue;
}

$accounts = new stdClass;
$accounts->name = $userss[‘username’];
$accounts->pass = ‘P3p06253’;
$accounts->mail =$userss[‘email’];
$accounts->init = $userss[‘email’];
$accounts->status = TRUE;
$accounts->roles = array(DRUPAL_AUTHENTICATED_RID => TRUE);
$accounts = user_save($accounts);

$users_relation[$userss[‘id’]] = $accounts->uid;

$accounts = user_load_by_name($userss[‘username’]);

$image_path = ‘/var/www/vhosts/innovaev2/htdocs/images/easyblog_avatar/’ . $userss[‘avatar’];

if(file_exists($image_path)){
$image_info = image_get_info($image_path);

$file = new StdClass();
if(!file_exists(«public://» . $userss[‘avatar’])){
$file = new StdClass();
$file->uid = $accounts->uid;
$file->uri = $image_path;
$file->filemime = $image_info[‘mime_type’];
$file->status = 0;
$file->filesize = $image_info[‘file_size’];
$dest = «public://» . $userss[‘avatar’];
$file = file_copy($file, $dest);
}
else{
$file = new StdClass();
$file->uid = $accounts->uid;
$file->uri = «public://» . $userss[‘avatar’];
$file->filemime = $image_info[‘mime_type’];
$file->status = 0;
$file->filesize = $image_info[‘file_size’];
}

$validators = array(
‘file_validate_is_image’ => array(),
‘file_validate_image_resolution’ => array(variable_get(‘user_picture_dimensions’, ’85×85′)),
‘file_validate_size’ => array(variable_get(‘user_picture_file_size’, ’30’) * 1024),
);

$errors = file_validate($file, $validators);
if (empty($errors)) {
file_save($file);
$edit[‘picture’] = $file;
user_save($accounts, $edit);
}
}
}

db_set_active(‘older’);

$to_import = db_query(«SELECT * FROM `obixc_easyblog_post`»);

$posts_array = array();
while ($post = $to_import->fetchAssoc()) {
$posts_array[$post[‘id’]] = $post;
}

db_set_active();

foreach($posts_array as $post){
$newnode = new stdClass();
$newnode->title = $post[‘title’];
$newnode->type = «blog»;

node_object_prepare($newnode);
$newnode->language = «und»;
$newnode->uid = (isset($users_relation[$post[‘created_by’]]) ? $users_relation[$post[‘created_by’]] : $users_relation[25]);
$newnode->status = 1; //(1 or 0): published or not
$newnode->promote = 0; //(1 or 0): promoted to front page

$post[‘content’] = trim($post[‘content’]);

$newnode->body[$newnode->language][0][‘value’] = ((empty($post[‘content’])) ? $post[‘intro’] : $post[‘content’]);
$newnode->body[LANGUAGE_NONE][0][‘format’] = ‘full_html’;

$post[‘image’] = trim($post[‘image’]);
if(!empty($post[‘image’])){
$image_options = explode(‘:’,$post[‘image’]);
$base_url = ‘/var/www/vhosts/innovaev2/htdocs/images/’;
switch ($image_options[0]){
case «user»:
$base_url .= «easyblog_images/»;
break;
case «post»:
$base_url .= «easyblog_articles/»;
break;
}
$image_path = $base_url . $image_options[1];
$image_info = image_get_info($image_path);

echo ‘

';
			var_dump($image_path);
			var_dump($image_info);
			echo '

‘;

$file = new StdClass();
$file->uid = $accounts->uid;
$file->uri = $image_path;
$file->filemime = $image_info[‘mime_type’];
$file->status = 0;
$file->filesize = $image_info[‘file_size’];
mkdir(«public://blog_images»);
$dest = «public://blog_images/» . $image_options[1];
mkdir(dirname(«/var/www/vhosts/dashboard.innovae.com/htdocs/sites/default/files/blog_images/» . $image_options[1]));
$file = file_copy($file, $dest);

$newnode->field_image[LANGUAGE_NONE][0] = (array)$file;
}

db_set_active(‘older’);

$to_import = db_query(«SELECT * FROM `obixc_easyblog_post_category` WHERE `post_id` = ‘» . $post[‘id’] . «‘»);

$posts_tags = array();
while ($tag = $to_import->fetchAssoc()) {
$posts_tags[] = $tag;
}

db_set_active();

foreach($posts_tags as $tag){
$newnode->field_categor_a_blog[$newnode->language][0][‘tid’] = $categories_relation[$tag[‘category_id’]];
}

db_set_active(‘older’);

$to_import = db_query(«SELECT * FROM `obixc_easyblog_post_tag` WHERE `post_id` = ‘» . $post[‘id’] . «‘»);

$posts_tags = array();
while ($tag = $to_import->fetchAssoc()) {
$posts_tags[] = $tag;
}

db_set_active();

foreach($posts_tags as $tag){
$newnode->field_tags[$newnode->language][0][‘tid’] = $tax_relation[$tag[‘tag_id’]];
}

$newnode->created = $post[‘publish_up’];
$newnode->date = $post[‘publish_up’];
$newnode->path = array(‘alias’ => «blog/» . $post[‘permalink’]);
$newnode = node_submit($newnode); // Prepare node for saving
node_save($newnode);
}
?>