Update of /cvsroot/php-blog/serendipity/include/admin/importers
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8053/include/admin/importers
Added Files:
geeklog.inc.php sunlog.inc.php
Log Message:
sunlog and geeklog importers. I'm spent. :-D
--- NEW FILE: geeklog.inc.php ---
<?php # $Id: geeklog.inc.php,v 1.1 2005/02/14 16:55:41 garvinhicking Exp $
# Copyright (c) 2003-2005, Jannis Hermanns (on behalf the Serendipity Developer Team)
# All rights reserved. See LICENSE file for licensing details
/*****************************************************************
* geeklog Importer, by Garvin Hicking *
* ****************************************************************/
class Serendipity_Import_geeklog extends Serendipity_Import {
var $info = array('software' => 'Geeklog 1.3.11');
var $data = array();
var $inputFields = array();
var $categories = array();
var $trans_table = '';
function getImportNotes() {
return 'GeekLog has a granular control over access privileges which cannot be migrated to Serendipity. All Users will be migrated as Superusers, you may need to set them to editor or chief users manually after import.';
}
function Serendipity_Import_geeklog($data) {
$this->data = $data;
$this->inputFields = array(array('text' => INSTALL_DBHOST,
'type' => 'input',
'name' => 'host'),
array('text' => INSTALL_DBUSER,
'type' => 'input',
'name' => 'user'),
array('text' => INSTALL_DBPASS,
'type' => 'protected',
'name' => 'pass'),
array('text' => INSTALL_DBNAME,
'type' => 'input',
'name' => 'name'),
array('text' => INSTALL_DBPREFIX,
'type' => 'input',
'name' => 'prefix',
'default' => 'gl_'),
array('text' => ACTIVATE_AUTODISCOVERY,
'type' => 'bool',
'name' => 'autodiscovery',
'default' => 'false')
);
}
function validateData() {
return sizeof($this->data);
}
function getInputFields() {
return $this->inputFields;
}
function strtrRecursive($data, $trans_table) {
foreach ($data as $key => $val) {
if (is_array($val)) {
$data[$key] = $this->strtrRecursive($val);
}
else {
$data[$key] = strtr($val, $trans_table);
}
}
return $data;
}
function import() {
global $serendipity;
// Save this so we can return it to its original value at the end of this method.
$noautodiscovery = isset($serendipity['noautodiscovery']) ? $serendipity['noautodiscovery'] : false;
if ($this->data['autodiscovery'] == 'false') {
$serendipity['noautodiscovery'] = 1;
}
// We need to convert interesting characters to HTML entities, except for those with special relevance to HTML.
$this->trans_table = get_html_translation_table(HTML_ENTITIES);
foreach (get_html_translation_table(HTML_SPECIALCHARS) as $char => $encoded)
if (isset($this->trans_table[$char]))
unset($this->trans_table[$char]);
$this->data['prefix'] = serendipity_db_escape_string($this->data['prefix']);
$users = array();
$entries = array();
if (!extension_loaded('mysql')) {
return MYSQL_REQUIRED;
}
$gdb = @mysql_connect($this->data['host'], $this->data['user'], $this->data['pass']);
if (!$gdb) {
return sprintf(COULDNT_CONNECT, $this->data['host']);
}
if (!@mysql_select_db($this->data['name'])) {
return sprintf(COULDNT_SELECT_DB, mysql_error($gdb));
}
/* Users */
$res = @mysql_query("SELECT uid AS ID,
username AS user_login,
passwd AS user_pass,
email AS user_email,
homepage AS user_url
FROM {$this->data['prefix']}users", $gdb);
if (!$res) {
return sprintf(COULDNT_SELECT_USER_INFO, mysql_error($gdb));
}
for ($x=0, $max_x = mysql_num_rows($res); $x < $max_x ; $x++ ) {
$users[$x] = mysql_fetch_assoc($res);
$data = array('right_publish' => 1,
'username' => $users[$x]['user_login'],
'email' => $users[$x]['user_email'],
'userlevel' => USERLEVEL_ADMIN,
'password' => $users[$x]['user_pass']); // MD5 compatible
serendipity_db_insert('authors', $this->strtrRecursive($data, $this->trans_table));
echo mysql_error();
$users[$x]['authorid'] = serendipity_db_insert_id('authors', 'authorid');
}
/* Categories */
$res = @mysql_query("SELECT tid AS cat_ID, topic AS cat_name, topic AS category_description FROM {$this->data['prefix']}topics ORDER BY tid;", $gdb);
if (!$res) {
return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysql_error($gdb));
}
// Get all the info we need
for ($x=0, $max_x = mysql_num_rows($res) ; $x < $max_x ; $x++) {
$categories[] = mysql_fetch_assoc($res);
}
// Insert all categories as top level (we need to know everyone's ID before we can represent the hierarchy).
for ($x=0, $max_x = sizeof($categories) ; $x < $max_x ; $x++ ) {
$cat = array('category_name' => $categories[$x]['cat_name'],
'category_description' => $categories[$x]['category_description'],
'parentid' => 0, // <---
'category_left' => 0,
'category_right' => 0);
serendipity_db_insert('category', $this->strtrRecursive($cat, $this->trans_table));
$categories[$x]['categoryid'] = serendipity_db_insert_id('category', 'categoryid');
}
serendipity_rebuildCategoryTree();
/* Entries */
$res = @mysql_query("SELECT * FROM {$this->data['prefix']}stories ORDER BY sid;", $gdb);
if (!$res) {
return sprintf(COULDNT_SELECT_ENTRY_INFO, mysql_error($gdb));
}
for ($x=0, $max_x = mysql_num_rows($res) ; $x < $max_x ; $x++ ) {
$entries[$x] = mysql_fetch_assoc($res);
$entry = array('title' => $entries[$x]['title'],
'isdraft' => ($entries[$x]['draft_flag'] == '0') ? 'false' : 'true',
'allow_comments' => ($entries[$x]['comments'] == '1' ) ? 'true' : 'false',
'timestamp' => strtotime($entries[$x]['date']),
'body' => strtr($entries[$x]['introtext'], $this->trans_table),
'extended' => strtr($entries[$x]['bodytext'], $this->trans_table),
);
$entry['authorid'] = '';
$entry['author'] = '';
foreach ($users as $user) {
if ($user['ID'] == $entries[$x]['uid']) {
$entry['authorid'] = $user['authorid'];
$entry['author'] = $user['user_login'];
break;
}
}
if (!is_int($entries[$x]['entryid'] = serendipity_updertEntry($entry))) {
return $entries[$x]['entryid'];
}
/* Entry/category */
foreach ($categories as $category) {
if ($category['cat_ID'] == $entries[$x]['tid'] ) {
$data = array('entryid' => $entries[$x]['entryid'],
'categoryid' => $category['categoryid']);
serendipity_db_insert('entrycat', $this->strtrRecursive($data, $this->trans_table));
break;
}
}
}
/* Comments */
$res = @mysql_query("SELECT * FROM {$this->data['prefix']}comments;", $gdb);
if (!$res) {
return sprintf(COULDNT_SELECT_COMMENT_INFO, mysql_error($gdb));
}
while ($a = mysql_fetch_assoc($res)) {
foreach ($entries as $entry) {
if ($entry['sid'] == $a['sid'] ) {
$username = '';
$mail = '';
$url = '';
foreach($users AS $user) {
if ($user['ID'] == $a['uid']) {
$username = $user['user_login'];
$mail = $user['user_email'];
$url = $user['user_url'];
break;
}
}
$comment = array('entry_id ' => $entry['entryid'],
'parent_id' => 0,
'timestamp' => strtotime($a['date']),
'author' => $username,
'email' => $mail,
'url' => $url,
'ip' => $a['ip'],
'status' => 'approved',
'body' => $a['comment'],
'type' => 'NORMAL');
serendipity_db_insert('comments', $this->strtrRecursive($comment, $this->trans_table));
$cid = serendipity_db_insert_id('comments', 'id');
serendipity_approveComment($cid, $entry['entryid'], true);
}
}
}
$serendipity['noautodiscovery'] = $noautodiscovery;
// That was fun.
return true;
}
}
return 'Serendipity_Import_geeklog';
/* vim: set sts=4 ts=4 expandtab : */
?>
--- NEW FILE: sunlog.inc.php ---
<?php # $Id: sunlog.inc.php,v 1.1 2005/02/14 16:55:41 garvinhicking Exp $
# Copyright (c) 2003-2005, Jannis Hermanns (on behalf the Serendipity Developer Team)
# All rights reserved. See LICENSE file for licensing details
/*****************************************************************
* sunlog Importer, by Garvin Hicking *
* ****************************************************************/
class Serendipity_Import_sunlog extends Serendipity_Import {
var $info = array('software' => 'Sunlog 0.4.4');
var $data = array();
var $inputFields = array();
var $categories = array();
var $trans_table = '';
function getImportNotes() {
return 'Sunlog uses a crypted string to represent stored passwords. Thus, those passwords are incompatible with the MD5 hashing of Serendipity and can not be reconstructed. The passwords for all users have been set to "sunlog". <strong>You need to modify the passwords manually for each user</strong>, we are sorry for that inconvenience.<br />'
. '<br />'
. 'Sunlog has a granular control over access privileges which cannot be migrated to Serendipity. All Users will be migrated as Superusers, you may need to set them to editor or chief users manually after import.';
}
function Serendipity_Import_sunlog($data) {
$this->data = $data;
$this->inputFields = array(array('text' => INSTALL_DBHOST,
'type' => 'input',
'name' => 'host'),
array('text' => INSTALL_DBUSER,
'type' => 'input',
'name' => 'user'),
array('text' => INSTALL_DBPASS,
'type' => 'protected',
'name' => 'pass'),
array('text' => INSTALL_DBNAME,
'type' => 'input',
'name' => 'name'),
array('text' => INSTALL_DBPREFIX,
'type' => 'input',
'name' => 'prefix',
'default' => 'sunlog_'),
array('text' => ACTIVATE_AUTODISCOVERY,
'type' => 'bool',
'name' => 'autodiscovery',
'default' => 'false')
);
}
function validateData() {
return sizeof($this->data);
}
function getInputFields() {
return $this->inputFields;
}
function strtrRecursive($data, $trans_table) {
foreach ($data as $key => $val) {
if (is_array($val)) {
$data[$key] = $this->strtrRecursive($val);
}
else {
$data[$key] = strtr($val, $trans_table);
}
}
return $data;
}
function import() {
global $serendipity;
// Save this so we can return it to its original value at the end of this method.
$noautodiscovery = isset($serendipity['noautodiscovery']) ? $serendipity['noautodiscovery'] : false;
if ($this->data['autodiscovery'] == 'false') {
$serendipity['noautodiscovery'] = 1;
}
// We need to convert interesting characters to HTML entities, except for those with special relevance to HTML.
$this->trans_table = get_html_translation_table(HTML_ENTITIES);
foreach (get_html_translation_table(HTML_SPECIALCHARS) as $char => $encoded)
if (isset($this->trans_table[$char]))
unset($this->trans_table[$char]);
$this->data['prefix'] = serendipity_db_escape_string($this->data['prefix']);
$users = array();
$entries = array();
if (!extension_loaded('mysql')) {
return MYSQL_REQUIRED;
}
$sunlogdb = @mysql_connect($this->data['host'], $this->data['user'], $this->data['pass']);
if (!$sunlogdb) {
return sprintf(COULDNT_CONNECT, $this->data['host']);
}
if (!@mysql_select_db($this->data['name'])) {
return sprintf(COULDNT_SELECT_DB, mysql_error($sunlogdb));
}
/* Users */
$res = @mysql_query("SELECT id AS ID,
name AS user_login,
email AS user_email,
homepage AS user_url
FROM {$this->data['prefix']}users", $sunlogdb);
if (!$res) {
return sprintf(COULDNT_SELECT_USER_INFO, mysql_error($sunlogdb));
}
for ($x=0, $max_x = mysql_num_rows($res); $x < $max_x ; $x++ ) {
$users[$x] = mysql_fetch_assoc($res);
$data = array('right_publish' => 1,
'username' => $users[$x]['user_login'],
'email' => $users[$x]['user_email'],
'userlevel' => USERLEVEL_ADMIN,
'password' => md5('sunlog'));
serendipity_db_insert('authors', $this->strtrRecursive($data, $this->trans_table));
echo mysql_error();
$users[$x]['authorid'] = serendipity_db_insert_id('authors', 'authorid');
}
/* Categories */
if (!$this->importCategories(null)) {
return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysql_error($sunlogdb));
}
serendipity_rebuildCategoryTree();
/* Entries */
$res = @mysql_query("SELECT * FROM {$this->data['prefix']}articles ORDER BY id;", $sunlogdb);
if (!$res) {
return sprintf(COULDNT_SELECT_ENTRY_INFO, mysql_error($sunlogdb));
}
for ($x=0, $max_x = mysql_num_rows($res) ; $x < $max_x ; $x++ ) {
$entries[$x] = mysql_fetch_assoc($res);
$entry = array('title' => $entries[$x]['title'],
'isdraft' => ($entries[$x]['draft'] == '0') ? 'false' : 'true',
'allow_comments' => ($entries[$x]['c_comments'] == '1' ) ? 'true' : 'false',
'timestamp' => strtotime($entries[$x]['timestamp']),
'body' => strtr($entries[$x]['lead_converted'], $this->trans_table),
'extended' => strtr($entries[$x]['article_converted'], $this->trans_table),
);
$entry['authorid'] = '';
$entry['author'] = '';
foreach ($users as $user) {
if ($user['ID'] == $entries[$x]['author']) {
$entry['authorid'] = $user['authorid'];
$entry['author'] = $user['user_login'];
break;
}
}
if (!is_int($entries[$x]['entryid'] = serendipity_updertEntry($entry))) {
return $entries[$x]['entryid'];
}
}
/* Even more category stuff */
$res = @mysql_query("SELECT * FROM {$this->data['prefix']}transfer_c;", $sunlogdb);
if (!$res) {
return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysql_error($sunlogdb));
}
for ($x=0, $max_x = mysql_num_rows($res) ; $x < $max_x ; $x++ ) {
$entrycat = mysql_fetch_assoc($res);
$entryid = 0;
$categoryid = 0;
foreach($entries AS $entry) {
if ($entry['id'] == $entrycat['article']) {
$entryid = $entry['entryid'];
break;
}
}
foreach($this->categories AS $category) {
if ($category['id'] == $entrycat['category']) {
$categoryid = $category['categoryid'];
}
}
if ($entryid > 0 && $categoryid > 0) {
$data = array('entryid' => $entryid,
'categoryid' => $categoryid);
serendipity_db_insert('entrycat', $this->strtrRecursive($data, $this->trans_table));
}
}
/* Comments */
$res = @mysql_query("SELECT * FROM {$this->data['prefix']}c_comments;", $sunlogdb);
if (!$res) {
return sprintf(COULDNT_SELECT_COMMENT_INFO, mysql_error($sunlogdb));
}
while ($a = mysql_fetch_assoc($res)) {
foreach ($entries as $entry) {
if ($entry['id'] == $a['for_entry'] ) {
$username = '';
$mail = '';
$url = '';
foreach($users AS $user) {
if ($user['ID'] == $a['user']) {
$username = $user['user_login'];
$mail = $user['user_email'];
$url = $user['user_url'];
break;
}
}
$comment = array('entry_id ' => $entry['entryid'],
'parent_id' => 0,
'timestamp' => strtotime($a['insertdate']),
'author' => $username,
'email' => $mail,
'url' => $url,
'ip' => '',
'status' => 'approved',
'body' => $a['comment'],
'type' => 'NORMAL');
serendipity_db_insert('comments', $this->strtrRecursive($comment, $this->trans_table));
$cid = serendipity_db_insert_id('comments', 'id');
serendipity_approveComment($cid, $entry['entryid'], true);
}
}
}
$serendipity['noautodiscovery'] = $noautodiscovery;
// That was fun.
return true;
}
function importCategories($parentid = 0, $new_parentid = 0) {
$where = "WHERE parent = '" . mysql_escape_string($parentid) . "'";
$res = mysql_query("SELECT * FROM {$this->data['prefix']}categories
" . $where);
if (!$res) {
echo mysql_error();
return false;
}
// Get all the info we need
for ($x=0, $max_x = mysql_num_rows($res) ; $x < $max_x ; $x++) {
$row = mysql_fetch_assoc($res);
$cat = array('category_name' => $row['title'],
'category_description' => $row['optional_1'] . ' ' . $row['optional_2'] . ' ' . $row['optional_3'],
'parentid' => (int)$new_parentid,
'category_left' => 0,
'category_right' => 0);
serendipity_db_insert('category', $this->strtrRecursive($cat, $this->trans_table));
$row['categoryid'] = serendipity_db_insert_id('category', 'categoryid');
$this->categories[] = $row;
$this->importCategories($row['id'], $row['categoryid']);
}
return true;
}
}
return 'Serendipity_Import_sunlog';
/* vim: set sts=4 ts=4 expandtab : */
?>
|