Hangar Import Drupal -> Wordpress

show_errors(); $sql = "SELECT * FROM node WHERE type='story' ORDER BY nid"; $nodes = $wpdb_drupal->get_results($sql); //print_r($nids); //echo count($nodes)."
"; $i=0; foreach ($nodes as $node) { //echo $nid->nid."
"; //get content of node $sql2 = "SELECT * FROM node_revisions WHERE nid=".$node->nid; $node_content = $wpdb_drupal->get_row($sql2); //get language information $sql3 = "SELECT * FROM localizernode WHERE nid=".$node->nid; $node_lang = $wpdb_drupal->get_row($sql3); if ($node->nid == $node_lang->pid){ //new base node -> create node object $n = new stdClass; $n->nid = $node->nid; $n->date = date('Y-m-d H:i:s',$node->created); $n->uid = $node->uid; } else { //translated node: $node->nid == $node->pid; $n = $langs[$node_lang->pid]; } //get language version switch ($node_lang->locale) { case 'ca': $n->title_ca = $node->title; $n->teaser_ca = $node_content->teaser; $n->body_ca = $node_content->body; break; case 'en': $n->title_en = $node->title; $n->teaser_en = $node_content->teaser; $n->body_en = $node_content->body; break; case 'es': $n->title_es = $node->title; $n->teaser_es = $node_content->teaser; $n->body_es = $node_content->body; break; } //-> save in associative array $langs[$n->nid] = $n; //echo "new node:".$n->nid."
"; //echo "- [".$n->nid."] ".$n->title_ca." - created:".$n->date." - user:[".$n->uid."] [".$node_lang->locale.'] '.$node_lang->pid.'
'.$n->teaser_ca.'
'; //.$n->body.'
'; //limit to few rows (for testing) //$i++; //if ($i == 500) break; } //print (or save) nodes foreach ($langs as $node) { if ($node->nid != ''){ echo "[".$node->nid."] - created:".$node->date." - user:[".$node->uid."]
"; echo "ca:".$node->title_ca."
"; //.$node->teaser_ca.'
'; echo "en:".$node->title_en."
"; //.$node->teaser_en.'
'; echo "es:".$node->title_es."
"; //.$node->teaser_es.'
'; //.$node->body_ca.'
'; $node->title = ''.$node->title_ca.''.$node->title_en.''.$node->title_es.''; $node->teaser = ''.$node->teaser_ca.''.$node->teaser_en.''.$node->teaser_es.''; $node->content = ''.$node->body_ca.''.$node->body_en.''.$node->body_es.''; //replace image route $node->teaser = str_replace("/drupal/sites/hangar.org/files", "http://hangar.org/webnou/wp-content/uploads/drupal", $node->teaser); $node->teaser = str_replace('teaser); $node->content = str_replace("/drupal/sites/hangar.org/files", "http://hangar.org/webnou/wp-content/uploads/drupal", $node->content); //insert posts into wordpress $post = array( 'comment_status' => 'closed', // 'closed' means no comments. 'ping_status' => 'closed', // 'closed' means pingbacks or trackbacks turned off 'post_author' => 11, //The user ID number of the author: 11=gerald 'post_category' => array(767), //Add some categories: 767=arxiu 'post_excerpt' => $node->teaser, //For all your post excerpt needs. 'post_date' => $node->date, //The time post was made. 'post_content' => $node->content, //The full text of the post. 'post_name' => $node->title_ca, // The name (slug) for your post 'post_status' => 'publish', //Set the status of the new post. 'post_title' => $node->title, //The title of your post. 'post_type' => 'post', //You may want to insert a regular post, page, etc. 'tags_input' => 'arxiu, drupal' //For tags. ); //write to WP //if ($node->nid == 1190 || $node->nid == 1293 || $node->nid == 1301) //echo "SAVED WITH ID:".wp_insert_post($post)."

"; } } ?>