1
0
mirror of https://github.com/e107inc/e107.git synced 2025-03-14 01:19:44 +01:00

phpBB3 Users and Forum import.

This commit is contained in:
Cameron 2013-04-16 16:00:13 -07:00
parent f3bafdae5d
commit 230e9cefb7
5 changed files with 906 additions and 228 deletions

View File

@ -30,7 +30,7 @@ Options supported:
*/
define('IMPORT_DEBUG',FALSE);
define('IMPORT_DEBUG',TRUE);
// define('IMPORT_DEBUG',TRUE);
require_once("../../class2.php");
@ -91,15 +91,20 @@ class import_main_ui extends e_admin_ui
protected $deleteExisting = false; // delete content from existing table during import.
protected $selectedTables = array(); // User selection of what tables to import. eg. news, pages etc.
protected $importClass = null;
protected $checked_class_list = '';
// Definitions of available areas to import
protected $importTables = array(
'users' => array('message' => LAN_CONVERT_25, 'classfile' => 'import_user_class.php', 'classname' => 'user_import'),
'news' => array('message' => LAN_CONVERT_28, 'classfile' => 'import_news_class.php', 'classname' => 'news_import'),
'page' => array('message' => "Pages", 'classfile' => 'import_page_class.php', 'classname' => 'page_import'),
'links' => array('message' => "Links", 'classfile' => 'import_links_class.php', 'classname' => 'links_import'),
'media' => array('message' => "Media", 'classfile' => 'import_media_class.php', 'classname' => 'media_import'),
'users' => array('message' => LAN_CONVERT_25, 'classfile' => 'import_user_class.php', 'classname' => 'user_import'),
'news' => array('message' => LAN_CONVERT_28, 'classfile' => 'import_news_class.php', 'classname' => 'news_import'),
'page' => array('message' => "Pages", 'classfile' => 'import_page_class.php', 'classname' => 'page_import'),
'links' => array('message' => "Links", 'classfile' => 'import_links_class.php', 'classname' => 'links_import'),
'media' => array('message' => "Media", 'classfile' => 'import_media_class.php', 'classname' => 'media_import'),
'forum' => array('message' => "Forum", 'classfile' => 'import_forum_class.php', 'classname' => 'forum_import'),
'forumthread' => array('message' => "Forum Topics/Threads", 'classfile' => 'import_forum_class.php', 'classname' => 'forumthread_import', 'nolist'=>true),
'forumpost' => array('message' => "Forum Posts", 'classfile' => 'import_forum_class.php', 'classname' => 'forumpost_import', 'nolist'=>true),
'forumtrack' => array('message' => "Forum Track", 'classfile' => 'import_forum_class.php', 'classname' => 'forumtrack_import', 'nolist'=>true),
// 'forumpost' => array('message' => "Media", 'classfile' => 'import_media_class.php', 'classname' => 'media_import'),
'comments' => array('message'=> "Comments"),
// 'forumdefs' => array('message' => LAN_CONVERT_26),
// 'forumposts' => array('message' => LAN_CONVERT_48),
@ -167,6 +172,11 @@ class import_main_ui extends e_admin_ui
$this->deleteExisting = varset($_POST['import_delete_existing_data'],0);
if(varset($_POST['classes_select']))
{
$this->checked_class_list = implode(',',$_POST['classes_select']);
}
if($_POST['selectedTables'])
{
$this->selectedTables = $_POST['selectedTables'];
@ -198,7 +208,7 @@ class import_main_ui extends e_admin_ui
$mes = e107::getMessage();
$frm = e107::getForm();
$tableCount = 0;
// $mes->addDebug(print_a($this->providers,true));
$text = "
@ -218,9 +228,11 @@ class import_main_ui extends e_admin_ui
<thead>
<tr>
<th>".LAN_CONVERT_06."</th>";
foreach($this->importTables as $name) // 1 column for each of users, news, forum etc.
foreach($this->importTables as $val) // 1 column for each of users, news, forum etc.
{
$text .= "<th class='center'>".$name['message']."</th>";
if(vartrue($val['nolist'])){ continue; }
$text .= "<th class='center'>".$val['message']."</th>";
$tableCount++;
}
$text.="
@ -234,7 +246,7 @@ class import_main_ui extends e_admin_ui
<td><img src='".e_PLUGIN."import/images/csv.png' alt='' style='float:left;height:32px;width:32px;margin-right:4px'>CSV</td>
<td class='center'>".ADMIN_TRUE_ICON."</td>";
for ($i=0; $i < count($this->importTables)-1; $i++)
for ($i=0; $i < $tableCount-1; $i++)
{
$text .= "<td>&nbsp;</td>";
}
@ -257,6 +269,7 @@ class import_main_ui extends e_admin_ui
foreach($this->importTables as $key=>$val)
{
if(vartrue($val['nolist'])){ continue; }
$text .= "<td class='center'>".(in_array($key,$info['supported']) ? ADMIN_TRUE_ICON : "&nbsp;")."</td>\n";
}
@ -453,7 +466,10 @@ class import_main_ui extends e_admin_ui
</tr>
<tr>
<td >$importType ".LAN_CONVERT_20."</td>
<td ><input class='tbox' type='text' name='dbParamUsername' size='30' value='".varset($_POST['dbParamUsername'])."' maxlength='100' /></td>
<td >
<input class='tbox' type='text' name='dbParamUsername' size='30' value='".varset($_POST['dbParamUsername'])."' maxlength='100' />
<div class='field-help'>Must be different from the one e107 uses.</div>
</td>
</tr>
<tr>
<td >$importType ".LAN_CONVERT_21."</td>
@ -648,8 +664,9 @@ class import_main_ui extends e_admin_ui
if($k == 'users') // Do any type-specific default setting
{
$exporter->overrideDefault('user_class', $checked_class_list);
break;
$mes->addDebug("dbImport(): Overriding Default for user_class: ".$this->checked_class_list);
$exporter->overrideDefault('user_class', $this->checked_class_list);
// break;
}
if ($this->deleteExisting)
@ -694,7 +711,7 @@ class import_main_ui extends e_admin_ui
/// - old BELOW ----------------------------------------
/*
foreach ($this->importTables as $k => $v)
{
if (isset($this->selectedTables[$k]))
@ -775,6 +792,7 @@ class import_main_ui extends e_admin_ui
}
}
*/
// $msg = LAN_CONVERT_29;
return true;

View File

@ -79,13 +79,21 @@ class base_import_class
return $this->saveMediaData($dataRecord);
break;
case 'forumdefs' :
case 'forum' :
return $this->saveForumData($dataRecord);
break;
case 'forumposts' :
return $this->savePostData($dataRecord);
case 'forumthread' :
return $this->saveForumThreadData($dataRecord);
break;
case 'forumpost' :
return $this->saveForumPostData($dataRecord);
break;
case 'forumtrack' :
return $this->saveForumTrackData($dataRecord);
break;
case 'polls' :
break;
@ -134,10 +142,20 @@ class base_import_class
return $this->copyMediaData($initial, $result);
break;
case 'forumdefs' :
case 'forum' :
return $this->copyForumData($initial, $result);
break;
case 'forumthread' :
return $this->copyForumThreadData($initial, $result);
break;
case 'forumposts' :
case 'forumpost' :
return $this->copyForumPostData($initial, $result);
break;
case 'forumtrack' :
return $this->copyForumTrackData($initial, $result);
break;
case 'polls' :
@ -189,85 +207,105 @@ class base_import_class
{
return $target;
}
}
//===========================================================
// UTILITY ROUTINES
//===========================================================
// Process all bbcodes in the passed value; return the processed string.
// Works recursively
// Start by assembling matched pairs. Then map and otherwise process as required.
// Divide the value into five bits:
// Preamble - up to the identified bbcode (won't contain bbcode)
// BBCode start code
// Inner - text between the two bbcodes (may contain another bbcode)
// BBCode end code
// Trailer - remaining unprocessed text (may contain more bbcodes)
// (Note: preg_split might seem obvious, but doesn't pick out the actual codes
function proc_bb($value, $options = "", $maptable = null)
{
$bblower = (strpos($options,'bblower') !== FALSE) ? TRUE : FALSE; // Convert bbcode to lower case
$bbphpbb = (strpos($options,'phpbb') !== FALSE) ? TRUE : FALSE; // Strip values as phpbb
$nextchar = 0;
$loopcount = 0;
while ($nextchar < strlen($value))
{
$firstbit = '';
$middlebit = '';
$lastbit = '';
$loopcount++;
if ($loopcount > 10) return 'Max depth exceeded';
unset($bbword);
$firstcode = strpos($value,'[',$nextchar);
if ($firstcode === FALSE) return $value; // Done if no square brackets
$firstend = strpos($value,']',$firstcode);
if ($firstend === FALSE) return $value; // Done if no closing bracket
$bbword = substr($value,$firstcode+1,$firstend - $firstcode - 1); // May need to process this more if parameter follows
$bbparam = '';
$temp = strpos($bbword,'=');
if ($temp !== FALSE)
function copyForumData(&$target, &$source)
{
$bbparam = substr($bbword,$temp);
$bbword = substr($bbword,0,-strlen($bbparam));
return $target;
}
if (($bbword) && ($bbword == trim($bbword)))
{
$laststart = strpos($value,'[/'.$bbword,$firstend); // Find matching end
$lastend = strpos($value,']',$laststart);
if (($laststart === FALSE) || ($lastend === FALSE))
{ // No matching end character
$nextchar = $firstend; // Just move scan pointer along
}
else
{ // Got a valid bbcode pair here
function copyForumPostData(&$target, &$source)
{
return $target;
}
function copyForumThreadData(&$target, &$source)
{
return $target;
}
function copyForumTrackData(&$target, &$source)
{
return $target;
}
//===========================================================
// UTILITY ROUTINES
//===========================================================
// Process all bbcodes in the passed value; return the processed string.
// Works recursively
// Start by assembling matched pairs. Then map and otherwise process as required.
// Divide the value into five bits:
// Preamble - up to the identified bbcode (won't contain bbcode)
// BBCode start code
// Inner - text between the two bbcodes (may contain another bbcode)
// BBCode end code
// Trailer - remaining unprocessed text (may contain more bbcodes)
// (Note: preg_split might seem obvious, but doesn't pick out the actual codes
function proc_bb($value, $options = "", $maptable = null)
{
$bblower = (strpos($options,'bblower') !== FALSE) ? TRUE : FALSE; // Convert bbcode to lower case
$bbphpbb = (strpos($options,'phpbb') !== FALSE) ? TRUE : FALSE; // Strip values as phpbb
$nextchar = 0;
$loopcount = 0;
while ($nextchar < strlen($value))
{
$firstbit = '';
if ($firstcode > 0) $firstbit = substr($value,0,$firstcode);
$middlebit = substr($value,$firstend+1,$laststart - $firstend-1);
$lastbit = substr($value,$lastend+1,strlen($value) - $lastend);
// Process bbcodes here
if ($bblower) $bbword = strtolower($bbword);
if ($bbphpbb && (strpos($bbword,':') !== FALSE)) $bbword = substr($bbword,0,strpos($bbword,':'));
if ($maptable)
{ // Do mapping
if (array_key_exists($bbword,$maptable)) $bbword = $maptable[$bbword];
$middlebit = '';
$lastbit = '';
$loopcount++;
if ($loopcount > 10) return 'Max depth exceeded';
unset($bbword);
$firstcode = strpos($value,'[',$nextchar);
if ($firstcode === FALSE) return $value; // Done if no square brackets
$firstend = strpos($value,']',$firstcode);
if ($firstend === FALSE) return $value; // Done if no closing bracket
$bbword = substr($value,$firstcode+1,$firstend - $firstcode - 1); // May need to process this more if parameter follows
$bbparam = '';
$temp = strpos($bbword,'=');
if ($temp !== FALSE)
{
$bbparam = substr($bbword,$temp);
$bbword = substr($bbword,0,-strlen($bbparam));
}
$bbbegin = '['.$bbword.$bbparam.']';
$bbend = '[/'.$bbword.']';
return $firstbit.$bbbegin.proc_bb($middlebit,$options,$maptable).$bbend.proc_bb($lastbit,$options,$maptable);
}
}
else
{
$nextchar = $firstend+1;
if (($bbword) && ($bbword == trim($bbword)))
{
$laststart = strpos($value,'[/'.$bbword,$firstend); // Find matching end
$lastend = strpos($value,']',$laststart);
if (($laststart === FALSE) || ($lastend === FALSE))
{ // No matching end character
$nextchar = $firstend; // Just move scan pointer along
}
else
{ // Got a valid bbcode pair here
$firstbit = '';
if ($firstcode > 0) $firstbit = substr($value,0,$firstcode);
$middlebit = substr($value,$firstend+1,$laststart - $firstend-1);
$lastbit = substr($value,$lastend+1,strlen($value) - $lastend);
// Process bbcodes here
if ($bblower) $bbword = strtolower($bbword);
if ($bbphpbb && (strpos($bbword,':') !== FALSE)) $bbword = substr($bbword,0,strpos($bbword,':'));
if ($maptable)
{ // Do mapping
if (array_key_exists($bbword,$maptable)) $bbword = $maptable[$bbword];
}
$bbbegin = '['.$bbword.$bbparam.']';
$bbend = '[/'.$bbword.']';
return $firstbit.$bbbegin.$this->proc_bb($middlebit,$options,$maptable).$bbend.$this->proc_bb($lastbit,$options,$maptable);
}
}
else
{
$nextchar = $firstend+1;
}
} //endwhile;
}
} //endwhile;
}
?>

View File

@ -30,48 +30,48 @@ To use:
class user_import
{
var $userDB = NULL;
var $blockMainAdmin = TRUE;
var $error;
var $userDB = NULL;
var $blockMainAdmin = TRUE;
var $error;
// Every field must be in exactly one of the arrays $userDefaults, $userSpecial, $userMandatory
var $userDefaults = array(
'user_id' => 0,
'user_customtitle' => '',
'user_sess' => '', // Photo
'user_email' => '',
'user_signature' => '',
'user_image' => '', // Avatar
'user_hideemail' => 1,
'user_lastvisit' => 0,
'user_currentvisit' => 0,
'user_lastpost' => 0,
'user_chats' => 0,
'user_comments' => 0,
'user_ip' => '',
'user_ban' => 0,
'user_prefs' => '',
// 'user_viewed' => '',
'user_visits' => 0,
'user_admin' => 0,
'user_login' => '', // User real name
'user_class' => '',
'user_perms' => '',
'user_xup' => ''
);
var $userDefaults = array(
'user_id' => 0,
'user_customtitle' => '',
'user_sess' => '', // Photo
'user_email' => '',
'user_signature' => '',
'user_image' => '', // Avatar
'user_hideemail' => 1,
'user_lastvisit' => 0,
'user_currentvisit' => 0,
'user_lastpost' => 0,
'user_chats' => 0,
'user_comments' => 0,
'user_ip' => '',
'user_ban' => 0,
'user_prefs' => '',
// 'user_viewed' => '',
'user_visits' => 0,
'user_admin' => 0,
'user_login' => '', // User real name
'user_class' => '',
'user_perms' => '',
'user_xup' => ''
);
// Fields which are defaulted at save-time if not previously set
var $userSpecial = array('user_join', 'user_realm', 'user_pwchange');
var $userSpecial = array('user_join', 'user_realm', 'user_pwchange');
// Fields which must be set up by the caller.
var $userMandatory = array(
'user_name', 'user_loginname', 'user_password'
);
var $userMandatory = array(
'user_name', 'user_loginname', 'user_password'
);
// Predefined fields which may appear in the extended user fields
var $userExtended = array(
var $userExtended = array(
'user_language',
'user_country',
'user_location',
@ -81,136 +81,178 @@ class user_import
'user_msn',
'user_homepage',
'user_birthday',
'user_timezone'
'user_timezone',
'user_plugin_forum_posts'
);
// Array is set up with those predefined extended fields which are actually in use
var $actualExtended = array();
// Array is set up with those predefined extended fields which are actually in use
var $actualExtended = array();
// Constructor
function user_import()
{
global $sql;
$this->userDB = new db; // Have our own database object to write to the user table
// Create list of predefined extended user fields which are present
if($ret = getcachedvars("userdata_{$uid}"))
function user_import()
{
foreach ($this->userExtended as $v)
{
if (isset($ret[$v])) $this->actualExtended[] = $v;
}
global $sql;
$this->userDB = new db; // Have our own database object to write to the user table
// Create list of predefined extended user fields which are present
if($ret = getcachedvars("userdata_{$uid}"))
{
foreach ($this->userExtended as $v)
{
if (isset($ret[$v])) $this->actualExtended[] = $v;
}
}
}
}
// Empty the user DB - by default leaving only the main admin.
function emptyTargetDB($inc_admin = FALSE)
{
$delClause = '';
if ($inc_admin === TRUE)
function emptyTargetDB($inc_admin = FALSE)
{
$this->blockMainAdmin = FALSE;
$delClause = '';
if ($inc_admin === TRUE)
{
$this->blockMainAdmin = FALSE;
}
else
{
$this->blockMainAdmin = TRUE;
$delClause = 'user_id != 1';
}
$this->userDB->delete('user',$delClause);
$this->userDB->delete('user_extended',$delClause);
}
else
{
$this->blockMainAdmin = TRUE;
$delClause = 'user_id != 1';
}
$this->userDB->db_Delete('user',$delClause);
$this->userDB->db_Delete('user_extended',$delClause);
}
// Set a new default for a particular field
function overrideDefault($key, $value)
{
// echo "Override: {$key} => {$value}<br />";
if (!isset($this->userDefaults[$key])) return FALSE;
$this->userDefaults[$key] = $value;
}
function overrideDefault($key, $value)
{
// echo "Override: {$key} => {$value}<br />";
if (!isset($this->userDefaults[$key])) return FALSE;
$this->userDefaults[$key] = $value;
}
// Returns an array with all relevant fields set to the current default
function getDefaults()
{
return $this->userDefaults;
}
// Vet a user or login name. If OK, always returns the name.
// On error, if $just_strip true, returns 'processed' name; otherwise returns FALSE
function vetUserName($name, $just_strip = FALSE)
{
$temp_name = trim(preg_replace('/&nbsp;|\#|\=|\$/', "", strip_tags($name)));
if (($temp_name == $name) || $just_strip) return $temp_name;
return FALSE;
}
// Add a user record to the DB - pass array as parameter.
// Returns an error code on failure. TRUE on success
function saveData($userRecord)
{
if ($this->blockMainAdmin && isset($userRecord['user_id']) && ($userRecord['user_id'] == 1)) return 1;
$extendedFields = array();
foreach ($userRecord as $k => $v)
function getDefaults()
{
if (in_array($k,$this->userExtended))
{
if (in_array($k,$this->actualExtended)) $extendedFields[$k] = $v; // Pull out any extended field values which are needed
unset($userRecord[$k]); // And always delete from the original data record
}
return $this->userDefaults;
}
foreach ($userRecord as $k => $v)
{ // Check only valid fields being passed
if (!array_key_exists($k,$this->userDefaults) && !in_array($k,$this->userSpecial) && !in_array($k,$this->userMandatory) ) //
// Vet a user or login name. If OK, always returns the name.
// On error, if $just_strip true, returns 'processed' name; otherwise returns FALSE
function vetUserName($name, $just_strip = FALSE)
{
$temp_name = trim(preg_replace('/&nbsp;|\#|\=|\$/', "", strip_tags($name)));
if (($temp_name == $name) || $just_strip) return $temp_name;
return FALSE;
}
// Add a user record to the DB - pass array as parameter.
// Returns an error code on failure. TRUE on success
function saveData($userRecord)
{
if ($this->blockMainAdmin && isset($userRecord['user_id']) && ($userRecord['user_id'] == 1))
{
echo "Failed on {$k} => {$v} <br />";
return 2;
e107::getMessage()->addDebug("Skipping user record of main-admin");
return true;
// return 1;
}
}
// Check user names for invalid characters
$userRecord['user_name'] = $this->vetUserName($userRecord['user_name'],FALSE);
$userRecord['user_loginname'] = $this->vetUserName($userRecord['user_loginname'],FALSE);
if (($userRecord['user_name'] === FALSE) || ($userRecord['user_name'] === FALSE)) return 5;
$extendedFields = array();
foreach ($userRecord as $k => $v)
{
if (in_array($k,$this->userExtended))
{
if (in_array($k,$this->actualExtended))
{
$extendedFields[$k] = $v; // Pull out any extended field values which are needed
}
unset($userRecord[$k]); // And always delete from the original data record
}
}
foreach ($userRecord as $k => $v) // Check only valid fields being passed
{
if (!array_key_exists($k,$this->userDefaults) && !in_array($k,$this->userSpecial) && !in_array($k,$this->userMandatory) ) //
{
e107::getMessage()->addDebug("Failed on {$k} => {$v} ");
return 2;
}
}
// Check user names for invalid characters
$userRecord['user_name'] = $this->vetUserName($userRecord['user_name'],FALSE);
$userRecord['user_loginname'] = $this->vetUserName($userRecord['user_loginname'],FALSE);
if (($userRecord['user_name'] === FALSE) || ($userRecord['user_name'] === FALSE))
{
e107::getMessage()->addDebug("user_name was empty");
return 5;
}
if (trim($userRecord['user_name']) == '') $userRecord['user_name'] = trim($userRecord['user_loginname']);
if (trim($userRecord['user_loginname']) == '') $userRecord['user_loginname'] = trim($userRecord['user_name']);
foreach ($this->userMandatory as $k)
{
if (!isset($userRecord[$k]))
{
e107::getMessage()->addDebug("Failed userMandatory on {$k}");
return 3;
}
if (strlen($userRecord[$k]) < 3)
{
// e107::getMessage()->addDebug("Failed userMandatory length on {$k}");
// return 3;
}
}
if (!isset($userRecord['user_join'])) $userRecord['user_join'] = time();
$userRecord['user_realm'] = ''; // Never carry across these fields
$userRecord['user_pwchange'] = 0;
if (trim($userRecord['user_name']) == '') $userRecord['user_name'] = trim($userRecord['user_loginname']);
if (trim($userRecord['user_loginname']) == '') $userRecord['user_loginname'] = trim($userRecord['user_name']);
foreach ($this->userMandatory as $k)
{
if (!isset($userRecord[$k])) return 3;
if (strlen($userRecord[$k]) < 3) return 3;
}
if (!isset($userRecord['user_join'])) $userRecord['user_join'] = time();
$userRecord['user_realm'] = ''; // Never carry across these fields
$userRecord['user_pwchange'] = 0;
if(!$result = $this->userDB->replace('user',$userRecord))
{
return 4;
}
if (count($extendedFields))
{
$extendedFields['user_extended_id'] = varset($userRecord['user_id'],0) ? $userRecord['user_id'] : $result;
if($this->userDB->insert('user_extended',$extendedFields) === false)
{
e107::getMessage()->addDebug("Failed to insert extended fields: ".print_a($extendedFields));
return 6;
}
if(!$result = $this->userDB->db_Insert('user',$userRecord))
{
return 4;
}
return TRUE;
}
if (count($extendedFields))
{
$extendedFields['user_extended_id'] = varset($userRecord['user_id'],0) ? $userRecord['user_id'] : $result;
$result = $this->userDB->db_Insert('user_extended',$extendedFields);
if ($result === FALSE) return 6;
}
return TRUE;
}
function getErrorText($errnum) // these errors are presumptuous and misleading. especially '4' .
{
$errorTexts = array(0 => 'No error', 1 => 'Can\'t change main admin data', 2 => 'invalid field passed',
3 => 'Mandatory field not set', 4 => 'User already exists', 5 => 'Invalid characters in user or login name',
6 => 'Error saving extended user fields');
if (isset($errorTexts[$errnum])) return $errorTexts[$errnum];
return 'Unknown: '.$errnum;
}
function getErrorText($errnum) // these errors are presumptuous and misleading. especially '4' .
{
$errorTexts = array(
0 => 'No error',
1 => 'Can\'t change main admin data',
2 => 'invalid field passed',
3 => 'Mandatory field not set',
4 => 'User already exists',
5 => 'Invalid characters in user or login name',
6 => 'Error saving extended user fields'
);
if (isset($errorTexts[$errnum])) return $errorTexts[$errnum];
return 'Unknown: '.$errnum;
}
}

View File

@ -35,7 +35,7 @@ require_once('import_classes.php');
class phpbb2_import extends base_import_class
{
public $title = 'PHPBB Version 2/3';
public $title = 'PHPBB Version 2';
public $description = 'Should do most versions, and Dragonfly';
public $supported = array('users');
public $mprefix = 'phpbb_';

View File

@ -0,0 +1,580 @@
<?php
/*
* e107 website system
*
* Copyright (C) 2008-2009 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
*
*
* $Source: /cvs_backup/e107_0.8/e107_plugins/import/phpbb2_import_class.php,v $
* $Revision$
* $Date$
* $Author$
*/
require_once('import_classes.php');
class phpbb3_import extends base_import_class
{
public $title = 'PHPBB Version 3';
public $description = 'Experimental';
public $supported = array('users','forum','forumthread','forumpost','forumtrack');
public $mprefix = 'phpbb_';
var $catcount = 0; // Counts forum IDs
var $id_map = array(); // Map of PHPBB forum IDs ==> E107 forum IDs
// Set up a query for the specified task.
// Returns TRUE on success. FALSE on error
// If $blank_user is true, certain cross-referencing user info is to be zeroed
function setupQuery($task, $blank_user=FALSE)
{
if ($this->ourDB == NULL) return FALSE;
switch ($task)
{
case 'users' :
$result = $this->ourDB->gen("SELECT * FROM {$this->DBPrefix}users ");
if ($result === FALSE) return FALSE;
break;
case 'forum' :
$result = $this->ourDB->gen("SELECT * FROM `{$this->DBPrefix}forums`");
if ($result === FALSE) return FALSE;
break;
case 'forumthread' :
$result = $this->ourDB->gen("SELECT * FROM `{$this->DBPrefix}topics`");
if ($result === FALSE) return FALSE;
break;
case 'forumpost' :
$result = $this->ourDB->gen("SELECT * FROM `{$this->DBPrefix}posts`");
if ($result === FALSE) return FALSE;
break;
case 'forumtrack' :
$result = $this->ourDB->gen("SELECT * FROM `{$this->DBPrefix}forums_track`");
if ($result === FALSE) return FALSE;
break;
case 'polls' :
return FALSE;
break;
case 'news' :
return FALSE;
break;
default :
return FALSE;
}
$this->copyUserInfo = true; // !$blank_user;
$this->currentTask = $task;
return TRUE;
}
//------------------------------------
// Internal functions below here
//------------------------------------
// Copy data read from the DB into the record to be returned.
/**
* $target - e107_users table
* $source - phpbb_user table : https://wiki.phpbb.com/Table.phpbb_users
*/
function copyUserData(&$target, &$source)
{
// if ($this->copyUserInfo)
$target['user_id'] = $source['user_id'];
$target['user_name'] = $source['username'];
$target['user_loginname'] = $source['username'];
if ((substr($source['user_password'],0,3) == '$H$') && (strlen($source['user_password']) == 34)) // Convert salted password to E107 style (they use the same basic coding)
{
$target['user_password'] = substr_replace($source['user_password'], '$E$',0,3);
}
else // Probably an old md5 password
{
$target['user_password'] = $source['user_password'];
}
$target['user_email'] = $source['user_email'];
$target['user_signature'] = $this->proc_bb($source['user_sig'],'phpbb,bblower');
$target['user_hideemail'] = $source['user_allow_viewemail'];
$target['user_join'] = $source['user_regdate'];
// $target['user_forums'] = $source['user_posts'];
$target['user_admin'] = 0; // $source['user_level'];
$target['user_lastvisit'] = $source['user_lastvisit'];
$target['user_ban'] = $source['user_type'];
switch ($source['user_avatar_type'])
{
default:
$target['user_image'] = $source['user_avatar'];
}
// $target['user_plugin_forum_viewed'];
$target['user_plugin_forum_posts'] = $source['user_posts'];
$target['user_timezone'] = $source['user_timezone']; // source is decimal(5,2)
$target['user_language'] = $source['user_lang']; // May need conversion
$target['user_location'] = $source['user_from'];
$target['user_icq'] = $source['user_icq'];
$target['user_aim'] = $source['user_aim'];
$target['user_yahoo'] = $source['user_yim'];
$target['user_msn'] = $source['user_msnm'];
$target['user_homepage'] = $source['user_website'];
// $target['user_'] = $source[''];
// $target[] = $source['user_active]; // PHPBB2
// $target['user_lastpost'] = $source['user_lastpost_time']; // PHPBB3
return $target;
}
/**
* $target - e107_forum table
* $source - phpbb_forums table : https://wiki.phpbb.com/Table.phpbb_forums
*/
function copyForumData(&$target, &$source)
{
$target['forum_id'] = $source['forum_id'];
$target['forum_name'] = $source['forum_name'];
$target['forum_description'] = $source['forum_desc'];
$target['forum_parent'] = $source['parent_id'];
$target['forum_sub'] = "";
$target['forum_datestamp'] = time();
$target['forum_moderators'] = "";
$target['forum_threads'] = $source['forum_topics'];
$target['forum_replies'] = "";
$target['forum_lastpost_user'] = $source['forum_last_poster_id'];
$target['forum_lastpost_user_anon'] = $source['forum_last_poster_name'];
$target['forum_lastpost_info'] = $source['forum_last_post_time'];
// $target['forum_class'] = "";
// $target['forum_order']
// $target['forum_postclass']
// $target['forum_threadclass']
// $target['forum_options']
return $target;
}
/**
* $target - e107 forum_threads
* $source - phpbb_topics : https://wiki.phpbb.com/Table.phpbb_topics
*/
function copyForumThreadData(&$target, &$source)
{
$target['thread_id'] = $source['topic_id'];
$target['thread_name'] = $source['topic_title'];
$target['thread_forum_id'] = $source['forum_id'];
$target['thread_views'] = $source['topic_views'];
// $target['thread_active'] = $source['topic_status'];
$target['thread_lastpost'] = $source['topic_last_post_id'];
$target['thread_sticky'] = $source['topic_time_limit'];
$target['thread_datestamp'] = $source['topic_time'];
$target['thread_user'] = $source['topic_poster'];
$target['thread_user_anon'] = $source['topic_first_poster_name'];
$target['thread_lastuser'] = $source['topic_last_poster_id'];
$target['thread_lastuser_anon'] = $source['topic_last_poster_name'];
$target['thread_total_replies'] = $source['topic_replies'];
// $target['thread_options'] = $source['topic_'];
return $target;
}
/**
* $target - e107_forum_post table
* $source - phpbb_posts table : https://wiki.phpbb.com/Table.phpbb_posts
*/
function copyForumPostData(&$target, &$source)
{
$target['post_id'] = $source[''];
$target['post_entry'] = $source['post_text'];
$target['post_thread'] = $source['topic_id'];
$target['post_forum'] = $source['forum_id'];
// $target['post_status'] = $source[''];
$target['post_datestamp'] = $source['post_time'];
$target['post_user'] = $source['poster_id'];
$target['post_edit_datestamp'] = $source['post_edit_time'];
$target['post_edit_user'] = $source['post_edit_user'];
$target['post_ip'] = $source['poster_ip'];
// $target['post_user_anon'] = $source[''];
// $target['post_attachments'] = $source[''];
// $target['post_options'] = $source[''];
return $target;
}
/**
* $target - e107_forum_track
* $source - phpbb_forums_track : https://wiki.phpbb.com/Table.phpbb_forums_track
*/
function copyForumTrackData(&$target, &$source)
{
$target['track_userid'] = $source['user_id'];
$target['track_thread'] = $source['forum_id'];
return $target;
}
// ---------------------------------------------- OLD ---------------------------------
function convertForumParent(&$target, &$source)
{
$this->catcount++;
$this->id_map[$source['cat_id']] = $this->catcount;
$target['forum_id'] = $this->catcount; // Create new IDs for parent forums
$target['forum_name'] = $source['cat_title'];
$target['forum_order'] = $source['cat_order'];
$target['forum_description'] = $source['cat_desc'];
$target['forum_moderators'] = e_UC_ADMIN;
// $target['forum_'] = $source[''];
// $target['forum_'] = $source[''];
}
/**
* $target - e107 table
* $source - phpbb3 table
*/
function convertForum(&$target, &$source, $catid)
{
$this->catcount++;
$this->id_map[$source['forum_id']] = $this->catcount;
$target['forum_id'] = $this->catcount;
$target['forum_parent'] = $this->id_map[$source['cat_id']]; // Map to the new E107 ID, rather than directly use the one from the DB
$target['forum_name'] = $source['forum_name'];
$target['forum_description'] = $source['forum_desc'];
$target['forum_order'] = $source['forum_order'];
$target['forum_threads'] = $source['forum_topics'];
$target['forum_replies'] = $source['forum_posts'];
$target['forum_moderators'] = e_UC_ADMIN;
// $target['forum_'] = $source[''];
}
}
/*
e107
thread_id
thread_name
thread_forum_id
thread_views
thread_active
thread_lastpost
thread_sticky
thread_datestamp
thread_user
thread_user_anon
thread_lastuser
thread_lastuser_anon
thread_total_replies
thread_options
*
/*
Historical info for conversion below here
function convertParents($catid)
{
$parentArray = array(
array("srcdata" => "cat_id", "e107" => "forum_id", "type" => "INT", "value" => $catid),
array("srcdata" => "cat_title", "e107" => "forum_name", "type" => "STRING"),
array("srcdata" => "cat_order", "e107" => "forum_order", "type" => "INT"),
array("srcdata" => "cat_desc", "e107" => "forum_description", "type" => "STRING"),
array("srcdata" => "null", "e107" => "forum_moderators", "type" => "INT", "value" => 254)
);
return $parentArray;
}
function convertForums($catid)
{
$forumArray = array(
array("srcdata" => "forum_id", "e107" => "forum_id", "type" => "INT"),
array("srcdata" => "cat_id", "e107" => "forum_parent", "type" => "STRING", "value" => $catid),
array("srcdata" => "forum_name", "e107" => "forum_name", "type" => "STRING"),
array("srcdata" => "forum_desc", "e107" => "forum_description", "type" => "STRING"),
array("srcdata" => "forum_order", "e107" => "forum_order", "type" => "INT"),
array("srcdata" => "forum_topics", "e107" => "forum_threads", "type" => "INT"),
array("srcdata" => "forum_posts", "e107" => "forum_replies", "type" => "INT"),
array("srcdata" => "null", "e107" => "forum_moderators", "type" => "INT", "value" => 254)
);
return $forumArray;
}
//function convertTopics($poster)
function convertTopics()
{
$topicArray = array(
array("srcdata" => "forum_id", "e107" => "thread_forum_id", "type" => "INT"),
array("srcdata" => "topic_title", "e107" => "thread_name", "type" => "STRING"),
array("srcdata" => "post_text", "e107" => "thread_thread", "type" => "STRING", "default" => "", "sproc" => "usebb,phpbb,bblower"),
array("srcdata" => "topic_poster", "e107" => "thread_user", "type" => "STRING"),
array("srcdata" => "null", "e107" => "thread_active", "type" => "INT", "value" => 1),
array("srcdata" => "topic_time", "e107" => "thread_datestamp", "type" => "INT"),
array("srcdata" => "topic_views", "e107" => "thread_views", "type" => "INT"),
array("srcdata" => "topic_replies", "e107" => "thread_total_replies", "type" => "INT"),
array("srcdata" => "null", "e107" => "thread_parent", "type" => "INT", "value" => 0),
);
return $topicArray;
}
function convertForumPosts($parent_id, $poster)
{
$postArray = array(
array("srcdata" => "post_text", "e107" => "thread_thread", "type" => "STRING", "default" => "", "sproc" => "usebb,phpbb,bblower"),
array("srcdata" => "forum_id", "e107" => "thread_forum_id", "type" => "INT"),
array("srcdata" => "post_time", "e107" => "thread_datestamp", "type" => "INT"),
array("srcdata" => "topic_views", "e107" => "thread_views", "type" => "INT"),
array("srcdata" => "post_time", "e107" => "thread_lastpost", "type" => "INT"),
array("srcdata" => "poster_id", "e107" => "thread_user", "type" => "STRING"),
array("srcdata" => "post_subject", "e107" => "thread_name", "type" => "STRING"),
array("srcdata" => "null", "e107" => "thread_parent", "type" => "INT", "value" => $parent_id),
);
return $postArray;
}
/*
-- --------------------------------------------------------
PHPBB uses three tables to record a poll. Looks wildly different to E107!
--
-- Table structure for table `_phpbb_vote_desc`
CREATE TABLE `_phpbb_vote_desc` (
`vote_id` mediumint(8) unsigned NOT NULL auto_increment,
`topic_id` mediumint(8) unsigned NOT NULL default '0',
`vote_text` text NOT NULL,
`vote_start` int(11) NOT NULL default '0',
`vote_length` int(11) NOT NULL default '0',
PRIMARY KEY (`vote_id`),
KEY `topic_id` (`topic_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=36 ;
--
-- Table structure for table `_phpbb_vote_results`
CREATE TABLE `_phpbb_vote_results` (
`vote_id` mediumint(8) unsigned NOT NULL default '0',
`vote_option_id` tinyint(4) unsigned NOT NULL default '0',
`vote_option_text` varchar(255) NOT NULL default '',
`vote_result` int(11) NOT NULL default '0',
KEY `vote_option_id` (`vote_option_id`),
KEY `vote_id` (`vote_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
--
-- Table structure for table `_phpbb_vote_voters`
CREATE TABLE `_phpbb_vote_voters` (
`vote_id` mediumint(8) unsigned NOT NULL default '0',
`vote_user_id` mediumint(8) NOT NULL default '0',
`vote_user_ip` char(8) NOT NULL default '',
KEY `vote_id` (`vote_id`),
KEY `vote_user_id` (`vote_user_id`),
KEY `vote_user_ip` (`vote_user_ip`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
*/
/*
//-----------------------------------------------------------
// ### get phpbb categories and insert them as forum parents
//-----------------------------------------------------------
mysql_query("TRUNCATE TABLE {$mySQLprefix}forum", $e107Connection);
$phpbb_res = mysql_query("SELECT * FROM {$phpbb2Prefix}categories", $phpbbConnection);
if(!$phpbb_res)
{
goError("Error! Unable to access ".$phpbb2Prefix."categories table.");
}
$catcount = 500;
while($parent = mysql_fetch_array($phpbb_res))
{
$parentArray = convertParents($catcount);
$query = createQuery($parentArray, $parent, $mySQLprefix."forum");
echo (mysql_query($query, $e107Connection) ? "Successfully inserted parent: ".$parent['cat_id'].": ".$parent['cat_title'] : "Unable to insert parent: ".$parent['cat_id'].": ".$parent['cat_title']."<br />".mysql_errno() . ": " . mysql_error())."<br />";
flush();
$phpbb_res2 = mysql_query("SELECT * FROM {$phpbb2Prefix}forums WHERE cat_id = ".$parent['cat_id'], $phpbbConnection);
if($phpbb_res2)
{
while($forum = mysql_fetch_array($phpbb_res2))
{
$forumArray = convertForums($catcount);
$query = createQuery($forumArray, $forum, $mySQLprefix."forum");
echo (mysql_query($query, $e107Connection) ? "Successfully inserted forum: ".$parent['cat_id'].": ".$parent['cat_title'] : "Unable to insert forum: ".$parent['cat_id'].": ".$parent['cat_title']."<br />".mysql_errno() . ": " . mysql_error())."<br />";
flush();
}
}
else
{
echo "Didn't find any forums for parent '".$parent['cat_title']."'<br />";
}
$catcount ++;
}
//------------------------------------------------------
// Read in forum topics
//------------------------------------------------------
mysql_query("TRUNCATE TABLE {$mySQLprefix}forum_t", $e107Connection);
mysql_query("TRUNCATE TABLE {$mySQLprefix}polls", $e107Connection);
$query = "SELECT * FROM {$phpbb2Prefix}topics
LEFT JOIN {$phpbb2Prefix}posts_text ON ({$phpbb2Prefix}topics.topic_title = {$phpbb2Prefix}posts_text.post_subject)
LEFT JOIN {$phpbb2Prefix}posts ON ({$phpbb2Prefix}posts.post_id = {$phpbb2Prefix}posts_text.post_id)
ORDER BY topic_time ASC";
$phpbb_res = mysql_query($query, $phpbbConnection);
if(!$phpbb_res)
{
goError("Error! Unable to access ".$phpbb2Prefix."topics table.");
}
while($topic = mysql_fetch_array($phpbb_res))
{
//echo "<pre>"; print_r($topic); echo "</pre>";
if($topic['topic_vote'])
{
// poll attached to this topic ...
$topic['topic_title'] = "[poll] ".$topic['topic_title'];
$query = "SELECT * FROM {$phpbb2Prefix}vote_desc WHERE topic_id=".$topic['topic_id'];
$phpbb_res3 = mysql_query($query, $phpbbConnection);
$pollQ = mysql_fetch_array($phpbb_res3);
$query = "SELECT * FROM {$phpbb2Prefix}vote_results WHERE vote_id=".$pollQ['vote_id'];
$phpbb_res3 = mysql_query($query, $phpbbConnection);
$options = "";
$votes = "";
while($pollO = mysql_fetch_array($phpbb_res3))
{
$options .= $pollO['vote_option_text'].chr(1);
$votes .= $pollO['vote_result'].chr(1);
}
extract($pollQ);
$vote_text = $tp->toDB($vote_text); // McFly added 25/5/06
$options = $tp->toDB($options); // McFly added 25/5/06
$query = "INSERT INTO ".$mySQLprefix."polls VALUES ('0', {$vote_start}, {$vote_start}, 0, 0, '{$vote_text}', '{$options}', '{$votes}', '', 2, 0, 0, 0, 255, 0)";
echo (mysql_query($query, $e107Connection) ? "Poll successfully inserted" : "Unable to insert poll ({$query})")."<br />";
}
if($topic['topic_poster'] == 2)
{
$topic['topic_poster'] = 1;
}
if($topic['topic_poster'] == -1)
{
$poster = ($topic['post_username'] ? $topic['post_username'] : "Anonymous");
$topic['topic_poster'] = "0.".$poster; // McFly moved, edited 25/5/06
}
$topicArray = convertTopics(); // McFly edited 25/5/06
$query = createQuery($topicArray, $topic, $mySQLprefix."forum_t");
if(!mysql_query($query, $e107Connection))
{
echo "Unable to insert topic: ".$topic['topic_id']."<br />";
flush();
}
else
{
echo "Successfully inserted topic: ".$topic['topic_id']."<br />";
flush();
$parent_id = mysql_insert_id();
$topic_id = $topic['topic_id'];
//echo "PARENT: $parent_id, TOPIC: $topic_id<br />";
// Not checking post_subject might work better
$query = "SELECT * FROM {$phpbb2Prefix}posts LEFT JOIN {$phpbb2Prefix}posts_text ON ({$phpbb2Prefix}posts.post_id = {$phpbb2Prefix}posts_text.post_id) WHERE topic_id='{$topic_id}' ORDER BY post_time DESC";
// $query = "SELECT * FROM {$phpbb2Prefix}posts LEFT JOIN {$phpbb2Prefix}posts_text ON ({$phpbb2Prefix}posts.post_id = {$phpbb2Prefix}posts_text.post_id) WHERE topic_id='{$topic_id}' AND post_subject = '' ORDER BY post_time DESC";
$phpbb_res2 = mysql_query($query, $phpbbConnection);
if(!$phpbb_res2)
{
goError("Error! Unable to access ".$phpbb2Prefix."posts / ".$phpbb2Prefix."posts_text table.");
}
while($post = mysql_fetch_array($phpbb_res2))
{
if($post['poster_id'] == 2)
{
$post['poster_id'] = 1;
}
if($post['poster_id'] == -1)
{
$poster = ($post['post_username'] ? $post['post_username'] : "Anonymous");
$post['poster_id'] = "0.".$poster; // McFly moved, edited 25/5/06
}
$postArray = convertForumPosts($parent_id, $poster);
$query = createQuery($postArray, $post, $mySQLprefix."forum_t",$mapdata);
echo (mysql_query($query, $e107Connection) ? "Successfully inserted thread: ".$post['post_id'] : "Unable to insert thread: ".$parent['cat_id'].": ".$parent['cat_title']."<br />".mysql_errno() . ": " . mysql_error())."<br />";
flush();
}
}
}
*/
?>