PageRenderTime 56ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

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

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