1
0
mirror of https://github.com/e107inc/e107.git synced 2025-04-21 05:02:02 +02:00

Remove redundant files

This commit is contained in:
e107steved 2009-12-03 22:35:38 +00:00
parent 13af90e1ab
commit a990899754
7 changed files with 0 additions and 1286 deletions

View File

@ -1,2 +0,0 @@
extra,add login name,simple,user_name,user_password,user_loginname
sq,basic information single quotes,simple_sq,user_name,user_password

View File

@ -1,103 +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_files/import/e107_import_class.php,v $
* $Revision: 1.3 $
* $Date: 2009-11-18 01:04:43 $
* $Author: e107coders $
*/
// 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['e107_import'] = 'E107';
$import_class_comment['e107_import'] = 'Reads 0.7 and 0.8 version files';
$import_class_support['e107_import'] = array('users');
$import_default_prefix['e107_import'] = 'e107_';
require_once('import_classes.php');
class e107_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}user WHERE `user_id` != 1");
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['user_id'];
$target['user_name'] = $source['user_name'];
$target['user_loginname'] = $source['user_loginname'];
$target['user_password'] = $source['user_password'];
$target['user_email'] = $source['user_email'];
$target['user_hideemail'] = $source['user_hideemail'];
$target['user_join'] = $source['user_join'];
$target['user_admin'] = $source['user_admin'];
$target['user_lastvisit'] = $source['user_lastvisit'];
$target['user_login'] = $source['user_login'];
$target['user_ban'] = $source['user_ban'];
$target['user_customtitle'] = $source['user_customtitle'];
$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_forums'] = $source['user_forums'];
$target['user_ip'] = $source['user_ip'];
$target['user_prefs'] = $source['user_prefs'];
$target['user_viewed'] = $source['user_viewed'];
$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_homepage'];
$target['user_birthday'] = $source['user_birthday'];
$target['user_timezone'] = $source['user_timezone'];
return $target;
}
}
?>

View File

@ -1,170 +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_files/import/import_classes.php,v $
* $Revision: 1.3 $
* $Date: 2009-11-18 01:04:43 $
* $Author: e107coders $
*/
/*
Root classes for import and saving of data. Application-specific classes build on these
*/
class base_import_class
{
var $ourDB = NULL;
var $DBPrefix = '';
var $currentTask = '';
var $copyUserInfo = TRUE;
// Connect to the DB if not already connected
function db_Connect($server, $user, $password, $database, $prefix)
{
if ($this->ourDB == NULL)
{
$this->ourDB = new db;
$result = $this->ourDB->db_Connect($server, $user, $password, $database);
if ($result) return $result;
$this->DBPrefix = $prefix;
}
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;
}
// 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)
{
case 'users' :
return $this->copyUserData($initial, $result);
break;
case 'forumdefs' :
return FALSE;
case 'forumposts' :
return FALSE;
case 'polls' :
return FALSE;
case 'news' :
return FALSE;
}
return FALSE;
}
// 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;
}
}
//===========================================================
// 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)
{
$bbparam = substr($bbword,$temp);
$bbword = substr($bbword,0,-strlen($bbparam));
}
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.proc_bb($middlebit,$options,$maptable).$bbend.proc_bb($lastbit,$options,$maptable);
}
}
else
{
$nextchar = $firstend+1;
}
} //endwhile;
}
?>

View File

@ -1,104 +0,0 @@
E107 IMPORT FACILITY FOR 0.8
============================
This facility imports data from an existing non-E107 CMS or other sources into E107.
**************** CAUTION!!! EXISTING DATA WILL BE DELETED FROM YOUR E107 INSTALLATION *****************
**************** THIS IS BETA CODE AT PRESENT - it may (probably will) contain bugs ! *********************
If you use these routines, please help to make them better and report success or any problems to steved by PM.
If you encounter problems, it may help solve them if you are able to provide a sample database which demonstrates the problem. It doesn't have to be massive - often 5-10 records is plenty. A zipped export from PHPMyAdmin is often simplest.
Prerequisites
-------------
You require an existing E107 V0.8 installation; create one if you are not working with an existing installation.
This installation must include all plugins and features for which you want to import data - for example:
- if you want to import forum threads, the E107 forum plugin must be installed.
- If you want to import certain predefined extended user fields, they must be set up
Other than configuration, you will usually want to import into a 'clean' installation - one which hasn't been used.
The import will in most cases delete and/or overwrite existing data, so BACK UP YOUR E107 INSTALLATION BEFORE PROCEEDING.
Running the Import
------------------
Log in to your E107 site as the main admin (this must be the very first user you created, which has an ID of 1).
Point your browser at: yoursite/e107_files/import/import_to_e107.php
You should see the front screen of the import routines.
Select the appropriate options and click on 'continue'.
Note that the import can take a long time if you have a large amount of 'source' data; you may need to temporarily adjust settings in php.ini to ensure that PHP doesn't time out before completion. (It is often simplest to run the import on a local set of databases using xampp or similar, so that you have complete control over the setup).
CSV Data import
---------------
This is the simplest way to import a list of users; a suitable file can be created as an export from many databases and spreadsheets, and is quite simple to create in a basic text editor such as Notepad.
Each line of the input text file corresponds to a single user, with the various values separated by commas, thus:
fred,password
jim,jimspassword
Make sure there are no spaces at the beginning or end of values (although there may be spaces in the middle).
E107 requires passwords to be MD5-encoded; if yours are in 'plain text' just tick the box 'Password in CSV file is not already encrypted' and the import routine will encode them during processing.
Custom CSV Import
-----------------
If more than basic username/password information is available, you'll want to use a custom CSV import. These are specified in lines of the file csv_import.txt. Some examples are already in the file; add your special entries at the end.
First step is to determine what data values you have available for import, and then tell the import routine the format of your CSV file. Must likely values you'll have are:
user_loginname - the 'login name' for the user
user_name - the 'display name' for the user - may be the same as the login name
user_password - the user's password; either in 'clear text' or MD5 encoded
user_image - path to the user's avatar
user_session - path to the user's photo
(for other values, just identify the field name in E107's 'user' table. You can also specify the predefined fields of E107's extended user data table).
Within file csv_import.txt, each line is itself CSV-formatted data, defining an import format:
Field 1 - an internal 'name' for the format - something fairly short
Field 2 - a description for the format - this is displayed in selection dropdowns
Field 3 - a format specifier code (see the list later)
Field 4 on are the names of data fields, in the order they will appear in the data (CSV) file
There are some example formats already in this file; it may be edited to add more.
Format
Name Delimiter Enclosure
--------------------------------------------
simple ',' none
simple_sq ',' single quote (')
simple_dq ',' double quote (")
simple_semi ',' semi-colon (;)
simple_bar ',' 'pipe' (|)
During the actual import some lines of data may be rejected; an error message is given, together with the line number of the data file.
Database Import
---------------
Converters have been written for most popular Content Management systems and BBS, and appear in the drop-down.
At present only user data is imported, to an extent which depends on the source data and our knowledge of the data format.
Extended user fields are imported if present in the E107 database.

View File

@ -1,695 +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_files/import/import_to_e107.php,v $
* $Revision: 1.3 $
* $Date: 2009-11-18 01:04:43 $
* $Author: e107coders $
*/
/*
Routine manages import from other databases
Options supported:
CSV (with format file)
Mambo/Joomla
PHPBB2
PHPBB3
SMF
PHPNuke
proboards
PHPFusion
*/
define('IMPORT_DEBUG',FALSE);
//define('IMPORT_DEBUG',TRUE);
require_once("../../class2.php");
// Language defs - maybe move out later
define('LAN_CONTINUE','Continue');
define('LAN_CONVERT_01','E107 Import utility');
define('LAN_CONVERT_02','This module allows you to import various data into E107');
define('LAN_CONVERT_03','You must start with a clean E107 database, other than the main admin user (ID=1)');
define('LAN_CONVERT_04','Field(s) left blank, please go back and re-enter values.');
define('LAN_CONVERT_05','*** IMPORTANT ***<br />Running this script may empty many of your E107 tables - make sure you have a full backup before continuing!');
define('LAN_CONVERT_06','Import data type');
define('LAN_CONVERT_07','CSV Format Specification');
define('LAN_CONVERT_08','Existing database');
define('LAN_CONVERT_09','Connection details for source database');
define('LAN_CONVERT_10','Passwords in source file are not encrypted');
define('LAN_CONVERT_11','Source data details');
define('LAN_CONVERT_12','Basic username and password');
define('LAN_CONVERT_13','CSV File');
define('LAN_CONVERT_14','Format of import database');
define('LAN_CONVERT_15','No import converters available');
define('LAN_CONVERT_16','Initial user class(es)');
define('LAN_CONVERT_17','Password in CSV file is not already encrypted');
define('LAN_CONVERT_18','(Password must be stored with MD5 encryption)');
define('LAN_CONVERT_19','Host');
define('LAN_CONVERT_20','Username');
define('LAN_CONVERT_21','Password');
define('LAN_CONVERT_22','Database');
define('LAN_CONVERT_23','Table Prefix');
define('LAN_CONVERT_24','Areas to import');
define('LAN_CONVERT_25','Users');
define('LAN_CONVERT_26','Forum Definitions');
define('LAN_CONVERT_27','Polls');
define('LAN_CONVERT_28','News');
define('LAN_CONVERT_29','Database import completed');
define('LAN_CONVERT_30','Import routine Information');
define('LAN_CONVERT_31','CSV data file does not exist, or invalid permissions');
define('LAN_CONVERT_32','Error reading CSV data file');
define('LAN_CONVERT_33','Error in CSV data line ');
define('LAN_CONVERT_34','Error: --ERRNUM-- while writing to user database, line ');
define('LAN_CONVERT_35','CSV import completed. --LINES-- read, --USERS-- users added, --ERRORS-- errors');
define('LAN_CONVERT_36','Filename for CSV data');
define('LAN_CONVERT_37','Invalid format specification for import type');
define('LAN_CONVERT_38','Delete existing data');
define('LAN_CONVERT_39','(If you don\'t, the posters of imported data will be shown as \'Anonymous\')');
define('LAN_CONVERT_40','Existing data deleted');
define('LAN_CONVERT_41','Required database access field is empty');
define('LAN_CONVERT_42','Error in definition file - required class does not exist');
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_48','Forum posts');
define('LAN_CONVERT_49','');
define('LAN_CONVERT_50','');
define('LAN_CONVERT_51','');
define('LAN_CONVERT_52','');
define('LAN_CONVERT_53','');
define('LAN_CONVERT_54','');
define('LAN_CONVERT_55','');
define('LAN_CONVERT_56','');
define('LAN_CONVERT_57','');
define('LAN_CONVERT_58','');
define('LAN_CONVERT_59','');
define('LAN_CONVERT_60','');
// Source DB types (i.e. CMS types) supported. Key of each element is the 'short code' for the type
$import_class_names = array(); // Title
$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'),
'forumdefs' => array('message' => LAN_CONVERT_26),
'forumposts' => array('message' => LAN_CONVERT_48),
'polls' => array('message' => LAN_CONVERT_27),
'news' => array('message' => LAN_CONVERT_28)
);
// 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_FILE.'import', "^.+?_import_class\.php$", "standard", 1);
foreach($importClassList as $file)
{
$tag = str_replace('_class.php','',$file['fname']);
include_once($file['fpath'].$file['fname']); // This will set up the variables
}
unset($importClassList);
unset($fl);
$import_source = varset($_POST['import_source'],'csv');
$checked_class_list = implode(',',varset($_POST['classes_select'],''));
$import_delete_existing_data = varset($_POST['import_delete_existing_data'],0);
$current_csv = varset($_POST['csv_format'],'default');
$csv_pw_not_encrypted = varset($_POST['csv_pw_not_encrypted'],0);
$csv_data_file = varset($_POST['csv_data_file'],'import.csv');
$current_db_type = varset($_POST['db_import_type'],key($import_class_names));
$db_blocks_to_import = array();
foreach ($db_import_blocks as $k => $v)
{
if (isset($_POST['import_block_'.$k]))
{
$db_blocks_to_import[$k] = 1;
}
}
require_once(e_ADMIN."auth.php");
if (!is_object($e_userclass))
{
require_once(e_HANDLER."userclass_class.php"); // Modified class handler
$e_userclass = new user_class;
}
define('CSV_DEF_FILE','csv_import.txt'); // Supplementary CSV format definitions
// Definitions of available CSV-based imports
$csv_formats = array('default' => 'user_name,user_password');
$csv_names = array('default' => LAN_CONVERT_12);
$csv_options = array('default' => 'simple');
$csv_option_settings = array(
'simple' => array('separator' => ',', 'envelope' => ''),
'simple_sq' => array('separator' => ',', 'envelope' => "'"),
'simple_dq' => array('separator' => ',', 'envelope' => '"'),
'simple_semi' => array('separator' => ',', 'envelope' => ';'),
'simple_bar' => array('separator' => ',', 'envelope' => '|')
);
// See what CSV format definitions are available
if (is_readable(CSV_DEF_FILE))
{
$csv_temp = file(CSV_DEF_FILE);
foreach ($csv_temp as $line)
{
$line = trim(str_replace("\n","",$line));
if ($line)
{
list($temp,$name,$options,$line) = explode(',',$line,4);
$temp = trim($temp);
$name = trim($name);
$options = trim($options);
$line = trim($line);
if ($temp && $name && $options && $line)
{
$csv_formats[$temp] = $line; // Add any new definitions
$csv_names[$temp] = $name;
$csv_options[$temp] = $options;
}
}
}
unset($csv_temp);
}
$msg = '';
//======================================================
// Executive routine - actually do conversion
//======================================================
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];
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 ($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 (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))
{
$converter = new $current_db_type;
}
else
{
$msg = LAN_CONVERT_42;
}
}
if (!$msg)
{
$result = $converter->db_Connect($_POST['dbParamHost'],
$_POST['dbParamUsername'],
$_POST['dbParamPassword'],
$_POST['dbParamDatabase'],
varset($_POST['dbParamPrefix'],varset($import_default_prefix[$current_db_type],'')));
if ($result !== TRUE)
{
$msg = LAN_CONVERT_43.": ".$result;
}
}
if (!$msg)
{
foreach ($db_import_blocks as $k => $v)
{
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'];
}
if (!$msg && (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;
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)
{
$errorCounter++;
$line_error = $exporter->getErrorText($result);
if ($msg) $msg .= "<br />";
$msg .= str_replace(array('--ERRNUM--','--DB--'),array($line_error,$k),LAN_CONVERT_46).$loopCounter;
}
}
$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);
}
}
}
}
// $msg = LAN_CONVERT_29;
$abandon = FALSE;
break;
}
if ($msg)
{
$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;
}
}
//======================================================
// Display front page
//======================================================
$text = "
<form method='post' action='".e_SELF."'>
<table style='width: 98%;' class='fborder'>
<tr>
<td class='forumheader3' colspan = '2' style='text-align: center; margin-left: auto; margin-right: auto;'>".LAN_CONVERT_02."
<br /><br /><b>".LAN_CONVERT_05."</b>
<br /><br /></td></tr>\n
<tr>
<td class='forumheader3'>".LAN_CONVERT_06."</td>\n
<td class='forumheader3'><select name='import_source' class='tbox' onchange='disp(this.value)'>\n
<option value='csv'".(($import_source == 'csv') ? " selected='selected'" : '').">".LAN_CONVERT_13."</option>
<option value='db'".(($import_source == 'db') ? " selected='selected'" : '').">".LAN_CONVERT_08."</option>
</select>
</td>
</tr>
<tr>
<td class='forumheader3'>".LAN_CONVERT_11."
</td>
<td class='forumheader3'>
<div id='import_csv'".(($import_source != 'csv') ? " style='display:none'" : '').">
<table style='width: 95%;' class='fborder'>
<colgroup>
<col style='width: 40%; text-align: right;' />
<col style='width: 60%; text-align: left;' />
</colgroup>
<tr>
<td>".LAN_CONVERT_07."</td>
<td><select name='csv_format' class='tbox'>\n";
foreach ($csv_names as $k => $v)
{
$s = ($current_csv == $k) ? " selected='selected'" : '';
$text .= "<option value='{$k}'{$s}>{$v}</option>\n";
}
$text .= "</select>\n
</td>
</tr>
<tr>
<td>".LAN_CONVERT_36."</td>
<td><input class='tbox' type='text' name='csv_data_file' size='30' value='{$csv_data_file}' maxlength='100' /></td>
</tr>
<tr><td>".LAN_CONVERT_17."
</td>
<td><input type='checkbox' name='csv_pw_not_encrypted' value='1'".($csv_pw_not_encrypted ? " checked='checked'" : '')."/>
<span class='smallblacktext'>".LAN_CONVERT_18."</span></td>
</tr>
</table>
</div>
<div id='import_db'".(($import_source != 'db') ? " style='display:none'" : '').">
<table style='width: 95%;' class='fborder'>
<colgroup>
<col style='width: 40%; text-align: right;' />
<col style='width: 60%; text-align: left;'/>
</colgroup>
<tr><td colspan='2' style='text-align:center' class='fcaption'>".LAN_CONVERT_08."</td></tr>
<tr><td>".LAN_CONVERT_14."</td>
<td>";
if (count($import_class_names) == 0)
{
$text .= LAN_CONVERT_15;
}
else
{
$text .= "<select name='db_import_type' class='tbox' onchange='flagbits(this.value)'>\n";
foreach ($import_class_names as $k => $v)
{
$s = ($current_db_type == $k) ? " selected='selected'" : '';
$text .= "<option value='{$k}'{$s}>{$v}</option>\n";
}
$text .= "</select>\n
<div id='db_comment_block'>&nbsp;Comment</div>";
}
$text .= "</td></tr>
<tr>
<td>".LAN_CONVERT_19."</td>
<td><input class='tbox' type='text' name='dbParamHost' size='30' value='localhost' maxlength='100' /></td>
</tr>
<tr>
<td >".LAN_CONVERT_20."</td>
<td ><input class='tbox' type='text' name='dbParamUsername' size='30' value='' maxlength='100' /></td>
</tr>
<tr>
<td >".LAN_CONVERT_21."</td>
<td ><input class='tbox' type='text' name='dbParamPassword' size='30' value='' maxlength='100' /></td>
</tr>
<tr>
<td >".LAN_CONVERT_22."</td>
<td ><input class='tbox' type='text' name='dbParamDatabase' size='30' value='' maxlength='100' /></td>
</tr>
<tr>
<td >".LAN_CONVERT_23."</td>
<td ><input class='tbox' type='text' name='dbParamPrefix' size='30' value='' maxlength='100' /></td>
</tr>
<tr>
<td >".LAN_CONVERT_24."</td>
<td >";
$padder = '';
foreach ($db_import_blocks as $k => $v)
{
$text .= $padder;
$text .= "<input type='checkbox' name='import_block_{$k}' id='import_block_{$k}' value='1'".($db_blocks_to_import[$k] ? " checked='checked'" : '')."/>&nbsp;".$v['message'];
$padder = "<br />";
}
$text .= "</td>
</tr>
</table>
</div>
</td></tr>
<tr><td class='forumheader3'>".LAN_CONVERT_38."
</td>
<td class='forumheader3'><input type='checkbox' name='import_delete_existing_data' value='1'".($import_delete_existing_data ? " checked='checked'" : '')."/>
<span class='smallblacktext'>".LAN_CONVERT_39."</span></td>
</tr>
<tr><td class='forumheader3'>".LAN_CONVERT_16."</td>
<td class='forumheader3'>";
$text .= $e_userclass->vetted_tree('classes_select',array($e_userclass,'checkbox'), $checked_class_list,'main,admin,classes,matchclass');
$text .= "</td></tr>
<tr><td class='forumheader3' style='text-align:center' colspan='2'>
<input class='button' type='submit' name='do_conversion' value='".LAN_CONTINUE."' />
</td>
</tr>
</table></form>";
// Now a little bit of JS to initialise some of the display divs etc
$temp = '';
if ($import_source) $temp .= "disp('{$import_source}');";
if ($current_db_type) $temp .= " flagbits('{$current_db_type}');";
if ($temp) $text .= "<script type=\"text/javascript\"> {$temp}</script>";
$ns -> tablerender(LAN_CONVERT_01, $text);
require_once(e_ADMIN."footer.php");
exit;
function csv_split(&$data,$delim=',',$enveloper='')
{
$ret_array = array();
$fldval='';
$enclosed = false;
// $fldcount=0;
// $linecount=0;
for($i=0;$i<strlen($data);$i++)
{
$c=$data[$i];
switch($c)
{
case $enveloper :
if($enclosed && ($i<strlen($data)) && ($data[$i+1]==$enveloper))
{
$fldval .= $c;
$i++; //skip next char
}
else
{
$enclosed = !$enclosed;
}
break;
case $delim :
if(!$enclosed)
{
$ret_array[]= $fldval;
$fldval='';
}
else
{
$fldval.=$c;
}
break;
case "\r":
case "\n":
$fldval .= $c; // We may want to strip these
break;
default:
$fldval .= $c;
}
}
if($fldval)
$ret_array[] = $fldval;
return $ret_array;
}
function headerjs()
{
// global $import_class_names; // Keys are the various db options
global $import_class_support;
global $db_import_blocks;
global $import_class_comment;
$vals = "var db_names = new Array();\n";
$texts = "var db_options = new Array();\n";
$blocks = "var block_names = new Array();\n";
$comments = "var comment_text = new Array();\n";
$i = 0;
foreach ($db_import_blocks as $it => $val)
{
$blocks .= "block_names[{$i}]='{$it}';\n";
$i++;
}
$i = 0;
foreach ($import_class_support as $k => $v)
{
$vals .= "db_names[$i] = '{$k}';\n";
$comments .= "comment_text[$i] = '{$import_class_comment[$k]}';\n";
// $temp = $import_class_support[$k]; // Array of import types supported
$j = 0;
$m = 1; // Mask bit
foreach ($db_import_blocks as $it => $val)
{
if (in_array($it,$v)) $j = $j + $m;
$m = $m + $m;
}
$texts .= "db_options[{$i}] = {$j};\n";
$i++;
}
$text = "
<script type='text/javascript'>{$vals}{$texts}{$blocks}{$comments}
function disp(type)
{
if(type == 'csv')
{
document.getElementById('import_csv').style.display = '';
document.getElementById('import_db').style.display = 'none';
return;
}
if(type =='db')
{
document.getElementById('import_csv').style.display = 'none';
document.getElementById('import_db').style.display = '';
return;
}
}
function flagbits(type)
{
var i,j;
for (i = 0; i < ".count($import_class_support)."; i++)
{
if (type == db_names[i])
{
var mask = 1;
for (j = 0; j < ".count($db_import_blocks)."; j++)
{
var checkbox = document.getElementById('import_block_'+block_names[j]);
if (checkbox != null)
{
if (db_options[i] & mask)
{
checkbox.checked = 'checked';
checkbox.disabled = '';
}
else
{
checkbox.checked = '';
checkbox.disabled = 'disabled';
}
}
else
{
alert('Could not find: '+'import_block_'+block_names[j]);
}
mask = mask + mask;
}
var checkbox = document.getElementById('db_comment_block');
if (checkbox != null) checkbox.innerHTML = comment_text[i];
return;
}
}
alert('Type not found: '+type);
}
</script>";
return $text;
}
?>

View File

@ -1,212 +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_files/import/import_user_class.php,v $
* $Revision: 1.3 $
* $Date: 2009-11-18 01:04:43 $
* $Author: e107coders $
*/
/*
Class intended to simplify importing of user information from outside.
It ensures that each user record has appropriate defaults
To use:
1. Create one instance of the class
2. Call emptyUserDB() to delete existing users
3. If necessary, call overrideDefault() as necessary to modify the defaults
4. For each record:
a) Call getDefaults() to get a record with all the defaults filled in
b) Update the record from the source database
c) Call saveUser($userRecord) to write the record to the DB
*/
class user_import
{
var $userDB = NULL;
var $blockMainAdmin = TRUE;
// 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_forums' => 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');
// Fields which must be set up by the caller.
var $userMandatory = array(
'user_name', 'user_loginname', 'user_password'
);
// Predefined fields which may appear in the extended user fields
var $userExtended = array(
'user_language',
'user_country',
'user_location',
'user_aim',
'user_icq',
'user_yahoo',
'user_msn',
'user_homepage',
'user_birthday',
'user_timezone'
);
// Array is set up with those predefined extended fields which are actually in use
var $actualExtended = array();
// Constructor
function user_import()
{
$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)
{
$this->blockMainAdmin = FALSE;
}
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;
}
// 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)
{
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 (!isset($this->userDefaults[$k])
&& !in_array($k,$this->userSpecial)
&& !in_array($k,$this->userMandatory))
{
echo "Failed on {$k} => {$v}<br />";
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)) 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])) 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;
$result = $this->userDB->db_Insert('user',$userRecord);
if ($result === FALSE) return 4;
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)
{
$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;
}
}
?>