pastebin

Paste Search Dynamic
Recent pastes
PHPslash import
  1. <?php
  2.  
  3.    // PHPslash import code written by Jon Masters
  4.    // Now based upon import-mt.php
  5.  
  6.    // Configurable parameters for existing phpslash database:
  7.  
  8.    $dbuser     = "";              // PHPslash username
  9.    $dbpassword = "";              // PHPslash password
  10.    $dbhost     = "";              // PHPslash hostname
  11.    $dbdb       = "";              // PHPslash database
  12.  
  13.    // end of configuration parameters.
  14.    //
  15.    // History:
  16.    //
  17.    // 2005/01/06 - Initial release just to get wordpress working my blog :-).
  18.  
  19. if (!file_exists('../wp-config.php')) {
  20.    die("There doesn't seem to be a wp-config.php file." .
  21.    "You must install Wordpress before you import any entries.");
  22. }
  23.  
  24. require('../wp-config.php');
  25.  
  26. $step = $HTTP_GET_VARS['step'];
  27. if (!step) $step = 0;
  28.  
  29. ?>
  30.  
  31. <!!DOCTYPE html public "-//W3C//DTD XHTML 1.0 Transitional//EN"
  32.    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  33. <html xmlns="http://www.w3.org/1999/xhtml">
  34. <title>WordPress &rsaquo; Import from PHP Slash</title>
  35. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  36. <style media="screen" type="text/css">
  37.         body {
  38.                 font-family: Georgia, "Times New Roman", Times, serif;
  39.                 margin-left: 20%;
  40.                 margin-right: 20%;
  41.              }
  42.         #logo {
  43.                 margin: 0;
  44.                 padding: 0;
  45.                 background-image: url(http://wordpress.org/images/logo.png);
  46.                 background-repeat: no-repeat;
  47.                 height: 60px;
  48.                 border-bottom: 4px solid #333;
  49.         }
  50.         #logo a {
  51.                 display: block;
  52.                 text-decoration: none;
  53.                 text-indent: -100em;
  54.                 height: 60px;
  55.         }
  56.         p {
  57.                 line-height: 140%;
  58.         }
  59.         #authors li     {
  60.                 padding:3px;
  61.                 border: 1px solid #ccc;
  62.                 width: 40%;
  63.                 margin-bottom:2px;
  64.         }
  65.         </style>
  66.  
  67. </head>
  68.    <body>
  69.       <h1 id="logo"><a href="http://wordpress.org">WordPress</a></h1>
  70. <?php
  71. switch($step) {
  72.  
  73.    case 0:
  74. ?>
  75.  
  76.       <p>Howdy! We&#8217;re about to begin the process to import all of your
  77.          PHP Slash entries into WordPress. Before we get started, you need to
  78.          edit this file (<code>import-phpslash.php</code>) and change a couple
  79.          of lines so we know where to find your phpslash database.</p>
  80.  
  81.       <p>If you've done that and you&#8217;re all ready,
  82.         <a href="import-phpslash.php?step=1">let's go</a>!
  83.  
  84.          Remember that the import process may take a minute or so if you have a
  85.          large number of entries and comments. Think of all the rebuilding time
  86.          you'll be saving once it's done. :)</p>
  87.  
  88. <?php
  89.  
  90.       break;
  91.  
  92.    case 1:
  93.  
  94. ?>
  95.  
  96.       <p>We will now try to import your PHPslash stories in to WordPress.
  97.          Watch the following output to see how it goes.</p>
  98.       <p>
  99.  
  100. <?php
  101.  
  102.  
  103.       $phpslash_dbh = @mysql_connect($dbhost, $dbuser, $dbpassword);
  104.      
  105.       if (!$phpslash_dbh) {
  106.          die("<div>
  107.         <p><strong>Error establishing a database connection!</strong>
  108.         This probably means that the connection information in your
  109.         <code>import-phpslash.php</code> file is incorrect.
  110.         Double check it and try again.</p>
  111.         <ul>
  112.            <li>Are you sure you have the correct user/password?</li>
  113.            <li>Are you sure that you have typed the correct hostname?</li>
  114.            <li>Are you sure that the database server is running?</li>
  115.         </ul>
  116.         <p><a href='http://wordpress.org/support/'>WordPress Support Forums</a>
  117.         </p></div>");
  118.       }
  119.  
  120.       if (!@mysql_select_db($dbdb,$phpslash_dbh)) {
  121.          die("
  122.         <p>We're having a little trouble selecting the PHPslash database.</p>
  123.         <ul>
  124.            <li>Are you sure it exists?</li>
  125.            <li>Your database name is currently specified as
  126.                <code>dbname</code>. Is this correct?</li>
  127.            <li>On some systems the name of your database is prefixed with your
  128.                username, so it would be like username_phpslash.
  129.                Could that be the problem?</li>
  130.         </ul>
  131.         <p><a href='http://wordpress.org/support/'>WordPress Support Forums</a></p>");
  132.       }
  133.  
  134.       // Rip out the entries from PHPslash, matching up user names.
  135.  
  136.       $psl_story_query = mysql_query("SELECT psl_author.author_name, " .
  137.                                      "psl_story.title, psl_story.dept, " .
  138.                                      "psl_story.intro_text, " .
  139.                                      "psl_story.body_text, " .
  140.                                      "psl_story.date_available " .
  141.                                      "FROM psl_story LEFT JOIN psl_author ON " .
  142.                                      "psl_author.author_id=psl_story.user_id " .
  143.                         // for debugging use id=240
  144.                         // "WHERE psl_story.story_id="240"" .
  145.                                      "ORDER BY psl_story.story_id ASC;");
  146.       if (!$psl_story_query) {
  147.          die("Invalid query: " . mysql_error());
  148.       }
  149.  
  150.       while ($psl_story_entry = mysql_fetch_array($psl_story_query,
  151.                                                   MYSQL_ASSOC)) {
  152.  
  153.          $wordpress_entry['post_author']  =
  154.                                     $psl_story_entry['author_name'];
  155.          $wordpress_entry['post_title'] = $psl_story_entry['title'];
  156.          $wordpress_entry['post_category'] = 1; // FIXME
  157.          $wordpress_entry['post_content'] = "[ from the " .
  158.                                          $psl_story_entry['dept'] .
  159.                                          " dept. ]<br/><br/>" .
  160.                                          $psl_story_entry['intro_text'] .
  161.                                          "<br/><br/>" .
  162.                                          $psl_story_entry['body_text'];
  163.          $wordpress_entry['post_date'] = date("Y-m-d H:i:s",
  164.                                       $psl_story_entry['date_available']);
  165.          $wordpress_entry['post_date_gmt'] = $wordpress_entry['post_date'];
  166.          $wordpress_entry['post_modified'] = date("Y-m-d H:i:s");
  167.          $wordpress_entry['post_modified_gmt'] = gmdate("Y-m-d H:i:s");
  168.  
  169.          // Let's check to see if it's in already
  170.          if ($wpdb->get_var("SELECT ID FROM $tableposts WHERE post_title = " .
  171.                             ""{$wordpress_entry['post_title']}" " .
  172.                             "AND post_date = " .
  173.                             ""{$wordpress_entry['post_date']}"")) {
  174.  
  175.             echo "<strong>[IGNORED] " . $wordpress_entry['post_title'] .
  176.                  "</strong><br/>";
  177.  
  178.          } else {
  179.  
  180.            
  181.             // Find the corresponding author
  182.  
  183.             if ($user_id = $wpdb->get_var("SELECT ID FROM " .
  184.                                 "$tableusers WHERE user_login = " .
  185.                                 ""{$wordpress_entry['post_author']}"")) {
  186.  
  187.                $wordpress_entry['post_author'] = $user_id;
  188.                echo "<strong>[imported] " .
  189.                     "[ " . $psl_story_entry['author_name'] . "] " .
  190.                     $wordpress_entry['post_title'] .
  191.                     "</strong><br/>";
  192.             } else {
  193.                $wordpress_entry['post_author'] = 0; // general user
  194.                echo "<strong>[imported] " .
  195.                     "[general]" .
  196.                     $wordpress_entry['post_title'] .
  197.                     "</strong><br/>";
  198.             }
  199.  
  200.             $wpdb->query("INSERT INTO $tableposts (
  201.                         post_author, post_title, post_category,
  202.                          post_content, post_date, post_date_gmt,
  203.                          post_modified, post_modified_gmt)
  204.                         VALUES
  205.                         ("{$wordpress_entry['post_author']}",
  206.                          "{$wordpress_entry['post_title']}",
  207.                          "{$wordpress_entry['post_category']}",
  208.                          "{$wordpress_entry['post_content']}",
  209.                          "{$wordpress_entry['post_date']}",
  210.                          "{$wordpress_entry['post_date_gmt']}",
  211.                          "{$wordpress_entry['post_modified']}",
  212.                          "{$wordpress_entry['post_modified_gmt']}")");
  213.  
  214.             $post_id = $wpdb->get_var("SELECT ID FROM $tableposts WHERE " .
  215.                                       "post_title = "{$wordpress_entry['post_title']}" " .
  216.                                       "AND post_date = "{$wordpress_entry['post_date']}"");
  217.  
  218.             // FIXME: We just insert category 1 for the moment.
  219.  
  220.             $wpdb->query("INSERT INTO $tablepost2cat (
  221.                         post_id, category_id)
  222.                         VALUES
  223.                         ($post_id,
  224.                          "{$wordpress_entry['post_category']}")");
  225.  
  226.          }
  227.  
  228.       ?>
  229.  
  230.       <?php
  231.       }
  232.  
  233.       ?>
  234.      
  235.       </p>
  236.  
  237.       <p>That's all for now. If the above didn't show any error messages
  238.          then the imported data should now show up in your WordPress.
  239.       </p>
  240.  
  241.       <?php
  242.  
  243.       break;
  244.  
  245.    } /* switch(step) */
  246.  
  247.    ?>
  248.    <p>This is the PHPslash import script by <a href="/">Jon Masters</a>.</p>
  249.    </body>
  250. </html>
Parsed in 0.557 seconds