home *** CD-ROM | disk | FTP | other *** search
/ MacAddict 108 / MacAddict108.iso / Software / Internet & Communication / WordPress 1.5.1.dmg / wordpress / wp-admin / import-textpattern.php < prev    next >
Encoding:
PHP Script  |  2005-04-19  |  4.9 KB  |  139 lines

  1. <?php
  2.  
  3. // For security reasons, fill in the connection details to your Textpattern database below:
  4.  
  5. $tp_database_name = 'textpattern';
  6. $tp_database_username = 'username';
  7. $tp_database_password = 'password';
  8. $tp_database_host = 'localhost';
  9.  
  10. if (!file_exists('../wp-config.php')) die("There doesn't seem to be a wp-config.php file. Double check that you updated wp-config-sample.php with the proper database connection information and renamed it to wp-config.php.");
  11. require('../wp-config.php');
  12. require('upgrade-functions.php');
  13.  
  14. $step = $_GET['step'];
  15. if (!$step) $step = 0;
  16. header( 'Content-Type: text/html; charset=utf-8' );
  17. ?>
  18. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  19. <html xmlns="http://www.w3.org/1999/xhtml">
  20. <title>WordPress › Textpattern Import</title>
  21. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  22. <style media="screen" type="text/css">
  23.     body {
  24.         font-family: Georgia, "Times New Roman", Times, serif;
  25.         margin-left: 15%;
  26.         margin-right: 15%;
  27.     }
  28.     #logo {
  29.         margin: 0;
  30.         padding: 0;
  31.         background-image: url(http://wordpress.org/images/wordpress.gif);
  32.         background-repeat: no-repeat;
  33.         height: 60px;
  34.         border-bottom: 4px solid #333;
  35.     }
  36.     #logo a {
  37.         display: block;
  38.         text-decoration: none;
  39.         text-indent: -100em;
  40.         height: 60px;
  41.     }
  42.     p {
  43.         line-height: 140%;
  44.     }
  45.     </style>
  46. </head><body> 
  47. <h1 id="logo"><a href="http://wordpress.org">WordPress</a></h1> 
  48. <?php
  49. switch($step) {
  50.  
  51.     case 0:
  52. ?> 
  53. <p>This script imports your entries from Textpattern into WordPress. It should be relatively painless, and we hope you're happy with the result.</p>
  54. <p>To run this, you first need to edit this file (<code>import-textpattern.php</code>) and enter your Textpattern database connection details. Let's check if the database connection information works...</p>
  55. <?php
  56. $connection = @mysql_connect($tp_database_host, $tp_database_username, $tp_database_password);
  57. $database = @mysql_select_db($tp_database_name);
  58. if ($connection && $database) {
  59. ?>
  60. <p>Everything seems dandy so far, <a href="?step=1">let's get started</a>!</p>
  61. <?php
  62. } else {
  63. ?>
  64. <p><em>It looks like your database information is incorrect. Please re-edit this file and double-check all the settings.</em></p>
  65. <?php
  66. }
  67.     break;
  68.     
  69.     case 1:
  70. ?> 
  71. <h1>Step 1</h1> 
  72. <p>First let's get posts and comments.</p> 
  73. <?php
  74. // For people running this on .72
  75. $query = "ALTER TABLE `$wpdb->posts` ADD `post_name` VARCHAR(200) NOT NULL";
  76. maybe_add_column($wpdb->posts, 'post_name', $query);
  77.  
  78. // Create post_name field
  79. $connection = @mysql_connect($tp_database_host, $tp_database_username, $tp_database_password);
  80. $database = @mysql_select_db($tp_database_name);
  81.  
  82. // For now we're going to give everything the same author and same category
  83. $author = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_level = 10 LIMIT 1");
  84. $category = $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories LIMIT 1");
  85.  
  86. $posts = mysql_query('SELECT * FROM textpattern', $connection);
  87.  
  88. while ($post = mysql_fetch_array($posts)) {
  89.     //  ID, AuthorID, LastMod, LastModID, Posted, Title, Body, Body_html, Abstract, Category1, Category2, Annotate, AnnotateInvite, Status, Listing1, Listing2, Section
  90.     $posted = $post['Posted'];
  91.     // 20030216162119
  92.     $year = substr($posted,0,4);
  93.     $month = substr($posted,4,2);
  94.     $day = substr($posted,6,2);
  95.     $hour = substr($posted,8,2);
  96.     $minute = substr($posted,10,2);
  97.     $second = substr($posted,12,2);
  98.     $timestamp = mktime($hour, $minute, $second, $month, $day, $year);
  99.     $posted = date('Y-m-d H:i:s', $timestamp);
  100.     
  101.     $content = addslashes($post['Body_html']);
  102.     $title = addslashes($post['Title']);
  103.     $post_name = sanitize_title($title);
  104.  
  105.     $wpdb->query("INSERT INTO $wpdb->posts
  106.         (post_author, post_date, post_content, post_title, post_category, post_name, post_status)
  107.         VALUES
  108.         ('$author', '$posted', '$content', '$title', '$category', '$post_name', 'publish')");
  109.  
  110.     // Get wordpress post id
  111.     $wp_post_ID = $wpdb->get_var("SELECT ID FROM $wpdb->posts ORDER BY ID DESC LIMIT 1");
  112.     
  113.     // Now let's insert comments if there are any for the TP post
  114.     $tp_id = $post['ID'];
  115.     $comments = mysql_query("SELECT * FROM txp_Discuss WHERE parentid = $tp_id");
  116.     if ($comments) {
  117.         while($comment = mysql_fetch_object($comments)) {
  118.             //  discussid, parentid, name, email, web, ip, posted, message
  119.             // For some reason here "posted" is a real MySQL date, so we don't have to do anything about it
  120.             //  comment_post_ID       comment_author       comment_author_email       comment_author_url       comment_author_IP       comment_date       comment_content       comment_karma
  121.             $wpdb->query("INSERT INTO $wpdb->comments
  122.                 (comment_post_ID, comment_author, comment_author_email, comment_author_url, comment_author_IP, comment_date, comment_content)
  123.                 VALUES
  124.                 ($wp_post_ID, '$comment->name', '$comment->email', '$comment->web', '$comment->ip', '$comment->posted', '$comment->message')");
  125.         }
  126.     }
  127. }
  128.  
  129. upgrade_all();
  130. ?>
  131. <p><strong>All done.</strong> Wasn’t that fun? <a href="../">Have fun</a>.</p> 
  132. <?php
  133. break;
  134. }
  135. ?> 
  136.  
  137. </body>
  138. </html>
  139.