milardovich

Holly shit!

Apr 28th, 2011
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.50 KB | None | 0 0
  1. <?php
  2. /*
  3.  * Migrador de kleo a wordpress
  4.  * Por Sergio Milardovich
  5.  * Este script es un asco
  6.  */
  7.     error_reporting(E_ALL);
  8.     $db_host = 'localhost';
  9.     $db_user = 'root';
  10.     $db_pass = '';
  11.     $db_wp_name = 'wordpress';
  12.     $db_kleo_name = 'milablog';
  13.     mysql_connect($db_host,$db_user,$db_pass);
  14.  
  15.     /*
  16.      * Agregar las categorías 
  17.      */
  18.     echo "\n Agregando categorías... \n";
  19.     mysql_select_db($db_wp_name);
  20.     echo "\t Formateando wordpress... \n";
  21.     mysql_query("TRUNCATE TABLE `wp_term_relationships`");
  22.     mysql_query("TRUNCATE TABLE `wp_posts`");
  23.     mysql_query("TRUNCATE TABLE `wp_terms`");
  24.     mysql_select_db($db_kleo_name);
  25.     $query = mysql_query("SELECT * FROM kleo_topics ORDER BY topicid ASC");
  26.     $i=1;
  27.     while($row = mysql_fetch_array($query)){
  28.         mysql_select_db($db_wp_name);
  29.         $name = $row['tname'];
  30.         $slug = strtolower(str_replace(" ","_",$row['tname']));
  31.         mysql_query("INSERT INTO  `wp_terms` (
  32.             `term_id` ,
  33.             `name` ,
  34.             `slug` ,
  35.             `term_group`
  36.         ) VALUES (
  37.             NULL ,  '$name',  '$slug',  '0'
  38.         );
  39.         ");
  40.         echo 'Agregando categoría "'.$name.'"'."\n";
  41.         mysql_query("INSERT INTO `wp_term_taxonomy` (`term_taxonomy_id`, `term_id`, `taxonomy`, `description`, `parent`, `count`) VALUES (NULL, '$i', 'Category', '', '0', '0');");
  42.         echo "\t".'Agregando taxonomías...'."\n";
  43.         $i++;
  44.     }
  45.     /*
  46.      * Agregar los posts
  47.      */
  48.     echo "\n \t Volcando los posts... \n";
  49.     mysql_select_db($db_kleo_name);
  50.     $query = mysql_query("SELECT * FROM kleo_blog ORDER BY id DESC");
  51.     $i=1;
  52.     while($row = mysql_fetch_array($query)){
  53.         $post_title = $row['title'];
  54.         $post_name = strtolower(str_replace(" ","_",$post_title));
  55.         $post_content = mysql_escape_string($row['content']);
  56.         $author = $row['aid'];
  57.         switch($row['type']){
  58.             case '2':
  59.                 $post_type = 'page';
  60.             break;
  61.             default:
  62.                 $post_type = 'post';
  63.             break;
  64.         }
  65.         $post_date = $row['posted'];
  66.         $post_date_gmt = $row['posted'];
  67.         $id = $row['id'];
  68.         mysql_select_db($db_kleo_name);
  69.         $aquery = mysql_query("SELECT * FROM kleo_assoc WHERE associtem = $id AND assoctype = 1");
  70.         $tkrow = mysql_fetch_array($aquery);
  71.         $tid = $tkrow['assoctopic'];
  72.         mysql_select_db($db_wp_name);
  73.         while($arow = mysql_fetch_array($aquery)){
  74.             mysql_select_db($db_kleo_name);
  75.             $tkquery = mysql_query("SELECT * FROM kleo_topics WHERE topicid = $tid");
  76.             $tkrow = mysql_fetch_array($tkquery);
  77.             $tname = $tkrow['tname'];
  78.             mysql_select_db($db_wp_name);
  79.             $tquery = mysql_query("SELECT * FROM wp_terms WHERE name = '$tname' LIMIT 1");
  80.             $trow = mysql_fetch_array($tquery);
  81.             $taxid = $trow['term_id'];
  82.             echo "\t Volcando asociaciones de este post...";
  83.             mysql_query("INSERT INTO  `wp_term_relationships` (
  84.                 `object_id` ,
  85.                 `term_taxonomy_id` ,
  86.                 `term_order`
  87.             ) VALUES (
  88.                 '$i',  '$taxid',  '1'
  89.             );");
  90.  
  91.         }
  92.         echo "Volcando el post número $i... \n";
  93.         mysql_select_db($db_wp_name);
  94.         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');");
  95.         $i++;
  96.     }
  97.     echo "\n\n Éxitos totales! \n\n";
  98.  
  99. ?>
Advertisement
Add Comment
Please, Sign In to add comment