
Шустрый

Профиль
Группа: Участник
Сообщений: 87
Регистрация: 25.10.2007
Репутация: -2 Всего: -15
|
dsCode, вот небольшой примерчек Код | <html> <head> <title>YaBB 1 Gold to YaBB SE Converter</title> <style> <!-- body { font-family : Verdana; font-size : 10pt; } td { font-size : 10pt; } --> </style> </head> <body bgcolor="#FFFFFF"> <center><table border=0 cellspacing=1 cellpadding=4 bgcolor="#000000" width=90%> <tr> <th bgcolor="#34699E"><font color="#FFFFFF">YaBB 1 Gold to YaBB SE Converter</font></th> </tr> <tr> <td bgcolor="#f0f0f0"> <?php
//Added to allow larger forums to convert without timing out - Jeff set_time_limit(0);
if (!$step) { ?> <?php } elseif($step == '1a') { $mode = ini_get("safe_mode"); ?> <form action="converter.php?step=1b" method="POST"> We are now determining whether PHP is currently running in safe mode.<p> <?php if ($mode) { ?> It appears that you are running in safe mode. While the conversion process will work for the most part, the following steps will be disabled to prevent errors. <ul> <li><i>template.html conversion</i> - you will have to manually replace your YaBB SE template.html</li> <li><i>Settings.pl conversion</i> - you will have to update Settings.php manually</li> </ul> The rest of the conversion should procede successfully though.<p> <?php } else { ?> It appears that safe mode is disabled. All conversion steps should be successful.<p> <?php } ?> <center> <input type=hidden name="from" value="intro"> <input type=submit value="Proceed >"> </center> </form> <?php
} if($step=='1b') { $y1gdir = $HTTP_SERVER_VARS["DOCUMENT_ROOT"]."/cgi-bin/YaBB"; $y1gdir = str_replace("//","/",$y1gdir); $boardsdir = "$y1gdir/Boards"; $membersdir = "$y1gdir/Members"; $datadir = "$y1gdir/Messages"; $vardir = "$y1gdir/Variables"; ?>
for ($i = 7; $i < sizeof($membergroupsFile); $i++) { if (trim($membergroupsFile[$i]) != '') { $membergroupsFile[$i] = mysql_escape_string(trim($membergroupsFile[$i])); $request = mysql_query("INSERT INTO {$dbprefix}membergroups (membergroup,grouptype) VALUES ('$membergroupsFile[$i]','1')"); if (mysql_affected_rows() < 0) print "<font color=red>Error editing table ({$dbprefix}membergroups). Unable to insert $membergroupsFile[$i]</font><br>"; else print "Editing table ({$dbprefix}membergroups). Inserting $membergroupsFile[$i]<br>"; } } unset ($membergroupsFile); ?> </td></tr></table> <center> <input type=hidden name="y1gdir" value="<?=$y1gdir?>"> <input type=hidden name="boardsdir" value="<?=$boardsdir?>"> <input type=hidden name="membersdir" value="<?=$membersdir?>"> <input type=hidden name="datadir" value="<?=$datadir?>"> <input type=hidden name="vardir" value="<?=$vardir?>"> <input type=hidden name="dbuser" value="<?=$dbuser?>"> <input type=hidden name="dbpassword" value="<?=$dbpassword?>"> <input type=hidden name="dbprefix" value="<?=$dbprefix?>"> <input type=hidden name="dbname" value="<?=$dbname?>"> <input type=hidden name="dbserver" value="<?=$dbserver?>"> <input type=hidden name="installdir" value="<?=$installdir?>"> <input type=submit value="Proceed >"> (Only proceed if successful!) </center> </form> <?php } elseif($step=="4") { ?> We are now going to attempt to convert your member data files.<br> <form action="converter.php?step=5" method="POST"> <table border=0 cellspacing=0 cellpadding=3> <tr><td> <?php $dh = opendir($membersdir); print "Importing Member Data:<br><blockquote>"; $users = array();
$dbcon = mysql_connect($dbserver, $dbuser, $dbpassword); mysql_select_db($dbname);
while (($file = readdir($dh)) !== false) { $extension = substr(strrchr($file, "."), 1); if ($extension != 'dat') { continue; }
$user = substr($file,0,strrpos($file,".")); $userData = file ("$membersdir/$file"); for ($i = 0; $i < sizeof($userData); $i++) $userData[$i] = mysql_escape_string(trim(htmlspecialchars($userData[$i]))); $password = crypt (stripcslashes($userData[0]),substr(stripcslashes($userData[0]),0,2)); if (strtotime(stripcslashes($userData[14])) == -1) { if (preg_match ("/(\d\d)\/(\d\d)\/(\d\d)(.*)(\d\d)\:(\d\d)\:(\d\d)/i", stripcslashes($userData[14]), $matches)) { $userData[14] = strtotime("$matches[5]:$matches[6]:$matches[7] $matches[1]/$matches[2]/$matches[3]"); } else { $userData[14] = time(); } } else { $userData[14] = strtotime(stripcslashes($userData[14])); } $birthdate = strtotime(stripcslashes($userData[16])); if ($birthdate > 0) { $tmp = getdate($birthdate); $userData[16] = "$tmp[year]-$tmp[mon]-$tmp[mday]"; } else { if (preg_match ("/(\d\d)\/(\d\d)\/(\d\d)(.*)(\d\d)\:(\d\d)\:(\d\d)/i", stripcslashes($userData[16]), $matches)) { $birthdate = strtotime("$matches[5]:$matches[6]:$matches[7] $matches[1]/$matches[2]/$matches[3]"); $tmp = getdate($birthdate); $userData[16] = "$tmp[year]-$tmp[mon]-$tmp[mday]"; } else { $userData[16] = ""; } } $userData[19] = $userData[19]=='checked'?'1':0; $userData[5] = str_replace("&&","\n",$userData[5]); $userData[5] = str_replace("&&","\n",$userData[5]); if ($userData[4] == 'Guest') {$userData[4] = $userData[1]; } $request = mysql_query("INSERT INTO {$dbprefix}members (memberName,passwd,realName,emailAddress,websiteTitle,websiteUrl,signature,posts,membergroup,ICQ,AIM,YIM,gender,personalText,avatar,dateRegistered,location,birthdate,timeOffset,hideEmail) VALUES ('$user','$password','$userData[1]','$userData[2]','$userData[3]','$userData[4]','$userData[5]','$userData[6]','$userData[7]','$userData[8]','$userData[9]','$userData[10]','$userData[11]','$userData[12]','$userData[13]','$userData[14]','$userData[15]','$userData[16]','$userData[18]','$userData[19]')"); if (mysql_error()=='') { print "$user added, "; $users[$user] = array($user,mysql_insert_id()); } else print "<font color=red>$user not added</font>, "; } print "</blockquote><p>Inserting Instant Messages<br><blockquote>"; closedir($dh); foreach($users as $user) { if (!file_exists("$membersdir/$user[0].msg")){ continue; } $data1 = file("$membersdir/$user[0].msg"); foreach ($data1 as $theData) { if (trim($theData) == '') { continue; } $data = explode("|",trim($theData));
$fromID = isset($users[$data[0]])?$users[$data[0]][1]:'-1'; $fromName = isset($users[$data[0]])?$users[$data[0]][0]:'Guest';
$data[1] = mysql_escape_string($data[1]);
if (strtotime($data[2]) == -1) { if (preg_match ("/(\d\d)\/(\d\d)\/(\d\d)(.*)(\d\d)\:(\d\d)\:(\d\d)/i", $data[2], $matches)) { $data[2] = strtotime("$matches[5]:$matches[6]:$matches[7] $matches[1]/$matches[2]/$matches[3]"); } else { $data[2] = time(); } } else { $data[2] = strtotime($data[2]); } $data[3] = mysql_escape_string( $data[3]);
if ($fromID != '-1') $request = mysql_query("INSERT INTO {$dbprefix}instant_messages (ID_MEMBER_FROM,ID_MEMBER_TO,fromName,toName,msgtime,subject,body,deletedBy) VALUES ('$fromID','$user[1]','$fromName','$user[0]','$data[2]','$data[1]','$data[3]','0')");
} print ("$user[0]'s im's, "); if (file_exists("$membersdir/$user[0].imconfig")) { $imFile = file ("$membersdir/$user[0].imconfig"); $imFile[0] = str_replace("|",",",trim($imFile)); $imFile[1] = (trim($imFile[1])=='')?'0':'1'; $request = mysql_query("UPDATE {$dbprefix}members SET im_email_notify='$imFile[1]',im_ignore_list='$imFile[0]' WHERE ID_MEMBER='$user[1]' LIMIT 1"); } } foreach($users as $user) { if (!file_exists("$membersdir/$user[0].karma")){ continue; } $data1 = file("$membersdir/$user[0].karma"); $field = (trim($data1[0])<0)?'karmaBad':'karmaGood'; $val = abs(trim($data1[0])); $request = mysql_query("UPDATE {$dbprefix}members SET $field='$val' WHERE ID_MEMBER='$user[1]' LIMIT 1"); print ("$user[0]'s karma, "); } print "</blockquote><br>"; ?> </td></tr></table> <center> <input type=hidden name="y1gdir" value="<?=$y1gdir?>"> <input type=hidden name="boardsdir" value="<?=$boardsdir?>"> <input type=hidden name="membersdir" value="<?=$membersdir?>"> <input type=hidden name="datadir" value="<?=$datadir?>"> <input type=hidden name="vardir" value="<?=$vardir?>"> <input type=hidden name="dbuser" value="<?=$dbuser?>"> <input type=hidden name="dbpassword" value="<?=$dbpassword?>"> <input type=hidden name="dbprefix" value="<?=$dbprefix?>"> <input type=hidden name="dbname" value="<?=$dbname?>"> <input type=hidden name="dbserver" value="<?=$dbserver?>"> <input type=hidden name="installdir" value="<?=$installdir?>"> <input type=submit value="Proceed >"> (Only proceed if successful!) </center> </form> <?php } elseif($step=="5") { ?> We are now going to attempt to convert your message files. This may take a while.<br> <form action="converter.php?step=6" method="POST"> <table border=0 cellspacing=0 cellpadding=3> <tr><td> <?php $dbcon = mysql_connect($dbserver, $dbuser, $dbpassword); mysql_select_db($dbname);
// first we need to load an array of all the members $dh = opendir($membersdir); print "Initializing member data for processing...."; $users = array(); while (($file = readdir($dh)) !== false) { $extension = substr(strrchr($file, "."), 1); if ($extension != 'dat') { continue; } $user = substr($file,0,strrpos($file,"."));
$request = mysql_query("SELECT ID_MEMBER FROM {$dbprefix}members WHERE memberName='$user' LIMIT 1"); $row = mysql_fetch_row($request); $users[$user] = array($user,$row[0]); } closedir($dh);
// now load an array of the sticky topics $stickyTopics = array(); if (file_exists("$boardsdir/$sticky.stk")) { foreach(file("$boardsdir/$sticky.stk") as $line) { if (trim($line)!= '') $stickyTopics[] = trim($line); } }
// now to create the categories $dh = opendir($boardsdir); $categories = array(); $boards = array(); while (($file = readdir($dh)) !== false) { list ($cat,$extension) = explode ('.',$file); if ($extension != 'cat') { continue; } // we are now only looping for the categories
$catFile = file ("$boardsdir/$file"); $catname = mysql_escape_string(trim($catFile[0])); $catmembergroups = mysql_escape_string(trim($catFile[1])); $request = mysql_query("INSERT INTO {$dbprefix}categories (name,memberGroups) VALUES ('$catname','$catmembergroups')"); $catid = mysql_insert_id(); $categories[$cat] = $catid;
print "Inserted category: $cat<br>"; // now we are going to loop though for every board for ($i = 2; $i < sizeof($catFile); $i++) { $curboard = trim($catFile[$i]); if ($curboard==''){ continue; }
$boardFile = file ("$boardsdir/$curboard.dat"); $boardname = mysql_escape_string(trim($boardFile[0])); $boarddesc = mysql_escape_string(trim($boardFile[1])); $boardmods = mysql_escape_string(trim(str_replace("|",",",$boardFile[2]))); $request = mysql_query("INSERT INTO {$dbprefix}boards (ID_CAT,name,description,moderators) VALUES ('$catid','$boardname','$boarddesc','$boardmods')"); $boardid = mysql_insert_id();
print " Inserted board: $boardname<br>"; // initialize the topics and posts count for later $numTopics = 0; $numPosts = 0;
// now loop through for all the topics $boardFile = file ("$boardsdir/$curboard.txt"); foreach ($boardFile as $boardFileEntry) { if (trim($boardFileEntry=='')){ continue; } $topicinfo = explode("|",trim($boardFileEntry)); $topicid = $topicinfo[0]; $locked = $topicinfo[8]; $topicinfo = file("$datadir/$topicid.data"); $numViews = trim($topicinfo[0]); $request = mysql_query("INSERT INTO {$dbprefix}topics (ID_BOARD,numViews,locked) VALUES ('$boardid','$numViews','$locked')"); $id_topic = mysql_insert_id();
$first = true; $numReplies = 0; $posterID = ''; $msgid = ''; // now to loop through for the messages $messageFile = file ("$datadir/$topicid.txt"); foreach($messageFile as $messageFileEntry) { if (trim($messageFileEntry)==''){ continue; } $messageinfo = explode("|",$messageFileEntry); for ($j = 0; $j < sizeof ($messageinfo); $j++) $messageinfo[$j] = mysql_escape_string(trim($messageinfo[$j])); $posterID = isset($users[$messageinfo[4]])?$users[$messageinfo[4]][1]:'-1';
// $messageinfo[3] = strtotime($messageinfo[3]);
if (strtotime($messageinfo[3]) == -1) { if (preg_match ("/(\d\d)\/(\d\d)\/(\d\d)(.*)(\d\d)\:(\d\d)\:(\d\d)/i", $messageinfo[3], $matches)) { $messageinfo[3] = strtotime("$matches[5]:$matches[6]:$matches[7] $matches[1]/$matches[2]/$matches[3]"); } else { $messageinfo[3] = time(); } } else { $messageinfo[3] = strtotime($messageinfo[3]); }
if (strtotime($messageinfo[11]) == -1) { if (preg_match ("/(\d\d)\/(\d\d)\/(\d\d)(.*)(\d\d)\:(\d\d)\:(\d\d)/i", $messageinfo[11], $matches)) { $messageinfo[11] = strtotime("$matches[5]:$matches[6]:$matches[7] $matches[1]/$matches[2]/$matches[3]"); } else { $messageinfo[11] = ''; } } else { $messageinfo[11] = strtotime($messageinfo[11]); }
$messageinfo[9] = !$messageinfo[9]; $messageinfo[4] = ($messageinfo[4]=='Guest')?$messageinfo[1]:$messageinfo[4]; $messageinfo[8] = preg_replace('/\[quote (.+?)]/i',"[quote]",$messageinfo[8]);
$request = mysql_query("INSERT INTO {$dbprefix}messages (ID_MEMBER,posterName,posterIP,posterEmail,posterTime,subject,body,smiliesEnabled,modifiedName,modifiedTime,icon,ID_TOPIC) VALUES ('$posterID','$messageinfo[4]','$messageinfo[7]','$messageinfo[2]','$messageinfo[3]','$messageinfo[0]','$messageinfo[8]','$messageinfo[9]','$messageinfo[11]','$messageinfo[10]','$messageinfo[5]','$id_topic')"); $msgid = mysql_insert_id();
if ($first) { $first = false; $request = mysql_query("UPDATE {$dbprefix}topics SET ID_FIRST_MSG='$msgid',ID_MEMBER_STARTED='$posterID' WHERE ID_TOPIC='$id_topic' LIMIT 1"); } else $numReplies ++; } // now, just for Andrea, we're going to try to import the notifies $notifies = array(); if (file_exists("$datadir/$topicid.mail")) { $notifyList = file ("$datadir/$topicid.mail"); foreach ($notifyList as $not) { $not = trim($not); $request = mysql_query("SELECT ID_MEMBER FROM {$dbprefix}members WHERE emailAddress='$not' LIMIT 1"); if (mysql_num_rows($request) > 0) { $row = mysql_fetch_row($request); $notifies[] = $row[0]; } } } $notify = (sizeof($notifies) > 0) ? implode(",",$notifies) : '';
// and now we'll try to do sticky topics $isSticky = (sizeof($stickyTopics) > 0 && in_array($topicid,$stickyTopics))?1:0;
$request = mysql_query("UPDATE {$dbprefix}topics SET ID_LAST_MSG='$msgid',ID_MEMBER_UPDATED='$posterID',numReplies='$numReplies',notifies='$notify',isSticky='$isSticky' WHERE ID_TOPIC='$id_topic' LIMIT 1"); $request = mysql_query("UPDATE {$dbprefix}boards SET numPosts=numPosts+$numReplies+1,numTopics=numTopics+1 WHERE ID_BOARD='$boardid' LIMIT 1"); } } }
closedir($dh); ?> </td></tr></table> <center> <input type=hidden name="y1gdir" value="<?=$y1gdir?>"> <input type=hidden name="boardsdir" value="<?=$boardsdir?>"> <input type=hidden name="membersdir" value="<?=$membersdir?>"> <input type=hidden name="datadir" value="<?=$datadir?>"> <input type=hidden name="vardir" value="<?=$vardir?>"> <input type=hidden name="dbuser" value="<?=$dbuser?>"> <input type=hidden name="dbpassword" value="<?=$dbpassword?>"> <input type=hidden name="dbprefix" value="<?=$dbprefix?>"> <input type=hidden name="dbname" value="<?=$dbname?>"> <input type=hidden name="dbserver" value="<?=$dbserver?>"> <input type=hidden name="installdir" value="<?=$installdir?>"> <input type=submit value="Proceed >"> (Only proceed if successful!) </center> </form> <?php } elseif($step=="7") { ?> We are now copying your selections<br> <table border=0 cellspacing=0 cellpadding=3> <tr><td> <?php $mode = ini_get("safe_mode"); if (isset($copyt) && !$mode) { if (copy("$y1gdir/template.html","$installdir/template.html")) print "template.html copied successfully.<br>"; else print "<font color=red>template.html copy failed.</font><br>"; }
$settingsArray = file("$installdir/Settings.php"); $url = ""; for($i = 0; $i < sizeof($settingsArray); $i++) { foreach ($copiedSettings as $set => $val) { $set = str_replace("{'","['",$set); $set = str_replace("'}","']",$set); if (substr($settingsArray[$i],1,strlen($set))==$set) { $settingsArray[$i] = preg_replace("/=(.*);/","= $val;",$settingsArray[$i],1); print "Replaced value of $set..with $val <br>"; continue; } } }
$fp = fopen("$installdir/Settings.php", "w"); foreach($settingsArray as $row) fputs($fp, $row); fclose ($fp); } include("$installdir/Settings.php"); ?> </td></tr></table> <center><p> Installation Complete!<p> <a href="<?=$boardurl?>/index.php">Click Here</a> to go to your board<br><br> </center> <?php }
?> </td> </tr> </table></center> </body> </html>
|
|