Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * Migrador de kleo a wordpress
- * Por Sergio Milardovich
- * Este script es un asco
- */
- error_reporting(E_ALL);
- $db_host = 'localhost';
- $db_user = 'root';
- $db_pass = '';
- $db_wp_name = 'wordpress';
- $db_kleo_name = 'milablog';
- mysql_connect($db_host,$db_user,$db_pass);
- /*
- * Agregar las categorías
- */
- echo "\n Agregando categorías... \n";
- mysql_select_db($db_wp_name);
- echo "\t Formateando wordpress... \n";
- mysql_query("TRUNCATE TABLE `wp_term_relationships`");
- mysql_query("TRUNCATE TABLE `wp_posts`");
- mysql_query("TRUNCATE TABLE `wp_terms`");
- mysql_select_db($db_kleo_name);
- $query = mysql_query("SELECT * FROM kleo_topics ORDER BY topicid ASC");
- $i=1;
- while($row = mysql_fetch_array($query)){
- mysql_select_db($db_wp_name);
- $name = $row['tname'];
- $slug = strtolower(str_replace(" ","_",$row['tname']));
- mysql_query("INSERT INTO `wp_terms` (
- `term_id` ,
- `name` ,
- `slug` ,
- `term_group`
- ) VALUES (
- NULL , '$name', '$slug', '0'
- );
- ");
- echo 'Agregando categoría "'.$name.'"'."\n";
- mysql_query("INSERT INTO `wp_term_taxonomy` (`term_taxonomy_id`, `term_id`, `taxonomy`, `description`, `parent`, `count`) VALUES (NULL, '$i', 'Category', '', '0', '0');");
- echo "\t".'Agregando taxonomías...'."\n";
- $i++;
- }
- /*
- * Agregar los posts
- */
- echo "\n \t Volcando los posts... \n";
- mysql_select_db($db_kleo_name);
- $query = mysql_query("SELECT * FROM kleo_blog ORDER BY id DESC");
- $i=1;
- while($row = mysql_fetch_array($query)){
- $post_title = $row['title'];
- $post_name = strtolower(str_replace(" ","_",$post_title));
- $post_content = mysql_escape_string($row['content']);
- $author = $row['aid'];
- switch($row['type']){
- case '2':
- $post_type = 'page';
- break;
- default:
- $post_type = 'post';
- break;
- }
- $post_date = $row['posted'];
- $post_date_gmt = $row['posted'];
- $id = $row['id'];
- mysql_select_db($db_kleo_name);
- $aquery = mysql_query("SELECT * FROM kleo_assoc WHERE associtem = $id AND assoctype = 1");
- $tkrow = mysql_fetch_array($aquery);
- $tid = $tkrow['assoctopic'];
- mysql_select_db($db_wp_name);
- while($arow = mysql_fetch_array($aquery)){
- mysql_select_db($db_kleo_name);
- $tkquery = mysql_query("SELECT * FROM kleo_topics WHERE topicid = $tid");
- $tkrow = mysql_fetch_array($tkquery);
- $tname = $tkrow['tname'];
- mysql_select_db($db_wp_name);
- $tquery = mysql_query("SELECT * FROM wp_terms WHERE name = '$tname' LIMIT 1");
- $trow = mysql_fetch_array($tquery);
- $taxid = $trow['term_id'];
- echo "\t Volcando asociaciones de este post...";
- mysql_query("INSERT INTO `wp_term_relationships` (
- `object_id` ,
- `term_taxonomy_id` ,
- `term_order`
- ) VALUES (
- '$i', '$taxid', '1'
- );");
- }
- echo "Volcando el post número $i... \n";
- mysql_select_db($db_wp_name);
- mysql_query("INSERT INTO `wp_posts` (`ID`, `post_author`, `post_date`, `post_date_gmt`, `post_content`, `post_title`, `post_excerpt`, `post_status`, `comment_status`, `ping_status`, `post_password`, `post_name`, `to_ping`, `pinged`, `post_modified`, `post_modified_gmt`, `post_content_filtered`, `post_parent`, `guid`, `menu_order`, `post_type`, `post_mime_type`, `comment_count`) VALUES (NULL, '$author', '$post_date', '$post_date_gmt', '$post_content', '$post_title', '', 'publish', 'open', 'open', '', '$post_name', '', '', '0000-00-00 00:00:00', '0000-00-00 00:00:00', '', '0', '', '0', '$post_type', '', '0');");
- $i++;
- }
- echo "\n\n Éxitos totales! \n\n";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment