1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-31 20:00:37 +02:00

Work on import routines.

This commit is contained in:
CaMer0n
2012-07-22 03:28:06 +00:00
parent ce440572a7
commit 2dda03de71
26 changed files with 1131 additions and 389 deletions

View File

@@ -59,20 +59,24 @@ $import_class_comment = array(); // Descriptive comment
$import_class_support = array(); // Array of data types supported
// Definitions of available areas to import
$db_import_blocks = array('users' => array('message' => LAN_CONVERT_25, 'classfile' => 'import_user_class.php', 'classname' => 'user_import'),
'news' => array('message' => LAN_CONVERT_28),
'forumdefs' => array('message' => LAN_CONVERT_26),
'forumposts' => array('message' => LAN_CONVERT_48),
'polls' => array('message' => LAN_CONVERT_27)
);
$db_import_blocks = 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'),
'comments' => array('message'=> "Comments"),
// 'forumdefs' => array('message' => LAN_CONVERT_26),
// 'forumposts' => array('message' => LAN_CONVERT_48),
// 'polls' => array('message' => LAN_CONVERT_27)
);
// See what DB-based imports are available (don't really want it here, but gets it into the header script)
require_once(e_HANDLER.'file_class.php');
$fl = new e_file;
$importClassList = $fl->get_files(e_PLUGIN.'import', "^.+?_import_class\.php$", "standard", 1);
$importClassList = $fl->get_files(e_PLUGIN.'import/providers', "^.+?_import_class\.php$", "standard", 1);
foreach($importClassList as $file)
{
$tag = str_replace('_class.php','',$file['fname']);
@@ -98,6 +102,7 @@ if(varset($_POST['import_source']))
$current_db_type = varset($_POST['db_import_type'],key($import_class_names));
}
$db_blocks_to_import = array();
@@ -168,193 +173,245 @@ $msg = '';
//======================================================
if(isset($_POST['do_conversion']))
{
$abandon = TRUE;
switch ($import_source)
{
case 'csv' :
if (!isset($csv_formats[$current_csv])) $msg = "CSV File format error<br /><br />";
if (!is_readable($csv_data_file)) $msg = LAN_CONVERT_31;
if (!isset($csv_options[$current_csv])) $msg = LAN_CONVERT_37.' '.$current_csv;
if (!isset($csv_option_settings[$csv_options[$current_csv]])) $msg = LAN_CONVERT_37.' '.$csv_options[$current_csv];
$abandon = TRUE;
if (!$msg)
{
$field_list = explode(',',$csv_formats[$current_csv]);
$separator = $csv_option_settings[$csv_options[$current_csv]]['separator'];
$enveloper = $csv_option_settings[$csv_options[$current_csv]]['envelope'];
if (IMPORT_DEBUG) echo "CSV import: {$current_csv} Fields: {$csv_formats[$current_csv]}<br />";
require_once('import_user_class.php');
$usr = new user_import;
$usr->overrideDefault('user_class',$checked_class_list);
if (($source_data = file($csv_data_file)) === FALSE) $msg = LAN_CONVERT_32;
if ($import_delete_existing_data) $usr->emptyTargetDB(); // Delete existing users - reasonably safe now
$line_counter = 0;
$error_counter = 0;
$write_counter = 0;
foreach ($source_data as $line)
{
$line_counter++;
$line_error = FALSE;
if ($line = trim($line))
{
$usr_data = $usr->getDefaults(); // Reset user data
$line_data = csv_split($line, $separator, $enveloper);
$field_data = current($line_data);
foreach ($field_list as $f)
switch ($import_source)
{
case 'csv' :
if (!isset($csv_formats[$current_csv])) $msg = "CSV File format error<br /><br />";
if (!is_readable($csv_data_file)) $msg = LAN_CONVERT_31;
if (!isset($csv_options[$current_csv])) $msg = LAN_CONVERT_37.' '.$current_csv;
if (!isset($csv_option_settings[$csv_options[$current_csv]]))
{
if ($field_data === FALSE) $line_error = TRUE;
if ($f != 'dummy') $usr_data[$f] = $field_data;
$field_data = next($line_data);
$msg = LAN_CONVERT_37.' '.$csv_options[$current_csv];
}
if ($line_error)
{
if ($msg) $msg .= "<br />";
$msg .= LAN_CONVERT_33.$line_counter;
$error_counter++;
}
else
{
if ($csv_pw_not_encrypted)
{
$usr_data['user_password'] = md5($usr_data['user_password']);
}
$line_error = $usr->saveData($usr_data);
if ($line_error === TRUE)
{
$write_counter++;
}
else
{
$line_error = $usr->getErrorText($line_error);
if ($msg) $msg .= "<br />";
$msg .= str_replace('--ERRNUM--',$line_error,LAN_CONVERT_34).$line_counter;
$error_counter++;
}
}
}
}
if ($msg) $msg .= "<br />";
if ($import_delete_existing_data) $msg .= LAN_CONVERT_40.'<br />';
$msg .= str_replace(array('--LINES--','--USERS--', '--ERRORS--'),array($line_counter,$write_counter,$error_counter),LAN_CONVERT_35);
}
break;
case 'db' :
if (!$msg)
{
$field_list = explode(',',$csv_formats[$current_csv]);
$separator = $csv_option_settings[$csv_options[$current_csv]]['separator'];
$enveloper = $csv_option_settings[$csv_options[$current_csv]]['envelope'];
if (IMPORT_DEBUG) echo "CSV import: {$current_csv} Fields: {$csv_formats[$current_csv]}<br />";
require_once('import_user_class.php');
$usr = new user_import;
$usr->overrideDefault('user_class',$checked_class_list);
if (($source_data = file($csv_data_file)) === FALSE) $msg = LAN_CONVERT_32;
if ($import_delete_existing_data) $usr->emptyTargetDB(); // Delete existing users - reasonably safe now
$line_counter = 0;
$error_counter = 0;
$write_counter = 0;
foreach ($source_data as $line)
{
$line_counter++;
$line_error = FALSE;
if ($line = trim($line))
{
$usr_data = $usr->getDefaults(); // Reset user data
$line_data = csv_split($line, $separator, $enveloper);
$field_data = current($line_data);
foreach ($field_list as $f)
{
if ($field_data === FALSE) $line_error = TRUE;
if ($f != 'dummy') $usr_data[$f] = $field_data;
$field_data = next($line_data);
}
if ($line_error)
{
if ($msg) $msg .= "<br />";
$msg .= LAN_CONVERT_33.$line_counter;
$error_counter++;
}
else
{
if ($csv_pw_not_encrypted)
{
$usr_data['user_password'] = md5($usr_data['user_password']);
}
$line_error = $usr->saveData($usr_data);
if ($line_error === TRUE)
{
$write_counter++;
}
else
{
$line_error = $usr->getErrorText($line_error);
if ($msg) $msg .= "<br />";
$msg .= str_replace('--ERRNUM--',$line_error,LAN_CONVERT_34).$line_counter;
$error_counter++;
}
}
}
}
if (IMPORT_DEBUG) echo "Importing: {$current_db_type}<br />";
if (!isset($_POST['dbParamHost']) || !isset($_POST['dbParamUsername']) || !isset($_POST['dbParamPassword']) || !isset($_POST['dbParamDatabase']))
{
$msg = LAN_CONVERT_41;
}
if (!$msg)
{
if (class_exists($current_db_type))
if ($msg) $msg .= "<br />";
if ($import_delete_existing_data) $msg .= LAN_CONVERT_40.'<br />';
$msg .= str_replace(array('--LINES--','--USERS--', '--ERRORS--'),array($line_counter,$write_counter,$error_counter),LAN_CONVERT_35);
}
break;
case 'db' :
if(dbImport() == false)
{
$abandon = true;
};
break;
case 'rss' :
if(rssImport() == false)
{
$abandon = true;
};
break;
}
if ($msg)
{
$emessage->add($msg, E_MESSAGE_INFO); // $ns -> tablerender(LAN_CONVERT_30, $msg);
$msg = '';
}
if ($abandon)
{
// unset($_POST['do_conversion']);
$text = "
<form method='post' action='".e_SELF."'>
<table style='width: 98%;' class='fborder'>
<tr><td class='forumheader3' style='text-align:center'>
<input class='button' type='submit' name='dummy_continue' value='".LAN_CONTINUE."' />
</td>
</tr>
</table></form>";
$ns -> tablerender(LAN_CONVERT_30,$emessage->render(). $text);
require_once(e_ADMIN."footer.php");
exit;
}
}
function rssImport()
{
global $current_db_type, $db_import_blocks, $import_delete_existing_data,$db_blocks_to_import;
$mes = e107::getMessage();
$mes->addDebug("Loading: RSS");
$mes->addWarning("Under Construction");
return dbImport('xml');
}
function dbImport($mode='db')
{
global $current_db_type, $db_import_blocks, $import_delete_existing_data,$db_blocks_to_import;
$mes = e107::getMessage();
// if (IMPORT_DEBUG) echo "Importing: {$current_db_type}<br />";
$mes->addDebug("Loading: ".$current_db_type);
if (class_exists($current_db_type))
{
$mes->addDebug("Class Available: ".$current_db_type);
$converter = new $current_db_type;
}
else
{
$mes->addError(LAN_CONVERT_42);
return false;
}
if($mode == 'db') // Don't do DB check on RSS/XML
{
if (!isset($_POST['dbParamHost']) || !isset($_POST['dbParamUsername']) || !isset($_POST['dbParamPassword']) || !isset($_POST['dbParamDatabase']))
{
$converter = new $current_db_type;
$mes->addError(LAN_CONVERT_41);
return false;
}
else
{
$msg = LAN_CONVERT_42;
}
}
if (!$msg)
{
$result = $converter->db_Connect($_POST['dbParamHost'], $_POST['dbParamUsername'], $_POST['dbParamPassword'], $_POST['dbParamDatabase'], $_POST['dbParamPrefix']);
if ($result !== TRUE)
{
$msg = LAN_CONVERT_43.": ".$result; // db connect failed
$mes->addError(LAN_CONVERT_43.": ".$result); // db connect failed
return false;
}
}
if (!$msg)
{
foreach ($db_import_blocks as $k => $v)
}
foreach ($db_import_blocks as $k => $v)
{
if (isset($db_blocks_to_import[$k]))
{
if (isset($db_blocks_to_import[$k]))
{
$loopCounter = 0;
$errorCounter = 0;
if (is_readable($v['classfile']))
{
require_once($v['classfile']);
}
else
{
$msg = LAN_CONVERT_45.': '.$v['classfile']; // can't read class file.
$mes->addError(LAN_CONVERT_45.': '.$v['classfile']); // can't read class file.
return false;
}
if (!$msg && (varset($_POST["import_block_{$k}"],0) == 1))
if (varset($_POST["import_block_{$k}"],0) == 1)
{
if (IMPORT_DEBUG) echo "Importing: {$k}<br />";
$result = $converter->setupQuery($k,!$import_delete_existing_data);
if ($result !== TRUE)
{
$msg = LAN_CONVERT_44.' '.$k;
// $msg .= "Prefix = ".$converter->DBPrefix;
break;
}
$exporter = new $v['classname']; // Writes the output data
// Do any type-specific default setting
switch ($k)
{
case 'users' :
$exporter->overrideDefault('user_class',$checked_class_list);
break;
}
if ($import_delete_existing_data) $exporter->emptyTargetDB(); // Clean output DB - reasonably safe now
while ($row = $converter->getNext($exporter->getDefaults()))
{
$loopCounter++;
$result = $exporter->saveData($row);
if ($result !== TRUE)
//if (IMPORT_DEBUG) echo "Importing: {$k}<br />";
$mes->addDebug("Importing: ".$k);
$result = $converter->setupQuery($k,!$import_delete_existing_data);
if ($result !== TRUE)
{
$mes->addError(LAN_CONVERT_44.' '.$k); // couldn't set query
// $msg .= "Prefix = ".$converter->DBPrefix;
break;
}
$exporter = new $v['classname']; // Writes the output data
switch ($k) // Do any type-specific default setting
{
$errorCounter++;
$line_error = $exporter->getErrorText($result);
if ($msg) $msg .= "<br />";
$msg .= str_replace(array('--ERRNUM--','--DB--'),array($line_error,$k),LAN_CONVERT_46).$loopCounter;
case 'users' :
$exporter->overrideDefault('user_class',$checked_class_list);
break;
}
}
$converter->endQuery;
unset($exporter);
if ($msg) $msg .= "<br />";
$msg .= str_replace(array('--LINES--','--USERS--', '--ERRORS--','--BLOCK--'),
array($loopCounter,$loopCounter-$errorCounter,$errorCounter, $k),LAN_CONVERT_47);
if ($import_delete_existing_data)
{
$exporter->emptyTargetDB(); // Clean output DB - reasonably safe now
}
while ($row = $converter->getNext($exporter->getDefaults(),$mode))
{
$loopCounter++;
$result = $exporter->saveData($row);
if ($result !== TRUE)
{
$errorCounter++;
$line_error = $exporter->getErrorText($result);
// if ($msg) $msg .= "<br />";
$msg = str_replace(array('--ERRNUM--','--DB--'),array($line_error,$k),LAN_CONVERT_46).$loopCounter;
$mes->addError($msg); // couldn't set query
}
}
$converter->endQuery();
unset($exporter);
$msg = str_replace(array('--LINES--','--USERS--', '--ERRORS--','--BLOCK--'),
array($loopCounter,$loopCounter-$errorCounter,$errorCounter, $k),LAN_CONVERT_47);
$mes->addSuccess($msg); // couldn't set query
}
}
}
}
// $msg = LAN_CONVERT_29;
$abandon = FALSE;
break;
}
if ($msg)
{
$emessage->add($msg, E_MESSAGE_INFO); // $ns -> tablerender(LAN_CONVERT_30, $msg);
$msg = '';
}
if ($abandon)
{
// unset($_POST['do_conversion']);
$text = "
<form method='post' action='".e_SELF."'>
<table style='width: 98%;' class='fborder'>
<tr><td class='forumheader3' style='text-align:center'>
<input class='button' type='submit' name='dummy_continue' value='".LAN_CONTINUE."' />
</td>
</tr>
</table></form>";
$ns -> tablerender(LAN_CONVERT_30, $text);
require_once(e_ADMIN."footer.php");
exit;
}
return true;
// $abandon = FALSE;
}
//======================================================
// Display front page
//======================================================
@@ -411,19 +468,25 @@ function showStartPage()
<tbody>
<tr>
<td>CSV</td>
<td class='center'>".ADMIN_TRUE_ICON."</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td class='center middle'>".$frm->radio('import_type', 'csv')."</td></tr>";
<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($db_import_blocks)-1; $i++)
{
$text .= "<td>&nbsp;</td>";
}
$text .= "<td class='center middle'>".$frm->radio('import_type', 'csv')."</td></tr>";
foreach ($import_class_names as $k => $title)
{
$iconFile = e_PLUGIN."import/images/".str_replace("_import","",strtolower($k)).".png";
$icon = (file_exists($iconFile)) ? "<img src='{$iconFile}' alt='' style='float:left;height:32px;width:32px;margin-right:4px'>" : "";
$text .= "<!-- $title -->
<tr><td>".$title."<div class='smalltext'>".$import_class_comment[$k]."</div></td>\n";
<tr><td>".$icon.$title."<div class='smalltext'>".$import_class_comment[$k]."</div></td>\n";
foreach($db_import_blocks as $key=>$val)
{
@@ -500,6 +563,15 @@ function showImportOptions($mode='csv')
";
}
elseif($mode == 'rss_import')
{
$text .= "<tr>
<td>Feed URL</td>
<td><input class='tbox' type='text' name='rss_feed' size='80' value='{$_POST['rss_feed']}' maxlength='250' />
<input type='hidden' name='import_source' value='rss' />
</td>
</tr>";
}
else
{
$importType = $import_class_names[$mode];
@@ -526,7 +598,13 @@ function showImportOptions($mode='csv')
<td ><input class='tbox' type='text' name='dbParamPrefix' size='30' value='".(varset($_POST['dbParamPrefix']) ? $_POST['dbParamPrefix'] : $import_default_prefix[$mode])."' maxlength='100' />
<input type='hidden' name='import_source' value='db' />
</td>
</tr>
</tr>";
}
if($mode != 'csv')
{
$text .= "
<tr>
<td >$importType ".LAN_CONVERT_24."</td>
<td >";
@@ -543,6 +621,7 @@ function showImportOptions($mode='csv')
$text .= "</td></tr>";
}
$text .= "<tr><td>".LAN_CONVERT_38."</td>
<td><input type='checkbox' name='import_delete_existing_data' value='1'".($import_delete_existing_data ? " checked='checked'" : '')."/>
<span class='smallblacktext'>".LAN_CONVERT_39."</span></td>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

@@ -20,96 +20,169 @@ Root classes for import and saving of data. Application-specific classes build o
class base_import_class
{
var $ourDB = NULL;
var $DBPrefix = '';
var $currentTask = '';
var $copyUserInfo = TRUE;
var $ourDB = NULL;
var $DBPrefix = '';
var $currentTask = '';
var $copyUserInfo = TRUE;
var $arrayData = array();
// Connect to the external DB if not already connected
function db_Connect($server, $user, $password, $database, $prefix)
{
if ($this->ourDB == NULL)
/**
* Connect to the external DB if not already connected
*/
function db_Connect($server, $user, $password, $database, $prefix)
{
$this->ourDB = new db;
$result = $this->ourDB->db_Connect($server, $user, $password, $database);
$this->DBPrefix = $prefix;
if ($result)
{
return $result;
}
if ($this->ourDB == NULL)
{
$this->ourDB = new db;
$result = $this->ourDB->db_Connect($server, $user, $password, $database);
$this->DBPrefix = $prefix;
if ($result)
{
return $result;
}
}
return TRUE;
}
return TRUE;
}
// Set up a query for the specified task. If $blank_user is TRUE, user ID Data in source data is ignored
// Returns TRUE on success. FALSE on error
function setupQuery($task, $blank_user=FALSE)
{
return FALSE;
}
function saveData($dataRecord)
{
switch($this->currentTask)
/**
* Set up a query for the specified task. If $blank_user is TRUE, user ID Data in source data is ignored
* @return boolean TRUE on success. FALSE on error
*/
function setupQuery($task, $blank_user=FALSE)
{
case 'users' :
return $this->saveUserData($dataRecord);
break;
case 'forumdefs' :
return $this->saveForumData($dataRecord);
return FALSE;
case 'forumposts' :
return $this->savePostData($dataRecord);
return FALSE;
case 'polls' :
return FALSE;
case 'news' :
return FALSE;
return FALSE;
}
return FALSE;
function saveData($dataRecord)
{
switch($this->currentTask)
{
case 'users' :
return $this->saveUserData($dataRecord);
break;
case 'news' :
return $this->saveNewsData($dataRecord);
break;
case 'page' :
return $this->savePageData($dataRecord);
break;
case 'links' :
return $this->saveLinksData($dataRecord);
break;
case 'media' :
return $this->saveMediaData($dataRecord);
break;
case 'forumdefs' :
return $this->saveForumData($dataRecord);
break;
case 'forumposts' :
return $this->savePostData($dataRecord);
break;
case 'polls' :
break;
}
return FALSE;
}
// Return the next record as an array. All data has been converted to the appropriate E107 formats
// Return FALSE if no more data
// Its passed a record initialised with the default values
function getNext($initial)
{
$result = $this->ourDB->db_Fetch();
if (!$result) return FALSE;
switch($this->currentTask)
function getNext($initial,$mode='db')
{
case 'users' :
return $this->copyUserData($initial, $result);
break;
case 'forumdefs' :
return FALSE;
case 'forumposts' :
return FALSE;
case 'polls' :
return FALSE;
case 'news' :
return FALSE;
if($mode == 'db')
{
$result = $this->ourDB->db_Fetch();
}
else
{
$result = current($this->arrayData);
next($this->arrayData);
}
if (!$result) return FALSE;
switch($this->currentTask)
{
case 'users' :
return $this->copyUserData($initial, $result);
break;
case 'news' :
return $this->copyNewsData($initial, $result);
break;
case 'page' :
return $this->copyPageData($initial, $result);
break;
case 'links' :
return $this->copyLinksData($initial, $result);
break;
case 'media' :
return $this->copyMediaData($initial, $result);
break;
case 'forumdefs' :
break;
case 'forumposts' :
break;
case 'polls' :
break;
}
return FALSE;
}
return FALSE;
}
// Called to signal that current task is complete; tidy up as required
function endQuery()
{
$this->currentTask = '';
}
// Called to signal that current task is complete; tidy up as required
function endQuery()
{
$this->currentTask = '';
}
// Empty function which descendants can inherit from
function copyUserData(&$target, &$source)
{
return $target;
}
// Empty functions which descendants can inherit from
function copyUserData(&$target, &$source)
{
return $target;
}
function copyNewsData(&$target, &$source)
{
return $target;
}
function copyPageData(&$target, &$source)
{
return $target;
}
function copyLinksData(&$target, &$source)
{
return $target;
}
function copyMediaData(&$target, &$source)
{
return $target;
}
}

View File

@@ -73,5 +73,5 @@ define('LAN_CONVERT_43','Error connecting to source database');
define('LAN_CONVERT_44','Query setup error for ');
define('LAN_CONVERT_45','Cannot read import code file');
define('LAN_CONVERT_46','Error: --ERRNUM-- while writing to --DB-- database, line ');
define('LAN_CONVERT_47','Block --BLOCK-- import completed. --LINES-- read, --USERS-- added, --ERRORS-- errors');
define('LAN_CONVERT_47','Batch --BLOCK-- import completed. --LINES-- read, --USERS-- added, --ERRORS-- errors');
define('LAN_CONVERT_48','Forum posts');

View File

@@ -0,0 +1,83 @@
<?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/mambo_import_class.php,v $
* $Revision: 11315 $
* $Date: 2010-02-10 10:18:01 -0800 (Wed, 10 Feb 2010) $
* $Author: secretr $
*/
// Each import file has an identifier which must be the same for:
// a) This file name - add '_class.php' to get the file name
// b) The array index of certain variables
// Array element key defines the function prefix and the class name; value is displayed in drop-down selection box
$import_class_names['joomla_import'] = 'Joomla';
$import_class_comment['joomla_import'] = 'Untested - need feedback from users ';
$import_class_support['joomla_import'] = array('users');
$import_default_prefix['joomla_import'] = 'jos_';
// Mambo and joomla have the same DB format apart from the default prefix - 'jos_' for Joomla
require_once('import_classes.php');
class joomla_import extends base_import_class
{
// Set up a query for the specified task.
// Returns TRUE on success. FALSE on error
function setupQuery($task, $blank_user=FALSE)
{
if ($this->ourDB == NULL) return FALSE;
switch ($task)
{
case 'users' :
$result = $this->ourDB->db_Select_gen("SELECT * FROM {$this->DBPrefix}users");
if ($result === FALSE) return FALSE;
break;
default :
return FALSE;
}
$this->copyUserInfo = !$blank_user;
$this->currentTask = $task;
return TRUE;
}
//------------------------------------
// Internal functions below here
//------------------------------------
// Copy data read from the DB into the record to be returned.
function copyUserData(&$target, &$source)
{
if ($this->copyUserInfo) $target['user_id'] = $source['id'];
$target['user_name'] = $source['name'];
$target['user_loginname'] = $source['username'];
$target['user_password'] = $source['password'];
$target['user_email'] = $source['email'];
// $target['user_hideemail'] = $source['user_viewemail'];
$target['user_join'] = $source['registerDate'];
$target['user_admin'] = ($source['usertype'] == 'superadministrator') ? 1 : 0;
if ($target['user_admin'] != 0)
{
$target['user_perms'] = '0.';
}
$target['user_lastvisit'] = $source['lastvisitDate'];
$target['user_login'] = $source['name'];
$target['user_ban'] = ($source['block'] ? 2 : 0);
return $target;
}
}
?>

View File

@@ -0,0 +1,294 @@
<?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/wordpress_import_class.php,v $
* $Revision: 11315 $
* $Date: 2010-02-10 10:18:01 -0800 (Wed, 10 Feb 2010) $
* $Author: secretr $
*/
// This must be an incredibly pointless file! But it does allow testing of the basic plugin structure.
// Each import file has an identifier which must be the same for:
// a) This file name - add '_class.php' to get the file name
// b) The array index of certain variables
// Array element key defines the function prefix and the class name; value is displayed in drop-down selection box
$import_class_names['rss_import'] = 'RSS';
$import_class_comment['rss_import'] = '(work in progress)';
$import_class_support['rss_import'] = array('news','page','links');
$import_default_prefix['rss_import'] = '';
require_once('import_classes.php');
class rss_import extends base_import_class
{
// Set up a query for the specified task.
// Returns TRUE on success. FALSE on error
function setupQuery($task, $blank_user=FALSE)
{
$xml = e107::getXml();
require_once(e_HANDLER."magpie_rss.php");
// $file = "http://www.e107.org/releases.php"; //pluginfeed.php or similar.
// $file = "http://localhost:8080/e107_0.8/e107_plugins/release/release.php"; // temporary testing
$file = "http://raelianews.org/rss";
$xml->setOptArrayTags('plugin'); // make sure 'plugin' tag always returns an array
switch ($task)
{
case 'users' :
//$query = "SELECT * FROM {$this->DBPrefix}users WHERE `user_id` != 1";
break;
case 'news' :
// $result = $xml->loadXMLfile($file,true);
// $rawData = $xml->getRemoteFile($file);
// $rss = new MagpieRSS( $rawData );
// $array = $xml->xml2array($rss);
$xml->setOptArrayTags('item'); // make sure 'plugin' tag always returns an array
$array = $xml->loadXMLfile($file,'advanced');
$this->arrayData = $array['channel']['item'];
if ($result === FALSE) return FALSE;
break;
case 'page' :
if ($result === FALSE) return FALSE;
break;
case 'media' :
break;
case 'links':
if ($result === FALSE) return FALSE;
break;
default :
return FALSE;
}
$this->copyUserInfo = !$blank_user;
$this->currentTask = $task;
return TRUE;
}
//------------------------------------
// Internal functions below here
//------------------------------------
/**
* Align source data to e107 User Table
* @param $target array - default e107 target values for e107_user table.
* @param $source array - WordPress table data
*/
function copyUserData(&$target, &$source)
{
}
/**
* Align source data to e107 News Table
* @param $target array - default e107 target values for e107_news table.
* @param $source array - WordPress table data
*/
function copyNewsData(&$target, &$source)
{
/* Example:
[ID] => 88
[post_author] => 1
[post_date] => 2012-01-25 04:11:22
[post_date_gmt] => 2012-01-25 09:11:22
[post_content] => [gallery itemtag="div" icontag="span" captiontag="p" link="file"]
[post_title] => Media Gallery
[post_excerpt] =>
[post_status] => inherit
[comment_status] => open
[ping_status] => open
[post_password] =>
[post_name] => 10-revision-6
[to_ping] =>
[pinged] =>
[post_modified] => 2012-01-25 04:11:22
[post_modified_gmt] => 2012-01-25 09:11:22
[post_content_filtered] =>
[post_parent] => 10
[guid] => http://siteurl.com/2012/01/25/10-revision-6/
[menu_order] => 0
[post_type] => post
[post_mime_type] =>
[comment_count] => 0
*/
// $target['news_id'] = $source['ID'];
$target['news_title'] = $source['post_title'];
$target['news_sef'] = $source['post_name'];
$target['news_body'] = $source['post_content'];
// $target['news_extended'] = '';
// $target['news_meta_keywords'] = '';
// $target['news_meta_description'] = '';
$target['news_datestamp'] = strtotime($source['post_date']);
$target['news_author'] = $source['post_author'];
// $target['news_category'] = '';
$target['news_allow_comments'] = ($source['comment_status']=='open') ? 1 : 0;
$target['news_start'] = '';
$target['news_end'] = '';
$target['news_class'] = '';
$target['news_render_type'] = '';
$target['news_comment_total'] = $source['comment_count'];
$target['news_summary'] = $source['post_excerpt'];
$target['news_thumbnail'] = '';
$target['news_sticky'] = '';
// return $target; // comment out to debug
// DEBUG INFO BELOW.
$this->renderDebug($source,$target);
}
/**
* Align source data to e107 Page Table
* @param $target array - default e107 target values for e107_page table.
* @param $source array - WordPress table data
*/
function copyPageData(&$target, &$source)
{
$tp = e107::getParser();
/* post_status:
publish - A published post or page
inherit - a revision
pending - post is pending review
private - a private post
future - a post to publish in the future
draft - a post in draft status
trash - post is in trashbin (available with 2.9)
*/
if($source['post_status']=='private' || $source['post_status']=='future' || $source['post_status'] == 'draft')
{
$target['page_class'] = e_UC_ADMIN;
}
// $target['page_id'] = $source['ID']; // auto increment
$target['page_title'] = $source['post_title'];
$target['page_sef'] = $source['post_name'];
$target['page_text'] = "[html]".$source['post_content']."[/html]";
$target['page_metakeys'] = '';
$target['page_metadscr'] = '';
$target['page_datestamp'] = strtotime($source['post_date']);
$target['page_author'] = $source['post_author'];
// $target['page_category'] = '',
$target['page_comment_flag'] = ($source['comment_status']=='open') ? 1 : 0;
$target['page_password'] = $source['post_password'];
return $target; // comment out to debug
// DEBUG INFO BELOW.
$this->renderDebug($source,$target);
}
/**
* Align source data to e107 Links Table
* @param $target array - default e107 target values for e107_links table.
* @param $source array - WordPress table data
*/
function copyLinksData(&$target, &$source)
{
$tp = e107::getParser();
/* WP
link_id
link_url
link_name
link_image
link_target
link_description
link_visible
link_owner
link_rating
link_updated
link_rel
link_notes
link_rss
*
* e107
* link_id
link_name
link_url
link_description
link_button
link_category
link_order
link_parent
link_open
link_class
link_function
link_sefurl
*/
// $target['page_id'] = $source['ID']; // auto increment
$target['link_name'] = $source['post_title'];
$target['link_url'] = $source['post_name'];
$target['link_description'] = "[html]".$source['post_content']."[/html]";
$target['link_button'] = '';
$target['link_category'] = '';
$target['link_order'] = strtotime($source['post_date']);
$target['link_parent'] = $source['post_author'];
$target['link_open'] = '';
$target['link_class'] = '';
$target['link_sefurl'] = $source['post_password'];
// return $target; // comment out to debug
// DEBUG INFO BELOW.
$this->renderDebug($source,$target);
}
function renderDebug($source,$target)
{
echo "
<div style='width:1000px'>
<table style='width:100%'>
<tr>
<td style='width:500px;padding:10px'>".print_a($source,TRUE)."</td>
<td style='border-left:1px solid black;padding:10px'>".print_a($target,TRUE)."</td>
</tr>
</table>
</div>";
}
}
?>

View File

@@ -0,0 +1,354 @@
<?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/wordpress_import_class.php,v $
* $Revision$
* $Date$
* $Author$
*/
// This must be an incredibly pointless file! But it does allow testing of the basic plugin structure.
// Each import file has an identifier which must be the same for:
// a) This file name - add '_class.php' to get the file name
// b) The array index of certain variables
// Array element key defines the function prefix and the class name; value is displayed in drop-down selection box
$import_class_names['wordpress_import'] = 'Wordpress';
$import_class_comment['wordpress_import'] = 'Tested with version 2.8.x (salted passwords)';
$import_class_support['wordpress_import'] = array('users','news','page','links');
$import_default_prefix['wordpress_import'] = 'wp_';
require_once('import_classes.php');
class wordpress_import extends base_import_class
{
// Set up a query for the specified task.
// Returns TRUE on success. FALSE on error
function setupQuery($task, $blank_user=FALSE)
{
if ($this->ourDB == NULL) return FALSE;
switch ($task)
{
case 'users' :
//$query = "SELECT * FROM {$this->DBPrefix}users WHERE `user_id` != 1";
$query = "SELECT u.*,
w.meta_value AS admin,
f.meta_value as firstname,
l.meta_value as lastname
FROM {$this->DBPrefix}users AS u
LEFT JOIN {$this->DBPrefix}usermeta AS w ON (u.ID = w.user_id AND w.meta_key = 'wp_capabilities')
LEFT JOIN {$this->DBPrefix}usermeta AS f ON (u.ID = f.user_id AND f.meta_key = 'first_name')
LEFT JOIN {$this->DBPrefix}usermeta AS l ON (u.ID = l.user_id AND l.meta_key = 'last_name')
GROUP BY u.ID";
// $this->ourDB -> db_Select_gen($query);
$result = $this->ourDB->db_Select_gen($query);
if ($result === FALSE) return FALSE;
break;
case 'userclass' :
/* For reference: (stored in usermeta -> wp_capabilities
* Administrator - Somebody who has access to all the administration features
* Editor - Somebody who can publish posts, manage posts as well as manage other people's posts, etc.
* Author - Somebody who can publish and manage their own posts
* Contributor - Somebody who can write and manage their posts but not publish posts
* Subscriber - Somebody who can read comments/comment/receive news letters, etc.
*/
break;
case 'news' :
$query = "SELECT * FROM {$this->DBPrefix}posts WHERE post_type = 'post' AND post_status !='trash' ORDER BY ID";
$result = $this->ourDB->db_Select_gen($query);
if ($result === FALSE) return FALSE;
break;
case 'page' :
$query = "SELECT * FROM {$this->DBPrefix}posts WHERE post_type = 'page' AND post_status !='trash' ORDER BY ID";
$result = $this->ourDB->db_Select_gen($query);
if ($result === FALSE) return FALSE;
break;
case 'media' :
$query = "SELECT * FROM {$this->DBPrefix}posts WHERE post_type = 'attachment' AND post_status !='trash' ORDER BY ID";
$result = $this->ourDB->db_Select_gen($query);
if ($result === FALSE) return FALSE;
break;
case 'links':
$query = "SELECT * FROM {$this->DBPrefix}links WHERE link_id !='' ORDER BY link_id";
$result = $this->ourDB->db_Select_gen($query);
if ($result === FALSE) return FALSE;
break;
default :
return FALSE;
}
$this->copyUserInfo = !$blank_user;
$this->currentTask = $task;
return TRUE;
}
//------------------------------------
// Internal functions below here
//------------------------------------
/**
* Align source data to e107 User Table
* @param $target array - default e107 target values for e107_user table.
* @param $source array - WordPress table data
*/
function copyUserData(&$target, &$source)
{
$user_meta = unserialize($source['admin']);
if ($this->copyUserInfo)
{
$target['user_id'] = $source['ID'];
}
$target['user_name'] = $source['user_nicename'];
$target['user_loginname'] = $source['user_login'];
$target['user_password'] = $source['user_pass']; // needs to be salted!!!!
$target['user_email'] = $source['user_email'];
$target['user_hideemail'] = $source['user_hideemail'];
$target['user_join'] = strtotime($source['user_registered']);
$target['user_admin'] = ($user_meta['administrator'] == 1) ? 1 : 0;
$target['user_lastvisit'] = $source['user_lastvisit'];
$target['user_login'] = $source['firstname']." ".$source['lastname'];
$target['user_ban'] = $source['user_ban'];
$target['user_customtitle'] = $source['display_name'];
$target['user_sess'] = $source['user_sess']; // Photo
$target['user_signature'] = $source['user_signature'];
$target['user_image'] = $source['user_image']; // Avatar
$target['user_currentvisit'] = $source['user_currentvisit'];
$target['user_lastpost'] = $source['user_lastpost'];
$target['user_chats'] = $source['user_chats'];
$target['user_comments'] = $source['user_comments'];
$target['user_ip'] = $source['user_ip'];
$target['user_prefs'] = $source['user_prefs'];
$target['user_visits'] = $source['user_visits'];
$target['user_class'] = $source['user_class'];
$target['user_perms'] = $source['user_perms'];
$target['user_xup'] = $source['user_xup'];
$target['user_language'] = $source['user_language'];
$target['user_country'] = $source['user_country'];
$target['user_location'] = $source['user_location'];
$target['user_aim'] = $source['user_aim'];
$target['user_icq'] = $source['user_icq'];
$target['user_yahoo'] = $source['user_yahoo'];
$target['user_msn'] = $source['user_msn'];
$target['user_homepage'] = $source['user_url'];
$target['user_birthday'] = $source['user_birthday'];
$target['user_timezone'] = $source['user_timezone'];
$this->renderDebug($source,$target);
//return $target;
}
/**
* Align source data to e107 News Table
* @param $target array - default e107 target values for e107_news table.
* @param $source array - WordPress table data
*/
function copyNewsData(&$target, &$source)
{
/* Example:
[ID] => 88
[post_author] => 1
[post_date] => 2012-01-25 04:11:22
[post_date_gmt] => 2012-01-25 09:11:22
[post_content] => [gallery itemtag="div" icontag="span" captiontag="p" link="file"]
[post_title] => Media Gallery
[post_excerpt] =>
[post_status] => inherit
[comment_status] => open
[ping_status] => open
[post_password] =>
[post_name] => 10-revision-6
[to_ping] =>
[pinged] =>
[post_modified] => 2012-01-25 04:11:22
[post_modified_gmt] => 2012-01-25 09:11:22
[post_content_filtered] =>
[post_parent] => 10
[guid] => http://siteurl.com/2012/01/25/10-revision-6/
[menu_order] => 0
[post_type] => post
[post_mime_type] =>
[comment_count] => 0
*/
// $target['news_id'] = $source['ID'];
$target['news_title'] = $source['post_title'];
$target['news_sef'] = $source['post_name'];
$target['news_body'] = $source['post_content'];
// $target['news_extended'] = '';
// $target['news_meta_keywords'] = '';
// $target['news_meta_description'] = '';
$target['news_datestamp'] = strtotime($source['post_date']);
$target['news_author'] = $source['post_author'];
// $target['news_category'] = '';
$target['news_allow_comments'] = ($source['comment_status']=='open') ? 1 : 0;
$target['news_start'] = '';
$target['news_end'] = '';
$target['news_class'] = '';
$target['news_render_type'] = '';
$target['news_comment_total'] = $source['comment_count'];
$target['news_summary'] = $source['post_excerpt'];
$target['news_thumbnail'] = '';
$target['news_sticky'] = '';
return $target; // comment out to debug
// DEBUG INFO BELOW.
$this->renderDebug($source,$target);
}
/**
* Align source data to e107 Page Table
* @param $target array - default e107 target values for e107_page table.
* @param $source array - WordPress table data
*/
function copyPageData(&$target, &$source)
{
$tp = e107::getParser();
/* post_status:
publish - A published post or page
inherit - a revision
pending - post is pending review
private - a private post
future - a post to publish in the future
draft - a post in draft status
trash - post is in trashbin (available with 2.9)
*/
if($source['post_status']=='private' || $source['post_status']=='future' || $source['post_status'] == 'draft')
{
$target['page_class'] = e_UC_ADMIN;
}
// $target['page_id'] = $source['ID']; // auto increment
$target['page_title'] = $source['post_title'];
$target['page_sef'] = $source['post_name'];
$target['page_text'] = "[html]".$source['post_content']."[/html]";
$target['page_metakeys'] = '';
$target['page_metadscr'] = '';
$target['page_datestamp'] = strtotime($source['post_date']);
$target['page_author'] = $source['post_author'];
// $target['page_category'] = '',
$target['page_comment_flag'] = ($source['comment_status']=='open') ? 1 : 0;
$target['page_password'] = $source['post_password'];
return $target; // comment out to debug
// DEBUG INFO BELOW.
$this->renderDebug($source,$target);
}
/**
* Align source data to e107 Links Table
* @param $target array - default e107 target values for e107_links table.
* @param $source array - WordPress table data
*/
function copyLinksData(&$target, &$source)
{
$tp = e107::getParser();
/* WP
link_id
link_url
link_name
link_image
link_target
link_description
link_visible
link_owner
link_rating
link_updated
link_rel
link_notes
link_rss
*
* e107
* link_id
link_name
link_url
link_description
link_button
link_category
link_order
link_parent
link_open
link_class
link_function
link_sefurl
*/
// $target['page_id'] = $source['ID']; // auto increment
$target['link_name'] = $source['post_title'];
$target['link_url'] = $source['post_name'];
$target['link_description'] = "[html]".$source['post_content']."[/html]";
$target['link_button'] = '';
$target['link_category'] = '';
$target['link_order'] = strtotime($source['post_date']);
$target['link_parent'] = $source['post_author'];
$target['link_open'] = '';
$target['link_class'] = '';
$target['link_sefurl'] = $source['post_password'];
// return $target; // comment out to debug
// DEBUG INFO BELOW.
$this->renderDebug($source,$target);
}
function renderDebug($source,$target)
{
echo "
<div style='width:1000px'>
<table style='width:100%'>
<tr>
<td style='width:500px;padding:10px'>".print_a($source,TRUE)."</td>
<td style='border-left:1px solid black;padding:10px'>".print_a($target,TRUE)."</td>
</tr>
</table>
</div>";
}
}
?>

View File

@@ -1,141 +0,0 @@
<?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/wordpress_import_class.php,v $
* $Revision$
* $Date$
* $Author$
*/
// This must be an incredibly pointless file! But it does allow testing of the basic plugin structure.
// Each import file has an identifier which must be the same for:
// a) This file name - add '_class.php' to get the file name
// b) The array index of certain variables
// Array element key defines the function prefix and the class name; value is displayed in drop-down selection box
$import_class_names['wordpress_import'] = 'Wordpress';
$import_class_comment['wordpress_import'] = 'Tested with version 2.8.x (salted passwords)';
$import_class_support['wordpress_import'] = array('users');
$import_default_prefix['wordpress_import'] = 'wp_';
require_once('import_classes.php');
class wordpress_import extends base_import_class
{
// Set up a query for the specified task.
// Returns TRUE on success. FALSE on error
function setupQuery($task, $blank_user=FALSE)
{
if ($this->ourDB == NULL) return FALSE;
switch ($task)
{
case 'users' :
$query = "SELECT * FROM {$this->DBPrefix}users WHERE `user_id` != 1";
$query = "SELECT u.*,
w.meta_value AS admin,
f.meta_value as firstname,
l.meta_value as lastname
FROM {$this->DBPrefix}users AS u
LEFT JOIN {$this->DBPrefix}usermeta AS w ON (u.ID = w.user_id AND w.meta_key = 'wp_capabilities')
LEFT JOIN {$this->DBPrefix}usermeta AS f ON (u.ID = f.user_id AND f.meta_key = 'first_name')
LEFT JOIN {$this->DBPrefix}usermeta AS l ON (u.ID = l.user_id AND l.meta_key = 'last_name')
GROUP BY u.ID";
$this->ourDB -> db_Select_gen($query);
$result = $this->ourDB->db_Select_gen($query);
if ($result === FALSE) return FALSE;
break;
case 'userclass' :
/* For reference: (stored in usermeta -> wp_capabilities
* Administrator - Somebody who has access to all the administration features
* Editor - Somebody who can publish posts, manage posts as well as manage other people's posts, etc.
* Author - Somebody who can publish and manage their own posts
* Contributor - Somebody who can write and manage their posts but not publish posts
* Subscriber - Somebody who can read comments/comment/receive news letters, etc.
*/
break;
default :
return FALSE;
}
$this->copyUserInfo = !$blank_user;
$this->currentTask = $task;
return TRUE;
}
//------------------------------------
// Internal functions below here
//------------------------------------
// Copy data read from the DB into the record to be returned.
function copyUserData(&$target, &$source)
{
$user_meta = unserialize($source['admin']);
if ($this->copyUserInfo)
{
$target['user_id'] = $source['ID'];
}
$target['user_name'] = $source['user_nicename'];
$target['user_loginname'] = $source['user_login'];
$target['user_password'] = $source['user_pass']; // needs to be salted!!!!
$target['user_email'] = $source['user_email'];
$target['user_hideemail'] = $source['user_hideemail'];
$target['user_join'] = strtotime($source['user_registered']);
$target['user_admin'] = ($user_meta['administrator'] == 1) ? 1 : 0;
$target['user_lastvisit'] = $source['user_lastvisit'];
$target['user_login'] = $source['firstname']." ".$source['lastname'];
$target['user_ban'] = $source['user_ban'];
$target['user_customtitle'] = $source['display_name'];
$target['user_sess'] = $source['user_sess']; // Photo
$target['user_signature'] = $source['user_signature'];
$target['user_image'] = $source['user_image']; // Avatar
$target['user_currentvisit'] = $source['user_currentvisit'];
$target['user_lastpost'] = $source['user_lastpost'];
$target['user_chats'] = $source['user_chats'];
$target['user_comments'] = $source['user_comments'];
$target['user_ip'] = $source['user_ip'];
$target['user_prefs'] = $source['user_prefs'];
$target['user_visits'] = $source['user_visits'];
$target['user_class'] = $source['user_class'];
$target['user_perms'] = $source['user_perms'];
$target['user_xup'] = $source['user_xup'];
$target['user_language'] = $source['user_language'];
$target['user_country'] = $source['user_country'];
$target['user_location'] = $source['user_location'];
$target['user_aim'] = $source['user_aim'];
$target['user_icq'] = $source['user_icq'];
$target['user_yahoo'] = $source['user_yahoo'];
$target['user_msn'] = $source['user_msn'];
$target['user_homepage'] = $source['user_url'];
$target['user_birthday'] = $source['user_birthday'];
$target['user_timezone'] = $source['user_timezone'];
// user_pass user_nicename user_email user_url user_registered user_activation_key user_status display_name
return $target;
}
}
?>