1
0

* Added improved Blogger.com importer using the API, thanks to jaa

This commit is contained in:
Garvin Hicking
2009-02-17 09:11:23 +00:00
parent f541e5874d
commit d9194ac95e
3 changed files with 538 additions and 256 deletions

View File

@@ -3,6 +3,8 @@
Version 1.5 () Version 1.5 ()
------------------------------------------------------------------------ ------------------------------------------------------------------------
* Added improved Blogger.com importer using the API, thanks to jaa
* Change password hashing from plain md5 to salted SHA1. Logins * Change password hashing from plain md5 to salted SHA1. Logins
should continue to work and are migrated to SHA1 keys upon should continue to work and are migrated to SHA1 keys upon
first login. MD5-logins will only work successfully once. This first login. MD5-logins will only work successfully once. This

View File

@@ -2,35 +2,50 @@
# Copyright (c) 2003-2005, Jannis Hermanns (on behalf the Serendipity Developer Team) # Copyright (c) 2003-2005, Jannis Hermanns (on behalf the Serendipity Developer Team)
# All rights reserved. See LICENSE file for licensing details # All rights reserved. See LICENSE file for licensing details
/****************************************************************
* Blogger Importer v0.2, by Jawish Hameed (jawish.org) *
****************************************************************/
require_once S9Y_PEAR_PATH . 'HTTP/Request.php';
class Serendipity_Import_Blogger extends Serendipity_Import { class Serendipity_Import_Blogger extends Serendipity_Import {
var $info = array('software' => 'Blogger.com'); var $info = array('software' => 'Blogger.com [using API]');
var $data = array(); var $data = array();
var $inputFields = array(); var $inputFields = array();
function Serendipity_Import_Blogger($data) { function Serendipity_Import_Blogger($data) {
global $serendipity; global $serendipity;
$this->data = $data; $this->data = $data;
$this->inputFields = array(array('text' => 'Path to your Blogger export file', $this->inputFields = array(array('text' => 'Category',
'type' => 'input', 'type' => 'list',
'name' => 'bloggerfile', 'name' => 'bCategory',
'value' => $serendipity['serendipityPath']), 'value' => 0,
'default' => $this->_getCategoryList()),
array('text' => 'New author default password (used for non-existing authors on the serendipity backend, as author passwords from Blogger are not migrated)', array('text' => ACTIVATE_AUTODISCOVERY,
'type' => 'input', 'type' => 'bool',
'name' => 'defaultpass', 'name' => 'autodiscovery',
'value' => ''), 'default' => 'false'),
array('text' => CHARSET, array('text' => CHARSET,
'type' => 'list', 'type' => 'list',
'name' => 'charset', 'name' => 'bCharset',
'value' => 'UTF-8', 'value' => 'UTF-8',
'default' => $this->getCharsets()), 'default' => $this->getCharsets())
);
}
array('text' => RSS_IMPORT_BODYONLY, function getImportNotes(){
'type' => 'bool', if (empty($_REQUEST['token'])) {
'name' => 'bodyonly', $msg = 'In order to import your blog on Blogger, Serendipity needs to be able to access it via Google\'s Blogger Data APIs.<br />';
'value' => 'false')); $msg .= 'Login to your Google/Blogger account and then click the link below.<br /><br />';
$msg .= '<a href="https://www.google.com/accounts/AuthSubRequest?scope=http%3A%2F%2Fwww.blogger.com%2Ffeeds%2F&session=1&secure=0&next='. urlencode('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']) .'">Go to Google to grant access</a><br />';
return $msg;
} else {
return '';
}
} }
function validateData() { function validateData() {
@@ -38,220 +53,228 @@ class Serendipity_Import_Blogger extends Serendipity_Import {
} }
function getInputFields() { function getInputFields() {
// Make sure Google login has been completed
if (!empty($_REQUEST['token'])) {
// Prepare session token request
$req = new HTTP_Request('https://www.google.com/accounts/AuthSubSessionToken');
$req->addHeader('Authorization', 'AuthSub token="'. $_REQUEST['token'] .'"');
// Request token
$req->sendRequest();
// Handle token reponse
if ($req->getResponseCode() != '200') return;
// Extract Auth token
preg_match_all('/^(.+)=(.+)$/m', $req->getResponseBody(), $matches);
$tokens = array_combine($matches[1], $matches[2]);
unset($matches);
// Add hidden auth token field to input field list
array_unshift($this->inputFields, array( 'text' => 'Google Auth Token (leave alone)',
'type' => 'input',
'name' => 'bAuthToken',
'default' => $tokens['Token']));
// Prepare blog list request
$req = &new HTTP_Request('http://www.blogger.com/feeds/default/blogs');
$req->addHeader('GData-Version', 2);
$req->addHeader('Authorization', 'AuthSub token="'. $tokens['Token'] .'"');
// Fetch blog list
$req->sendRequest();
// Handle errors
if ($req->getResponseCode() != '200') return false;
// Load list
$bXml = simplexml_load_string($req->getResponseBody());
// Generate list of the blogs under the authenticated account
$bList = array();
foreach ($bXml->entry as $entry) {
$bList[substr($entry->id, strpos($entry->id, 'blog-') + 5)] = $entry->title;
}
// Add blog list to input fields for selection
array_unshift($this->inputFields, array('text' => 'Blog to import',
'type' => 'list',
'name' => 'bId',
'value' => 0,
'default' => $bList));
return $this->inputFields; return $this->inputFields;
} else {
return array();
}
} }
function getImportNotes() { function _getCategoryList() {
$out = ' $res = serendipity_fetchCategories('all');
<style type="text/css"> $ret = array(0 => NO_CATEGORY);
<!-- if (is_array($res)) {
.style1 { foreach ($res as $v) {
font-size: large; $ret[$v['categoryid']] = $v['category_name'];
font-weight: bold;
font-family: Arial, Helvetica, sans-serif;
} }
.style2 {
font-family: Arial, Helvetica, sans-serif;
font-size: x-small;
} }
--> return $ret;
</style>
<p class="style1">BLOGGER.COM to SERENDIPITY IMPORT</p>
<p class="style2">Version 0.1,( 29/10/2005 )</p>
<p class="style2"> <br />
1. First go to Blogger.com, login.</p>
<p class="style2">2. Go to the templates section. Set the following as your template. You should backup the current template if you want to reset it back after this operation. Click &quot;Save template changes&quot; button to save this new template.</p>
<p class="style2">
<label>
<textarea name="textarea" cols="60" rows="20"><Blogger>
STARTPOST
TITLE: <PostSubject><$BlogItemSubject$></PostSubject>
AUTHOR: <$BlogItemAuthor$>
DATE: <$BlogItemDateTime$>
-----
BODY:
<$BlogItemBody$>
-----
<BlogItemCommentsEnabled>
<BlogItemComments>
COMMENT:
AUTHOR: <$BlogCommentAuthor$>
DATE: <$BlogCommentDateTime$>
BODY: <$BlogCommentBody$>
-----
</BlogItemComments>
</BlogItemCommentsEnabled>
ENDPOST
</Blogger>
</textarea>
</label>
</p>
<p class="style2">3. Go to the &quot;Settings&quot; section of blogger. </p>
<p class="style2">4. Click the &quot;Formatting&quot; link. From the formatting options, find the &quot;Timestamp Format&quot; option and set it to the top most option. i.e the one with the date and time showing. Find the &quot;Show&quot; option, and set it to 999. Save changes</p>
<p class="style2">5. Now click the &quot;Comments&quot; link. Find the &quot;Comments Timestamp Format&quot; option and set it to the 2nd option from the list. i.e the one with the date and time showing. Save changes. </p>
<p class="style2">6. On the server with your Serendipity installation, create a directory called &quot;blogger&quot;. </p>
<p class="style2">7. Next, back on Blogger.com, go to the &quot;Publishing&quot; section. Set it to publish to an FTP server. Enter the details of the server with your Serendipity installation. Set the FTP path as the path to the &quot;blogger&quot; directory you created in the previous step. </p>
<p class="style2">8. Go back to Blogger.com and find &quot;Publish Entire Blog&quot; under &quot;Posting&quot; -&gt; &quot;Status&quot;. Click the Publish entire blog button to let blogger publish the blog to your ftp server.</p>
<p class="style2">9. Now in the box below type in the path to the &quot;index.html&quot; file blogger created under your &quot;blogger&quot; directory. File path should then look something like &quot;/httpdocs/blogger/index.html&quot;.</p>
<p class="style2">10. This script will create the users as from the blogger blog being imported. However if a user already exists, then that user will be used instead of creating a new user with similar name. For the new users that this script will create, you need to provide a default password. Type it in the box below.</p>
<p class="style2">11. Click &quot;Submit&quot;. Your posts and comments should be imported to serendipity!</p>
<p class="style2"> If you have questions or problems, feel free to drop me a mail at jaa at technova dot com dot mv.<br />
<br />
Jaa<br />
http://jaa.technova.com.mv</p>';
return $out;
} }
function import() { function import() {
global $serendipity; global $serendipity;
if (empty($this->data['bloggerfile']) || !file_exists($this->data['bloggerfile'])) { // Force user to select a blog to act on
echo "Path to blogger file empty or path to file wrong! Go back and correct."; if (empty($this->data['bId']) || $this->data['bId'] == 0) {
echo 'Please select a blog to import!';
return false; return false;
} }
# get default pass from request // Save this so we can return it to its original value at the end of this method.
$defaultpass = $this->data['defaultpass']; $noautodiscovery = isset($serendipity['noautodiscovery']) ? $serendipity['noautodiscovery'] : false;
# get blogger uploaded file path from request and load file if ($this->data['autodiscovery'] == 'false') {
$html = file_get_contents($this->data['bloggerfile']); $serendipity['noautodiscovery'] = 1;
# find posts using pattern matching
preg_match_all("/STARTPOST(.*)ENDPOST/sU", $html, $posts);
# iterate through all posts
foreach($posts[1] as $post) {
# locate the post title
if (preg_match("/TITLE:(.*)/", $post, $title)) {
$title = trim($title[1]);
echo "<b>" . htmlspecialchars($title) . "</b><br />";
} else {
$title = "";
echo "<b>Empty title</b><br />";
} }
# locate the post author $this->getTransTable();
if (preg_match("/AUTHOR:(.*)/", $post, $author)) {
$author = trim($author[1]); // Prepare export request
echo "<em>" . htmlspecialchars($author[1]) . "</em><br />"; $req = &new HTTP_Request('http://www.blogger.com/feeds/'. $this->data['bId'] .'/archive');
} else { $req->addHeader('GData-Version', 2);
$author = ""; $req->addHeader('Authorization', 'AuthSub token="'. $this->data['bAuthToken'] .'"');
echo "<em>Unknown author</em><br />";
// Attempt fetch blog export
$req->sendRequest();
// Handle errors
if ($req->getResponseCode() != '200') {
echo "Error occured while trying to export the blog.";
return false;
} }
# locate the post date // Export success
if (preg_match("/DATE:(.*)/", $post, $date)) { echo 'Successfully exported entries from Blogger<br />';
$date = strtotime(trim($date[1]));
echo "Posted on " . htmlspecialchars($date[1]) . ".<br />";
} else {
$date = time();
echo "Unknown posting time.<br />";
}
# locate the post body // Get Serendipity authors list
if (preg_match("/BODY:(.*)-----/sU", $post, $body)) { $authorList = array();
$body = trim($body[1]); $s9y_users = serendipity_fetchUsers();
echo strlen($body) . " Bytes of text.<br />"; foreach ($s9y_users as $user) {
} else { $authorList[$user['authorid']] = $user['username'];
$body = "";
echo "<strong>Empty Body!</strong><br />";
} }
unset($s9y_users);
# find all comments for the post using pattern matching // Load export
if (preg_match_all( "/COMMENT:(.*)----/sU", $post, $commentlist)) { $bXml = simplexml_load_string($req->getResponseBody());
echo count($commentlist[1]) . " comments found.<br />";
} else {
$commentlist = array();
echo "No comments found.<br />";
}
$result = serendipity_db_query("SELECT authorid FROM ". $serendipity['dbPrefix'] ."authors WHERE username = '". serendipity_db_escape_string($author) ."' LIMIT 1", true, 'assoc'); // Process entries
if (!is_array($result)) { $entryList = $entryFailList = array();
$data = array('right_publish' => 1, foreach ($bXml->entry as $bEntry) {
// Check entry type
switch ($bEntry->category['term']) {
case 'http://schemas.google.com/blogger/2008/kind#post':
// Process posts:
// Create author if not in serendipity
$author = (string) $bEntry->author->name;
if (!array_search($author, $authorList)) {
serendipity_db_insert( 'authors',
array( 'right_publish' => 1,
'realname' => $author, 'realname' => $author,
'username' => $author, 'username' => $author,
'userlevel' => 0, 'userlevel' => 0,
'password' => md5($defaultpass)); // MD5 compatible 'password' => md5($defaultpass))
serendipity_db_insert('authors', $data); );
$authorid = serendipity_db_insert_id('authors', 'authorid'); $authorid = serendipity_db_insert_id('authors', 'authorid');
} else { $authorList[$authorid] = $author;
$authorid = $result['authorid'];
} }
$sEntry = array('title' => $this->decode((string) $bEntry->title),
$entry = array('title' => $title, 'isdraft' => ($bEntry->children('http://purl.org/atom/app#')->control->draft == 'yes') ? 'true' : 'false',
'isdraft' => 'false', 'allow_comments' => (count($bEntry->xpath("*[@rel='replies']")) > 0) ? 'true' : 'false',
'allow_comments' => 'true', 'timestamp' => strtotime($bEntry->published),
'timestamp' => $date, 'body' => $this->strtr((string) $bEntry->content),
'body' => $body,
'extended' => '', 'extended' => '',
'categories' => $this->data['bCategory'],
'author' => $author, 'author' => $author,
'authorid' => $authorid 'authorid' => $authorid
); );
echo "Entry insert...<br />"; // Add entry to s9y
if (!is_int($id = serendipity_updertEntry($entry))) { echo '..~.. ';
echo "Inserting entry failed.<br />"; if (is_int($id = serendipity_updertEntry($sEntry))) {
return $id; // Add entry id to processed table for later lookups
$entryList[(string) $bEntry->id] = array($id, $sEntry['title'], 0);
} else { } else {
echo "Entry $id inserted.<br />"; // Add to fail list
$entryFailList[] = $sEntry['title'];
} }
# iterate through all comments break;
$c = 0;
foreach($commentlist[1] as $comment) {
$c++;
# locate the author and author url case 'http://schemas.google.com/blogger/2008/kind#comment':
$curl = ''; // Process comments:
$cauthor = '';
$cdate = time();
$cbody = '';
if (preg_match("/AUTHOR:(.*)/", $comment, $cauthor) && preg_match("/href=\"(.*)\"/", $cauthor[1], $curl)) { // Extract entry id for comment
$curl = (isset($curl[1]) ? trim($curl[1]) : ''); $cEntryId = $bEntry->xpath("thr:in-reply-to[@ref]");
$cauthor = trim(strip_tags($cauthor[1])); $cEntryId = (string) $cEntryId[0]['ref'];
}
# locate the date // Check to make sure the related entry has been added to s9y
if (preg_match("/DATE:(.*)/", $comment, $cdate)) { if (array_key_exists($cEntryId, $entryList)) {
$cdate = strtotime($cdate[1]); // Add to s9y
} $sComment = array( 'entry_id ' => $entryList[$cEntryId][0],
# locate the comment body
if (preg_match("/BODY:(.*)/s", $comment, $cbody)) {
$cbody = trim($cbody[1]);
}
$icomment = array('entry_id ' => $id,
'parent_id' => 0, 'parent_id' => 0,
'timestamp' => $cdate, 'timestamp' => strtotime($bEntry->published),
'author' => $cauthor, 'author' => (string) $bEntry->author->name,
'email' => '', 'email' => (string) $bEntry->author->email,
'url' => $curl, 'url' => (string) (isset($bEntry->author->uri)) ? $bEntry->author->uri : '',
'ip' => '', 'ip' => '',
'status' => 'approved', 'status' => 'approved',
'body' => $cbody, 'body' => $this->strtr((string) $bEntry->content),
'subscribed'=> 'false', 'subscribed'=> 'false',
'type' => 'NORMAL'); 'type' => 'NORMAL'
);
serendipity_db_insert('comments', $sComment);
serendipity_db_insert('comments', $icomment); // Update entry list with comment count
$entryList[$cEntryId][2]++;
} }
serendipity_db_query("UPDATE ". $serendipity['dbPrefix'] ."entries SET comments = ". $c ." WHERE id = ". $id); break;
echo "Comment count set to: ". $c ."<br />";
} }
}
// Report on resultant authors
echo '<br />Current list of authors: <br />'. join(', ', array_values($authorList)) .'<br /><br />';
// Do cleanup and report on entries
echo 'The following entries were successfully imported:<br />';
foreach ($entryList as $eId => $eDetails) {
// Update comment count for entry in s9y
serendipity_db_query("UPDATE ". $serendipity['dbPrefix'] ."entries SET comments = ". $eDetails[2] ." WHERE id = ". $eDetails[0]);
echo '- '. $eDetails[1] .' comments('. $eDetails[2] .')<br />';
}
echo '<br />';
// Report fails
echo 'The following entries ran into trouble and was not imported:<br />';
foreach ($entryFailList as $eId => $eDetails) {
echo '- '. $eDetails .'<br />';
}
// Reset autodiscovery
$serendipity['noautodiscovery'] = $noautodiscovery;
// All done!
echo "Import finished.<br />"; echo "Import finished.<br />";
return true; return true;
} }
} }
return 'Serendipity_Import_Blogger'; return 'Serendipity_Import_Blogger';
/* vim: set sts=4 ts=4 expandtab : */
?> ?>

View File

@@ -0,0 +1,257 @@
<?php # $Id$
# Copyright (c) 2003-2005, Jannis Hermanns (on behalf the Serendipity Developer Team)
# All rights reserved. See LICENSE file for licensing details
class Serendipity_Import_OldBlogger extends Serendipity_Import {
var $info = array('software' => 'Blogger.com [OLD]');
var $data = array();
var $inputFields = array();
function Serendipity_Import_OldBlogger($data) {
global $serendipity;
$this->data = $data;
$this->inputFields = array(array('text' => 'Path to your Blogger export file',
'type' => 'input',
'name' => 'bloggerfile',
'value' => $serendipity['serendipityPath']),
array('text' => 'New author default password (used for non-existing authors on the serendipity backend, as author passwords from Blogger are not migrated)',
'type' => 'input',
'name' => 'defaultpass',
'value' => ''),
array('text' => CHARSET,
'type' => 'list',
'name' => 'charset',
'value' => 'UTF-8',
'default' => $this->getCharsets()),
array('text' => RSS_IMPORT_BODYONLY,
'type' => 'bool',
'name' => 'bodyonly',
'value' => 'false'));
}
function validateData() {
return sizeof($this->data);
}
function getInputFields() {
return $this->inputFields;
}
function getImportNotes() {
$out = '
<style type="text/css">
<!--
.style1 {
font-size: large;
font-weight: bold;
font-family: Arial, Helvetica, sans-serif;
}
.style2 {
font-family: Arial, Helvetica, sans-serif;
font-size: x-small;
}
-->
</style>
<p class="style1">BLOGGER.COM to SERENDIPITY IMPORT</p>
<p class="style2">Version 0.1,( 29/10/2005 )</p>
<p class="style2"> <br />
1. First go to Blogger.com, login.</p>
<p class="style2">2. Go to the templates section. Set the following as your template. You should backup the current template if you want to reset it back after this operation. Click &quot;Save template changes&quot; button to save this new template.</p>
<p class="style2">
<label>
<textarea name="textarea" cols="60" rows="20"><Blogger>
STARTPOST
TITLE: <PostSubject><$BlogItemSubject$></PostSubject>
AUTHOR: <$BlogItemAuthor$>
DATE: <$BlogItemDateTime$>
-----
BODY:
<$BlogItemBody$>
-----
<BlogItemCommentsEnabled>
<BlogItemComments>
COMMENT:
AUTHOR: <$BlogCommentAuthor$>
DATE: <$BlogCommentDateTime$>
BODY: <$BlogCommentBody$>
-----
</BlogItemComments>
</BlogItemCommentsEnabled>
ENDPOST
</Blogger>
</textarea>
</label>
</p>
<p class="style2">3. Go to the &quot;Settings&quot; section of blogger. </p>
<p class="style2">4. Click the &quot;Formatting&quot; link. From the formatting options, find the &quot;Timestamp Format&quot; option and set it to the top most option. i.e the one with the date and time showing. Find the &quot;Show&quot; option, and set it to 999. Save changes</p>
<p class="style2">5. Now click the &quot;Comments&quot; link. Find the &quot;Comments Timestamp Format&quot; option and set it to the 2nd option from the list. i.e the one with the date and time showing. Save changes. </p>
<p class="style2">6. On the server with your Serendipity installation, create a directory called &quot;blogger&quot;. </p>
<p class="style2">7. Next, back on Blogger.com, go to the &quot;Publishing&quot; section. Set it to publish to an FTP server. Enter the details of the server with your Serendipity installation. Set the FTP path as the path to the &quot;blogger&quot; directory you created in the previous step. </p>
<p class="style2">8. Go back to Blogger.com and find &quot;Publish Entire Blog&quot; under &quot;Posting&quot; -&gt; &quot;Status&quot;. Click the Publish entire blog button to let blogger publish the blog to your ftp server.</p>
<p class="style2">9. Now in the box below type in the path to the &quot;index.html&quot; file blogger created under your &quot;blogger&quot; directory. File path should then look something like &quot;/httpdocs/blogger/index.html&quot;.</p>
<p class="style2">10. This script will create the users as from the blogger blog being imported. However if a user already exists, then that user will be used instead of creating a new user with similar name. For the new users that this script will create, you need to provide a default password. Type it in the box below.</p>
<p class="style2">11. Click &quot;Submit&quot;. Your posts and comments should be imported to serendipity!</p>
<p class="style2"> If you have questions or problems, feel free to drop me a mail at jaa at technova dot com dot mv.<br />
<br />
Jaa<br />
http://jaa.technova.com.mv</p>';
return $out;
}
function import() {
global $serendipity;
if (empty($this->data['bloggerfile']) || !file_exists($this->data['bloggerfile'])) {
echo "Path to blogger file empty or path to file wrong! Go back and correct.";
return false;
}
# get default pass from request
$defaultpass = $this->data['defaultpass'];
# get blogger uploaded file path from request and load file
$html = file_get_contents($this->data['bloggerfile']);
# find posts using pattern matching
preg_match_all("/STARTPOST(.*)ENDPOST/sU", $html, $posts);
# iterate through all posts
foreach($posts[1] as $post) {
# locate the post title
if (preg_match("/TITLE:(.*)/", $post, $title)) {
$title = trim($title[1]);
echo "<b>" . htmlspecialchars($title) . "</b><br />";
} else {
$title = "";
echo "<b>Empty title</b><br />";
}
# locate the post author
if (preg_match("/AUTHOR:(.*)/", $post, $author)) {
$author = trim($author[1]);
echo "<em>" . htmlspecialchars($author[1]) . "</em><br />";
} else {
$author = "";
echo "<em>Unknown author</em><br />";
}
# locate the post date
if (preg_match("/DATE:(.*)/", $post, $date)) {
$date = strtotime(trim($date[1]));
echo "Posted on " . htmlspecialchars($date[1]) . ".<br />";
} else {
$date = time();
echo "Unknown posting time.<br />";
}
# locate the post body
if (preg_match("/BODY:(.*)-----/sU", $post, $body)) {
$body = trim($body[1]);
echo strlen($body) . " Bytes of text.<br />";
} else {
$body = "";
echo "<strong>Empty Body!</strong><br />";
}
# find all comments for the post using pattern matching
if (preg_match_all( "/COMMENT:(.*)----/sU", $post, $commentlist)) {
echo count($commentlist[1]) . " comments found.<br />";
} else {
$commentlist = array();
echo "No comments found.<br />";
}
$result = serendipity_db_query("SELECT authorid FROM ". $serendipity['dbPrefix'] ."authors WHERE username = '". serendipity_db_escape_string($author) ."' LIMIT 1", true, 'assoc');
if (!is_array($result)) {
$data = array('right_publish' => 1,
'realname' => $author,
'username' => $author,
'userlevel' => 0,
'password' => md5($defaultpass)); // MD5 compatible
serendipity_db_insert('authors', $data);
$authorid = serendipity_db_insert_id('authors', 'authorid');
} else {
$authorid = $result['authorid'];
}
$entry = array('title' => $title,
'isdraft' => 'false',
'allow_comments' => 'true',
'timestamp' => $date,
'body' => $body,
'extended' => '',
'author' => $author,
'authorid' => $authorid
);
echo "Entry insert...<br />";
if (!is_int($id = serendipity_updertEntry($entry))) {
echo "Inserting entry failed.<br />";
return $id;
} else {
echo "Entry $id inserted.<br />";
}
# iterate through all comments
$c = 0;
foreach($commentlist[1] as $comment) {
$c++;
# locate the author and author url
$curl = '';
$cauthor = '';
$cdate = time();
$cbody = '';
if (preg_match("/AUTHOR:(.*)/", $comment, $cauthor) && preg_match("/href=\"(.*)\"/", $cauthor[1], $curl)) {
$curl = (isset($curl[1]) ? trim($curl[1]) : '');
$cauthor = trim(strip_tags($cauthor[1]));
}
# locate the date
if (preg_match("/DATE:(.*)/", $comment, $cdate)) {
$cdate = strtotime($cdate[1]);
}
# locate the comment body
if (preg_match("/BODY:(.*)/s", $comment, $cbody)) {
$cbody = trim($cbody[1]);
}
$icomment = array('entry_id ' => $id,
'parent_id' => 0,
'timestamp' => $cdate,
'author' => $cauthor,
'email' => '',
'url' => $curl,
'ip' => '',
'status' => 'approved',
'body' => $cbody,
'subscribed'=> 'false',
'type' => 'NORMAL');
serendipity_db_insert('comments', $icomment);
}
serendipity_db_query("UPDATE ". $serendipity['dbPrefix'] ."entries SET comments = ". $c ." WHERE id = ". $id);
echo "Comment count set to: ". $c ."<br />";
}
echo "Import finished.<br />";
return true;
}
}
return 'Serendipity_Import_OldBlogger';
/* vim: set sts=4 ts=4 expandtab : */
?>