PageRenderTime 43ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/1.5.1.1/wp-admin/import-greymatter.php

#
PHP | 322 lines | 307 code | 14 blank | 1 comment | 15 complexity | 33c32cb9539cfc23c1c3b709430d70eb MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-2.0, LGPL-2.1, GPL-2.0
  1. <?php
  2. if (!file_exists('../wp-config.php')) die("There doesn't seem to be a wp-config.php file. You must install WordPress before you import any entries.");
  3. require_once('../wp-config.php');
  4. require('upgrade-functions.php');
  5. $wpvarstoreset = array('action', 'gmpath', 'archivespath', 'lastentry');
  6. for ($i=0; $i<count($wpvarstoreset); $i += 1) {
  7. $wpvar = $wpvarstoreset[$i];
  8. if (!isset($$wpvar)) {
  9. if (empty($_POST["$wpvar"])) {
  10. if (empty($_GET["$wpvar"])) {
  11. $$wpvar = '';
  12. } else {
  13. $$wpvar = $_GET["$wpvar"];
  14. }
  15. } else {
  16. $$wpvar = $_POST["$wpvar"];
  17. }
  18. }
  19. }
  20. header( 'Content-Type: text/html; charset=utf-8' );
  21. ?>
  22. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  23. <html xmlns="http://www.w3.org/1999/xhtml">
  24. <title>WordPress &rsaquo; Import from GreyMatter</title>
  25. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  26. <style media="screen" type="text/css">
  27. body {
  28. font-family: Georgia, "Times New Roman", Times, serif;
  29. margin-left: 20%;
  30. margin-right: 20%;
  31. }
  32. #logo {
  33. margin: 0;
  34. padding: 0;
  35. background-image: url(http://wordpress.org/images/logo.png);
  36. background-repeat: no-repeat;
  37. height: 60px;
  38. border-bottom: 4px solid #333;
  39. }
  40. #logo a {
  41. display: block;
  42. text-decoration: none;
  43. text-indent: -100em;
  44. height: 60px;
  45. }
  46. p {
  47. line-height: 140%;
  48. }
  49. #authors li {
  50. padding:3px;
  51. border: 1px solid #ccc;
  52. width: 40%;
  53. margin-bottom:2px;
  54. }
  55. </style>
  56. </head><body>
  57. <h1 id="logo"><a href="http://wordpress.org">WordPress</a></h1>
  58. <?php
  59. switch ($action) {
  60. case "step1":
  61. function gm2autobr($string) { // transforms GM's |*| into wp's <br />\n
  62. $string = str_replace("|*|","<br />\n",$string);
  63. return($string);
  64. }
  65. if (!@chdir($archivespath))
  66. die("Wrong path, $archivespath\ndoesn't exist\non the server");
  67. if (!@chdir($gmpath))
  68. die("Wrong path, $gmpath\ndoesn't exist\non the server");
  69. ?>
  70. <p>The importer is running...</p>
  71. <ul>
  72. <li>importing users... <ul><?php
  73. chdir($gmpath);
  74. $userbase = file("gm-authors.cgi");
  75. foreach($userbase as $user) {
  76. $userdata=explode("|", $user);
  77. $user_ip="127.0.0.1";
  78. $user_domain="localhost";
  79. $user_browser="server";
  80. $s=$userdata[4];
  81. $user_joindate=substr($s,6,4)."-".substr($s,0,2)."-".substr($s,3,2)." 00:00:00";
  82. $user_login=addslashes($userdata[0]);
  83. $pass1=addslashes($userdata[1]);
  84. $user_nickname=addslashes($userdata[0]);
  85. $user_email=addslashes($userdata[2]);
  86. $user_url=addslashes($userdata[3]);
  87. $user_joindate=addslashes($user_joindate);
  88. $loginthere = $wpdb->get_var("SELECT user_login FROM $wpdb->users WHERE user_login = '$user_login'");
  89. if ($loginthere) {
  90. echo "<li>user <i>$user_login</i>... <b>Already exists</b></li>";
  91. continue;
  92. }
  93. $query = "INSERT INTO $wpdb->users (user_login,user_pass,user_nickname,user_email,user_url,user_ip,user_domain,user_browser,user_registered,user_level,user_idmode) VALUES ('$user_login','$pass1','$user_nickname','$user_email','$user_url','$user_ip','$user_domain','$user_browser','$user_joindate','1','nickname')";
  94. $result = $wpdb->query($query);
  95. if ($result==false) {
  96. die ("<strong>ERROR</strong>: couldn't register an user!");
  97. }
  98. echo "<li>user <i>$user_login</i>... <b>Done</b></li>";
  99. }
  100. ?></ul><b>Done</b></li>
  101. <li>importing posts, comments, and karma...<br /><ul><?php
  102. chdir($archivespath);
  103. for($i = 0; $i <= $lastentry; $i = $i + 1) {
  104. $entryfile = "";
  105. if ($i<10000000) {
  106. $entryfile .= "0";
  107. if ($i<1000000) {
  108. $entryfile .= "0";
  109. if ($i<100000) {
  110. $entryfile .= "0";
  111. if ($i<10000) {
  112. $entryfile .= "0";
  113. if ($i<1000) {
  114. $entryfile .= "0";
  115. if ($i<100) {
  116. $entryfile .= "0";
  117. if ($i<10) {
  118. $entryfile .= "0";
  119. }}}}}}}
  120. $entryfile .= "$i";
  121. if (is_file($entryfile.".cgi")) {
  122. $entry=file($entryfile.".cgi");
  123. echo "<li>entry # $entryfile ";
  124. $postinfo=explode("|",$entry[0]);
  125. $postmaincontent=gm2autobr($entry[2]);
  126. $postmorecontent=gm2autobr($entry[3]);
  127. $post_author=trim(addslashes($postinfo[1]));
  128. // we'll check the author is registered, or if it's a deleted author
  129. $sql = "SELECT * FROM $wpdb->users WHERE user_login = '$post_author'";
  130. $result = $wpdb->query($sql);
  131. if (! $result) { // if deleted from GM, we register the author as a level 0 user in wp
  132. $user_ip="127.0.0.1";
  133. $user_domain="localhost";
  134. $user_browser="server";
  135. $user_joindate="1979-06-06 00:41:00";
  136. $user_login=addslashes($post_author);
  137. $pass1=addslashes("password");
  138. $user_nickname=addslashes($post_author);
  139. $user_email=addslashes("user@deleted.com");
  140. $user_url=addslashes("");
  141. $user_joindate=addslashes($user_joindate);
  142. $query = "INSERT INTO $wpdb->users (user_login,user_pass,user_nickname,user_email,user_url,user_ip,user_domain,user_browser,user_registered,user_level,user_idmode) VALUES ('$user_login','$pass1','$user_nickname','$user_email','$user_url','$user_ip','$user_domain','$user_browser','$user_joindate','0','nickname')";
  143. $result = $wpdb->query($query);
  144. if ($result==false) {
  145. die ("<strong>ERROR</strong>: couldn't register an user!");
  146. }
  147. echo ": registered deleted user <i>$user_login</i> at level 0 ";
  148. }
  149. $sql = "SELECT ID FROM $wpdb->users WHERE user_login = '$post_author'";
  150. $post_author_ID = $wpdb->get_var($sql);
  151. $post_title=gm2autobr($postinfo[2]);
  152. $post_title=addslashes($post_title);
  153. $postyear=$postinfo[6];
  154. $postmonth=zeroise($postinfo[4],2);
  155. $postday=zeroise($postinfo[5],2);
  156. $posthour=zeroise($postinfo[7],2);
  157. $postminute=zeroise($postinfo[8],2);
  158. $postsecond=zeroise($postinfo[9],2);
  159. if (($postinfo[10]=="PM") && ($posthour!="12"))
  160. $posthour=$posthour+12;
  161. $post_date="$postyear-$postmonth-$postday $posthour:$postminute:$postsecond";
  162. $post_content=$postmaincontent;
  163. if (strlen($postmorecontent)>3)
  164. $post_content .= "<!--more--><br /><br />".$postmorecontent;
  165. $post_content=addslashes($post_content);
  166. $post_karma=$postinfo[12];
  167. $query = "INSERT INTO $wpdb->posts (post_author,post_date,post_content,post_title) VALUES ('$post_author_ID','$post_date','$post_content','$post_title')";
  168. $result = $wpdb->query($query);
  169. if (!$result)
  170. die ("Error in posting...");
  171. $query = "SELECT ID FROM $wpdb->posts ORDER BY ID DESC LIMIT 1";
  172. $post_ID = $wpdb->get_var($query);
  173. // Grab a default category.
  174. $post_category = $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories LIMIT 1");
  175. // Update the post2cat table.
  176. $exists = $wpdb->get_row("SELECT * FROM $wpdb->post2cat WHERE post_id = $post_ID AND category_id = $post_category");
  177. if (!$exists) {
  178. $wpdb->query("
  179. INSERT INTO $wpdb->post2cat
  180. (post_id, category_id)
  181. VALUES
  182. ($post_ID, $post_category)
  183. ");
  184. }
  185. $c=count($entry);
  186. if ($c>4) {
  187. for ($j=4;$j<$c;$j++) {
  188. $entry[$j]=gm2autobr($entry[$j]);
  189. $commentinfo=explode("|",$entry[$j]);
  190. $comment_post_ID=$post_ID;
  191. $comment_author=addslashes($commentinfo[0]);
  192. $comment_author_email=addslashes($commentinfo[2]);
  193. $comment_author_url=addslashes($commentinfo[3]);
  194. $comment_author_IP=addslashes($commentinfo[1]);
  195. $commentyear=$commentinfo[7];
  196. $commentmonth=zeroise($commentinfo[5],2);
  197. $commentday=zeroise($commentinfo[6],2);
  198. $commenthour=zeroise($commentinfo[8],2);
  199. $commentminute=zeroise($commentinfo[9],2);
  200. $commentsecond=zeroise($commentinfo[10],2);
  201. if (($commentinfo[11]=="PM") && ($commenthour!="12"))
  202. $commenthour=$commenthour+12;
  203. $comment_date="$commentyear-$commentmonth-$commentday $commenthour:$commentminute:$commentsecond";
  204. $comment_content=addslashes($commentinfo[12]);
  205. $sql3 = "INSERT INTO $wpdb->comments (comment_post_ID,comment_author,comment_author_email,comment_author_url,comment_author_IP,comment_date,comment_content) VALUES ('$comment_post_ID','$comment_author','$comment_author_email','$comment_author_url','$comment_author_IP','$comment_date','$comment_content')";
  206. $result3 = $wpdb->query($sql3);
  207. if (!$result3)
  208. die ("There is an error with the database, it can't store your comment..");
  209. }
  210. $comments=$c-4;
  211. echo ": imported $comments comment";
  212. if ($comments>1)
  213. echo "s";
  214. }
  215. echo "... <b>Done</b></li>";
  216. }
  217. }
  218. upgrade_all();
  219. ?>
  220. </ul><b>Done</b></li></ul>
  221. <p>&nbsp;</p>
  222. <p>Completed GM 2 WordPress import !</p>
  223. <p>Now you can go and <a href="wp-login.php">log in</a>, have fun !</p>
  224. <?php
  225. break;
  226. default:
  227. ?>
  228. <p>This is a basic GreyMatter to WordPress import script.</p>
  229. <p>What it does:</p>
  230. <ul>
  231. <li>parses gm-authors.cgi to import authors: everyone is imported at level 1</li>
  232. <li>parses the entries cgi files to import posts, comments, and karma on posts (although karma is not used on WordPress); if authors are found not to be in gm-authors.cgi, imports them at level 0</li>
  233. </ul>
  234. <p>What it does not:</p>
  235. <ul>
  236. <li>parse gm-counter.cgi (what's the use of that file ?), gm-banlist.cgi, gm-cplog.cgi (you can make a CP log hack if you really feel like it, but I question the need of a CP log)</li>
  237. <li>import gm-templates. you'll start with the basic template wp.php</li>
  238. <li>doesn't keep entries on top</li>
  239. </ul>
  240. <h3>First step: Install WordPress</h3>
  241. <p>Install the WordPress blog as explained in the <a href="../readme.html" target="_blank">ReadMe</a>, then immediately come back here.</p>
  242. <form name="stepOne" method="get">
  243. <input type="hidden" name="action" value="step1" />
  244. <h3>Second step: Provide GreyMatter details</h3>
  245. <table cellpadding="0">
  246. <tr>
  247. <td>Path to GM files:</td>
  248. <td><input type="text" style="width:300px" name="gmpath" value="/home/my/site/cgi-bin/greymatter/" /></td>
  249. </tr>
  250. <tr>
  251. <td>Path to GM entries:</td>
  252. <td><input type="text" style="width:300px" name="archivespath" value="/home/my/site/cgi-bin/greymatter/archives/" /></td>
  253. </tr>
  254. </table>
  255. <p>This importer will search for files 00000001.cgi to 000-whatever.cgi, so you need to enter the number of the last GM post here. (If you don't know that number, just log into your FTP and look it up in the entries' folder)</p>
  256. <table>
  257. <tr>
  258. <td>Last entry's number:</td>
  259. <td><input type="text" name="lastentry" value="00000001" /></td>
  260. </tr>
  261. </table>
  262. <p>When you're ready, click OK to start importing: <input type="submit" name="submit" value="OK" class="search" /></p>
  263. </form>
  264. </body>
  265. </html>
  266. <?php
  267. break;
  268. }
  269. ?>