Better checks to see if the local PEAR inclusion is required
This commit is contained in:
14
docs/NEWS
14
docs/NEWS
@ -3,6 +3,12 @@
|
|||||||
Version 1.2 ()
|
Version 1.2 ()
|
||||||
------------------------------------------------------------------------
|
------------------------------------------------------------------------
|
||||||
|
|
||||||
|
* Improve memory usage of WordPress importer, add debug output
|
||||||
|
(garvinhicking)
|
||||||
|
|
||||||
|
* EXPERIMENTAL: Modify session language fetch function to allow
|
||||||
|
earlier plugin API calls (Rob Richards)
|
||||||
|
|
||||||
* No longer accept trackbacks to draft entries.Thanks to j_b_poquelin
|
* No longer accept trackbacks to draft entries.Thanks to j_b_poquelin
|
||||||
(garvinhicking)
|
(garvinhicking)
|
||||||
|
|
||||||
@ -64,7 +70,13 @@ Version 1.2 ()
|
|||||||
* Allow to call permalinks that end with a "/" the same as if not
|
* Allow to call permalinks that end with a "/" the same as if not
|
||||||
ending with a "/" (garvinhicking)
|
ending with a "/" (garvinhicking)
|
||||||
|
|
||||||
Version 1.1.1 ()
|
Version 1.1.2 ()
|
||||||
|
-----------------------------------------------------------------------
|
||||||
|
|
||||||
|
* Better checks to see if the local PEAR inclusion is required
|
||||||
|
(garvinhicking)
|
||||||
|
|
||||||
|
Version 1.1.1 (February 22nd, 2007)
|
||||||
------------------------------------------------------------------------
|
------------------------------------------------------------------------
|
||||||
|
|
||||||
* Patch plugin permissionship management to properly indicate
|
* Patch plugin permissionship management to properly indicate
|
||||||
|
@ -68,6 +68,7 @@ class Serendipity_Import_WordPress extends Serendipity_Import {
|
|||||||
|
|
||||||
function import() {
|
function import() {
|
||||||
global $serendipity;
|
global $serendipity;
|
||||||
|
static $debug = true;
|
||||||
|
|
||||||
// Save this so we can return it to its original value at the end of this method.
|
// Save this so we can return it to its original value at the end of this method.
|
||||||
$noautodiscovery = isset($serendipity['noautodiscovery']) ? $serendipity['noautodiscovery'] : false;
|
$noautodiscovery = isset($serendipity['noautodiscovery']) ? $serendipity['noautodiscovery'] : false;
|
||||||
@ -84,90 +85,121 @@ class Serendipity_Import_WordPress extends Serendipity_Import {
|
|||||||
$entries = array();
|
$entries = array();
|
||||||
|
|
||||||
if ( !extension_loaded('mysql') ) {
|
if ( !extension_loaded('mysql') ) {
|
||||||
return MYSQL_REQUIRED;;
|
return MYSQL_REQUIRED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (function_exists('set_time_limit')) {
|
||||||
|
@set_time_limit(300);
|
||||||
}
|
}
|
||||||
|
|
||||||
$wpdb = @mysql_connect($this->data['host'], $this->data['user'], $this->data['pass']);
|
$wpdb = @mysql_connect($this->data['host'], $this->data['user'], $this->data['pass']);
|
||||||
if ( !$wpdb ) {
|
if (!$wpdb) {
|
||||||
return sprintf(COULDNT_CONNECT, $this->data['host']);
|
return sprintf(COULDNT_CONNECT, $this->data['host']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !@mysql_select_db($this->data['name']) ) {
|
if (!@mysql_select_db($this->data['name'])) {
|
||||||
return sprintf(COULDNT_SELECT_DB, mysql_error($wpdb));
|
return sprintf(COULDNT_SELECT_DB, mysql_error($wpdb));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This will hold the s9y <-> WP ID associations.
|
||||||
|
$assoc = array();
|
||||||
|
|
||||||
/* Users */
|
/* Users */
|
||||||
// Fields: ID, user_login, user_pass, user_email, user_level
|
// Fields: ID, user_login, user_pass, user_email, user_level
|
||||||
$res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}users;", $wpdb);
|
$res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}users;", $wpdb);
|
||||||
if ( !$res ) {
|
if (!$res) {
|
||||||
return sprintf(COULDNT_SELECT_USER_INFO, mysql_error($wpdb));
|
printf(COULDNT_SELECT_USER_INFO, mysql_error($wpdb));
|
||||||
}
|
} else {
|
||||||
|
if ($debug) echo "Importing users...<br />\n";
|
||||||
for ( $x=0 ; $x<mysql_num_rows($res) ; $x++ ) {
|
for ($x=0, $c = mysql_num_rows($res) ; $x < $c ; $x++) {
|
||||||
$users[$x] = mysql_fetch_assoc($res);
|
$users[$x] = mysql_fetch_assoc($res);
|
||||||
|
|
||||||
$data = array('right_publish' => (!isset($users[$x]['user_level']) || $users[$x]['user_level'] >= 1) ? 1 : 0,
|
$data = array('right_publish' => (!isset($users[$x]['user_level']) || $users[$x]['user_level'] >= 1) ? 1 : 0,
|
||||||
'realname' => $users[$x]['user_login'],
|
'realname' => $users[$x]['user_login'],
|
||||||
'username' => $users[$x]['user_login'],
|
'username' => $users[$x]['user_login'],
|
||||||
'password' => $users[$x]['user_pass']); // WP uses md5, too.
|
'password' => $users[$x]['user_pass']); // WP uses md5, too.
|
||||||
|
|
||||||
if ( isset($users[$x]['user_level']) && $users[$x]['user_level'] <= 1 ) {
|
if (isset($users[$x]['user_level']) && $users[$x]['user_level'] <= 1) {
|
||||||
$data['userlevel'] = USERLEVEL_EDITOR;
|
$data['userlevel'] = USERLEVEL_EDITOR;
|
||||||
} elseif ( isset($users[$x]['user_level']) && $users[$x]['user_level'] < 5 ) {
|
} elseif (isset($users[$x]['user_level']) && $users[$x]['user_level'] < 5) {
|
||||||
$data['userlevel'] = USERLEVEL_CHIEF;
|
$data['userlevel'] = USERLEVEL_CHIEF;
|
||||||
} else {
|
} else {
|
||||||
$data['userlevel'] = USERLEVEL_ADMIN;
|
$data['userlevel'] = USERLEVEL_ADMIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($serendipity['serendipityUserlevel'] < $data['userlevel']) {
|
||||||
|
$data['userlevel'] = $serendipity['serendipityUserlevel'];
|
||||||
|
}
|
||||||
|
|
||||||
|
serendipity_db_insert('authors', $this->strtrRecursive($data));
|
||||||
|
$users[$x]['authorid'] = serendipity_db_insert_id('authors', 'authorid');
|
||||||
|
|
||||||
|
// Set association.
|
||||||
|
$assoc['users'][$users[$x]['ID']] = $users[$x]['authorid'];
|
||||||
}
|
}
|
||||||
|
if ($debug) echo "Imported users.<br />\n";
|
||||||
if ($serendipity['serendipityUserlevel'] < $data['userlevel']) {
|
|
||||||
$data['userlevel'] = $serendipity['serendipityUserlevel'];
|
// Clean memory
|
||||||
}
|
unset($users);
|
||||||
|
|
||||||
serendipity_db_insert('authors', $this->strtrRecursive($data));
|
|
||||||
$users[$x]['authorid'] = serendipity_db_insert_id('authors', 'authorid');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Categories */
|
/* Categories */
|
||||||
$res = @$this->nativeQuery("SELECT cat_ID, cat_name, category_description, category_parent FROM {$this->data['prefix']}categories ORDER BY category_parent, cat_ID;", $wpdb);
|
$res = @$this->nativeQuery("SELECT cat_ID, cat_name, category_description, category_parent
|
||||||
if ( !$res ) {
|
FROM {$this->data['prefix']}categories
|
||||||
return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysql_error($wpdb));
|
ORDER BY category_parent, cat_ID;", $wpdb);
|
||||||
}
|
if (!$res) {
|
||||||
|
printf(COULDNT_SELECT_CATEGORY_INFO, mysql_error($wpdb));
|
||||||
|
} else {
|
||||||
|
if ($debug) echo "Importing categories...<br />\n";
|
||||||
|
|
||||||
// Get all the info we need
|
// Get all the info we need
|
||||||
for ( $x=0 ; $x<mysql_num_rows($res) ; $x++ )
|
for ($x=0 ; $x<mysql_num_rows($res) ; $x++) {
|
||||||
$categories[] = mysql_fetch_assoc($res);
|
$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 ; $x<sizeof($categories) ; $x++ ) {
|
// Insert all categories as top level (we need to know everyone's ID before we can represent the hierarchy).
|
||||||
$cat = array('category_name' => $categories[$x]['cat_name'],
|
for ($x=0, $c = sizeof($categories) ; $x < $c ; $x++) {
|
||||||
'category_description' => $categories[$x]['category_description'],
|
$cat = array('category_name' => $categories[$x]['cat_name'],
|
||||||
'parentid' => 0, // <---
|
'category_description' => $categories[$x]['category_description'],
|
||||||
'category_left' => 0,
|
'parentid' => 0,
|
||||||
'category_right' => 0);
|
'category_left' => 0,
|
||||||
|
'category_right' => 0);
|
||||||
serendipity_db_insert('category', $this->strtrRecursive($cat));
|
|
||||||
$categories[$x]['categoryid'] = serendipity_db_insert_id('category', 'categoryid');
|
serendipity_db_insert('category', $this->strtrRecursive($cat));
|
||||||
}
|
$categories[$x]['categoryid'] = serendipity_db_insert_id('category', 'categoryid');
|
||||||
|
|
||||||
// There has to be a more efficient way of doing this...
|
// Set association.
|
||||||
foreach ( $categories as $cat ) {
|
$assoc['categories'][$categories[$x]['cat_ID']] = $categories[$x]['categoryid'];
|
||||||
if ( $cat['category_parent'] != 0 ) {
|
}
|
||||||
// Find the parent
|
|
||||||
$par_id = 0;
|
foreach ($categories as $cat) {
|
||||||
foreach ( $categories as $possible_par ) {
|
if ($cat['category_parent'] != 0) {
|
||||||
if ( $possible_par['cat_ID'] == $cat['category_parent'] ) {
|
// Find the parent
|
||||||
$par_id = $possible_par['categoryid'];
|
$par_id = 0;
|
||||||
break;
|
foreach ($categories as $possible_par) {
|
||||||
|
if ($possible_par['cat_ID'] == $cat['category_parent']) {
|
||||||
|
$par_id = $possible_par['categoryid'];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($par_id != 0) {
|
||||||
|
serendipity_db_query("UPDATE {$serendipity['dbPrefix']}category
|
||||||
|
SET parentid={$par_id}
|
||||||
|
WHERE categoryid={$cat['categoryid']};");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $par_id != 0 ) {
|
|
||||||
serendipity_db_query("UPDATE {$serendipity['dbPrefix']}category SET parentid={$par_id} WHERE categoryid={$cat['categoryid']};");
|
|
||||||
} // else { echo "D'oh! " . random_string_of_profanity(); }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clean memory
|
||||||
|
unset($categories);
|
||||||
|
|
||||||
|
if ($debug) echo "Imported categories.<br />\n";
|
||||||
|
if ($debug) echo "Rebuilding category tree...<br />\n";
|
||||||
|
serendipity_rebuildCategoryTree();
|
||||||
|
if ($debug) echo "Rebuilt category tree.<br />\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
serendipity_rebuildCategoryTree();
|
|
||||||
|
|
||||||
/* Entries */
|
/* Entries */
|
||||||
if (serendipity_db_bool($this->data['import_all'])) {
|
if (serendipity_db_bool($this->data['import_all'])) {
|
||||||
@ -175,86 +207,81 @@ class Serendipity_Import_WordPress extends Serendipity_Import {
|
|||||||
} else {
|
} else {
|
||||||
$res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}posts ORDER BY post_date;", $wpdb);
|
$res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}posts ORDER BY post_date;", $wpdb);
|
||||||
}
|
}
|
||||||
if ( !$res ) {
|
|
||||||
return sprintf(COULDNT_SELECT_ENTRY_INFO, mysql_error($wpdb));
|
|
||||||
}
|
|
||||||
|
|
||||||
for ( $x=0 ; $x<mysql_num_rows($res) ; $x++ ) {
|
if (!$res) {
|
||||||
$entries[$x] = mysql_fetch_assoc($res);
|
printf(COULDNT_SELECT_ENTRY_INFO, mysql_error($wpdb));
|
||||||
|
} else {
|
||||||
$content = explode('<!--more-->', $entries[$x]['post_content'], 2);
|
if ($debug) echo "Importing entries...<br />\n";
|
||||||
$body = $content[0];
|
for ($x=0, $c = mysql_num_rows($res) ; $x < $c ; $x++ ) {
|
||||||
$extended = $content[1];
|
$entries[$x] = mysql_fetch_assoc($res);
|
||||||
|
|
||||||
$entry = array('title' => $this->decode($entries[$x]['post_title']), // htmlentities() is called later, so we can leave this.
|
$content = explode('<!--more-->', $entries[$x]['post_content'], 2);
|
||||||
'isdraft' => ($entries[$x]['post_status'] == 'publish') ? 'false' : 'true',
|
$body = $content[0];
|
||||||
'allow_comments' => ($entries[$x]['comment_status'] == 'open' ) ? 'true' : 'false',
|
$extended = $content[1];
|
||||||
'timestamp' => strtotime($entries[$x]['post_date']),
|
|
||||||
'body' => $this->strtr($body),
|
$entry = array('title' => $this->decode($entries[$x]['post_title']), // htmlentities() is called later, so we can leave this.
|
||||||
'extended' => $this->strtr($extended));
|
'isdraft' => ($entries[$x]['post_status'] == 'publish') ? 'false' : 'true',
|
||||||
|
'allow_comments' => ($entries[$x]['comment_status'] == 'open' ) ? 'true' : 'false',
|
||||||
foreach ( $users as $user ) {
|
'timestamp' => strtotime($entries[$x]['post_date']),
|
||||||
if ( $user['ID'] == $entries[$x]['post_author'] ) {
|
'body' => $this->strtr($body),
|
||||||
$entry['authorid'] = $user['authorid'];
|
'extended' => $this->strtr($extended),
|
||||||
break;
|
'authorid' => $assoc['users'][$entries[$x]['post_author']]);
|
||||||
|
|
||||||
|
if (!is_int($entries[$x]['entryid'] = serendipity_updertEntry($entry))) {
|
||||||
|
printf(COULDNT_SELECT_ENTRY_INFO, mysql_error($wpdb));
|
||||||
|
echo "ID: {$entries[$x]['ID']} - {$entry['title']}<br />\n";
|
||||||
|
return $entries[$x]['entryid'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$assoc['entries'][$entries[$x]['ID']] = $entries[$x]['entryid'];
|
||||||
}
|
}
|
||||||
|
if ($debug) echo "Imported entries...<br />\n";
|
||||||
|
|
||||||
if ( !is_int($entries[$x]['entryid'] = serendipity_updertEntry($entry)) ) {
|
// Clean memory
|
||||||
return $entries[$x]['entryid'];
|
unset($entries);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Entry/category */
|
/* Entry/category */
|
||||||
$res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}post2cat;", $wpdb);
|
$res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}post2cat;", $wpdb);
|
||||||
if ( !$res ) {
|
if (!$res) {
|
||||||
return sprintf(COULDNT_SELECT_ENTRY_INFO, mysql_error($wpdb));
|
printf(COULDNT_SELECT_ENTRY_INFO, mysql_error($wpdb));
|
||||||
}
|
} else {
|
||||||
|
if ($debug) echo "Importing category associations...<br />\n";
|
||||||
while ( $a = mysql_fetch_assoc($res) ) {
|
while ($a = mysql_fetch_assoc($res)) {
|
||||||
foreach ( $categories as $category ) {
|
$data = array('entryid' => $assoc['entries'][$a['post_id']],
|
||||||
if ( $category['cat_ID'] == $a['category_id'] ) {
|
'categoryid' => $assoc['categories'][$a['category_id']]);
|
||||||
foreach ( $entries as $entry ) {
|
serendipity_db_insert('entrycat', $this->strtrRecursive($data));
|
||||||
if ( $a['post_id'] == $entry['ID'] ) {
|
|
||||||
$data = array('entryid' => $entry['entryid'],
|
|
||||||
'categoryid' => $category['categoryid']);
|
|
||||||
serendipity_db_insert('entrycat', $this->strtrRecursive($data));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if ($debug) echo "Imported category associations.<br />\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Comments */
|
/* Comments */
|
||||||
$res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}comments;", $wpdb);
|
$res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}comments;", $wpdb);
|
||||||
if ( !$res ) {
|
if (!$res) {
|
||||||
return sprintf(COULDNT_SELECT_COMMENT_INFO, mysql_error($wpdb));
|
printf(COULDNT_SELECT_COMMENT_INFO, mysql_error($wpdb));
|
||||||
}
|
} else {
|
||||||
|
$serendipity['allowSubscriptions'] = false;
|
||||||
while ( $a = mysql_fetch_assoc($res) ) {
|
if ($debug) echo "Importing comments...<br />\n";
|
||||||
foreach ( $entries as $entry ) {
|
while ($a = mysql_fetch_assoc($res)) {
|
||||||
if ( $entry['ID'] == $a['comment_post_ID'] ) {
|
$comment = array('entry_id ' => $assoc['entries'][$a['comment_post_ID']],
|
||||||
$comment = array('entry_id ' => $entry['entryid'],
|
'parent_id' => 0,
|
||||||
'parent_id' => 0,
|
'timestamp' => strtotime($a['comment_date']),
|
||||||
'timestamp' => strtotime($a['comment_date']),
|
'author' => $a['comment_author'],
|
||||||
'author' => $a['comment_author'],
|
'email' => $a['comment_author_email'],
|
||||||
'email' => $a['comment_author_email'],
|
'url' => $a['comment_author_url'],
|
||||||
'url' => $a['comment_author_url'],
|
'ip' => $a['comment_author_IP'],
|
||||||
'ip' => $a['comment_author_IP'],
|
'status' => (empty($a['comment_approved']) || $a['comment_approved'] == '1') ? 'approved' : 'pending',
|
||||||
'status' => (empty($a['comment_approved']) || $a['comment_approved'] == '1') ? 'approved' : 'pending',
|
'subscribed'=> 'false',
|
||||||
'subscribed'=> 'false',
|
'body' => $a['comment_content'],
|
||||||
'body' => $a['comment_content'],
|
'type' => 'NORMAL');
|
||||||
'type' => 'NORMAL');
|
|
||||||
|
serendipity_db_insert('comments', $this->strtrRecursive($comment));
|
||||||
serendipity_db_insert('comments', $this->strtrRecursive($comment));
|
if ($comment['status'] == 'approved') {
|
||||||
if ($comment['status'] == 'approved') {
|
$cid = serendipity_db_insert_id('comments', 'id');
|
||||||
$cid = serendipity_db_insert_id('comments', 'id');
|
serendipity_approveComment($cid, $comment['entry_id'], true);
|
||||||
serendipity_approveComment($cid, $entry['entryid'], true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ($debug) echo "Imported comments.<br />\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
$serendipity['noautodiscovery'] = $noautodiscovery;
|
$serendipity['noautodiscovery'] = $noautodiscovery;
|
||||||
@ -267,4 +294,3 @@ class Serendipity_Import_WordPress extends Serendipity_Import {
|
|||||||
return 'Serendipity_Import_WordPress';
|
return 'Serendipity_Import_WordPress';
|
||||||
|
|
||||||
/* vim: set sts=4 ts=4 expandtab : */
|
/* vim: set sts=4 ts=4 expandtab : */
|
||||||
?>
|
|
||||||
|
@ -183,7 +183,7 @@ if (function_exists('set_include_path')) {
|
|||||||
$use_include = @ini_set('include_path', $new_include);
|
$use_include = @ini_set('include_path', $new_include);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($use_include) {
|
if ($use_include !== $false && $use_include == $new_include) {
|
||||||
@define('S9Y_PEAR', true);
|
@define('S9Y_PEAR', true);
|
||||||
@define('S9Y_PEAR_PATH', '');
|
@define('S9Y_PEAR_PATH', '');
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user