1
0
in blogger a strange editor was used to write the file
This commit is contained in:
Ian
2014-11-24 14:30:49 +01:00
parent 8da4c647a8
commit efe2303b23
2 changed files with 39 additions and 40 deletions

View File

@ -12,8 +12,7 @@ class Serendipity_Import_Blogger extends Serendipity_Import {
var $info = array('software' => 'Blogger.com [using API]'); 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;
@ -55,22 +54,22 @@ class Serendipity_Import_Blogger extends Serendipity_Import {
function getInputFields() { function getInputFields() {
// Make sure Google login has been completed // Make sure Google login has been completed
if (!empty($_REQUEST['token'])) { if (!empty($_REQUEST['token'])) {
// Prepare session token request // Prepare session token request
$req = new HTTP_Request('https://www.google.com/accounts/AuthSubSessionToken'); $req = new HTTP_Request('https://www.google.com/accounts/AuthSubSessionToken');
$req->addHeader('Authorization', 'AuthSub token="'. $_REQUEST['token'] .'"'); $req->addHeader('Authorization', 'AuthSub token="'. $_REQUEST['token'] .'"');
// Request token // Request token
$req->sendRequest(); $req->sendRequest();
// Handle token reponse // Handle token reponse
if ($req->getResponseCode() != '200') return; if ($req->getResponseCode() != '200') return;
// Extract Auth token // Extract Auth token
preg_match_all('/^(.+)=(.+)$/m', $req->getResponseBody(), $matches); preg_match_all('/^(.+)=(.+)$/m', $req->getResponseBody(), $matches);
$tokens = array_combine($matches[1], $matches[2]); $tokens = array_combine($matches[1], $matches[2]);
unset($matches); unset($matches);
// Add hidden auth token field to input field list // Add hidden auth token field to input field list
array_unshift($this->inputFields, array( 'text' => 'Google Auth Token (leave alone)', array_unshift($this->inputFields, array( 'text' => 'Google Auth Token (leave alone)',
'type' => 'input', 'type' => 'input',
@ -81,35 +80,35 @@ class Serendipity_Import_Blogger extends Serendipity_Import {
$req = new HTTP_Request('http://www.blogger.com/feeds/default/blogs'); $req = new HTTP_Request('http://www.blogger.com/feeds/default/blogs');
$req->addHeader('GData-Version', 2); $req->addHeader('GData-Version', 2);
$req->addHeader('Authorization', 'AuthSub token="'. $tokens['Token'] .'"'); $req->addHeader('Authorization', 'AuthSub token="'. $tokens['Token'] .'"');
// Fetch blog list // Fetch blog list
$req->sendRequest(); $req->sendRequest();
// Handle errors // Handle errors
if ($req->getResponseCode() != '200') return false; if ($req->getResponseCode() != '200') return false;
// Load list // Load list
$bXml = simplexml_load_string($req->getResponseBody()); $bXml = simplexml_load_string($req->getResponseBody());
// Generate list of the blogs under the authenticated account // Generate list of the blogs under the authenticated account
$bList = array(); $bList = array();
foreach ($bXml->entry as $entry) { foreach ($bXml->entry as $entry) {
$bList[substr($entry->id, strpos($entry->id, 'blog-') + 5)] = $entry->title; $bList[substr($entry->id, strpos($entry->id, 'blog-') + 5)] = $entry->title;
} }
// Add blog list to input fields for selection // Add blog list to input fields for selection
array_unshift($this->inputFields, array('text' => 'Blog to import', array_unshift($this->inputFields, array('text' => 'Blog to import',
'type' => 'list', 'type' => 'list',
'name' => 'bId', 'name' => 'bId',
'value' => 0, 'value' => 0,
'default' => $bList)); 'default' => $bList));
return $this->inputFields; return $this->inputFields;
} else { } else {
return array(); return array();
} }
} }
function _getCategoryList() { function _getCategoryList() {
$res = serendipity_fetchCategories('all'); $res = serendipity_fetchCategories('all');
$ret = array(0 => NO_CATEGORY); $ret = array(0 => NO_CATEGORY);
@ -120,16 +119,16 @@ class Serendipity_Import_Blogger extends Serendipity_Import {
} }
return $ret; return $ret;
} }
function import() { function import() {
global $serendipity; global $serendipity;
// Force user to select a blog to act on // Force user to select a blog to act on
if (empty($this->data['bId']) || $this->data['bId'] == 0) { if (empty($this->data['bId']) || $this->data['bId'] == 0) {
echo 'Please select a blog to import!'; echo 'Please select a blog to import!';
return false; return false;
} }
// 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;
@ -138,24 +137,24 @@ class Serendipity_Import_Blogger extends Serendipity_Import {
} }
$this->getTransTable(); $this->getTransTable();
// Prepare export request // Prepare export request
$req = new HTTP_Request('http://www.blogger.com/feeds/'. $this->data['bId'] .'/archive'); $req = new HTTP_Request('http://www.blogger.com/feeds/'. $this->data['bId'] .'/archive');
$req->addHeader('GData-Version', 2); $req->addHeader('GData-Version', 2);
$req->addHeader('Authorization', 'AuthSub token="'. $this->data['bAuthToken'] .'"'); $req->addHeader('Authorization', 'AuthSub token="'. $this->data['bAuthToken'] .'"');
// Attempt fetch blog export // Attempt fetch blog export
$req->sendRequest(); $req->sendRequest();
// Handle errors // Handle errors
if ($req->getResponseCode() != '200') { if ($req->getResponseCode() != '200') {
echo "Error occured while trying to export the blog."; echo "Error occured while trying to export the blog.";
return false; return false;
} }
// Export success // Export success
echo '<span class="block_level">Successfully exported entries from Blogger</span>'; echo '<span class="block_level">Successfully exported entries from Blogger</span>';
// Get Serendipity authors list // Get Serendipity authors list
$authorList = array(); $authorList = array();
$s9y_users = serendipity_fetchUsers(); $s9y_users = serendipity_fetchUsers();
@ -166,16 +165,16 @@ class Serendipity_Import_Blogger extends Serendipity_Import {
// Load export // Load export
$bXml = simplexml_load_string($req->getResponseBody()); $bXml = simplexml_load_string($req->getResponseBody());
// Process entries // Process entries
$entryList = $entryFailList = array(); $entryList = $entryFailList = array();
foreach ($bXml->entry as $bEntry) { foreach ($bXml->entry as $bEntry) {
// Check entry type // Check entry type
switch ($bEntry->category['term']) { switch ($bEntry->category['term']) {
case 'http://schemas.google.com/blogger/2008/kind#post': case 'http://schemas.google.com/blogger/2008/kind#post':
// Process posts: // Process posts:
// Create author if not in serendipity // Create author if not in serendipity
$author = (string) $bEntry->author->name; $author = (string) $bEntry->author->name;
if (!array_search($author, $authorList)) { if (!array_search($author, $authorList)) {
@ -189,7 +188,7 @@ class Serendipity_Import_Blogger extends Serendipity_Import {
$authorid = serendipity_db_insert_id('authors', 'authorid'); $authorid = serendipity_db_insert_id('authors', 'authorid');
$authorList[$authorid] = $author; $authorList[$authorid] = $author;
} }
$sEntry = array('title' => $this->decode((string) $bEntry->title), $sEntry = array('title' => $this->decode((string) $bEntry->title),
'isdraft' => ($bEntry->children('http://purl.org/atom/app#')->control->draft == 'yes') ? 'true' : 'false', 'isdraft' => ($bEntry->children('http://purl.org/atom/app#')->control->draft == 'yes') ? 'true' : 'false',
'allow_comments' => (count($bEntry->xpath("*[@rel='replies']")) > 0) ? 'true' : 'false', 'allow_comments' => (count($bEntry->xpath("*[@rel='replies']")) > 0) ? 'true' : 'false',
@ -200,7 +199,7 @@ class Serendipity_Import_Blogger extends Serendipity_Import {
'author' => $author, 'author' => $author,
'authorid' => $authorid 'authorid' => $authorid
); );
// Add entry to s9y // Add entry to s9y
echo '..~.. '; echo '..~.. ';
if (is_int($id = serendipity_updertEntry($sEntry))) { if (is_int($id = serendipity_updertEntry($sEntry))) {
@ -210,16 +209,16 @@ class Serendipity_Import_Blogger extends Serendipity_Import {
// Add to fail list // Add to fail list
$entryFailList[] = $sEntry['title']; $entryFailList[] = $sEntry['title'];
} }
break; break;
case 'http://schemas.google.com/blogger/2008/kind#comment': case 'http://schemas.google.com/blogger/2008/kind#comment':
// Process comments: // Process comments:
// Extract entry id for comment // Extract entry id for comment
$cEntryId = $bEntry->xpath("thr:in-reply-to[@ref]"); $cEntryId = $bEntry->xpath("thr:in-reply-to[@ref]");
$cEntryId = (string) $cEntryId[0]['ref']; $cEntryId = (string) $cEntryId[0]['ref'];
// Check to make sure the related entry has been added to s9y // Check to make sure the related entry has been added to s9y
if (array_key_exists($cEntryId, $entryList)) { if (array_key_exists($cEntryId, $entryList)) {
// Add to s9y // Add to s9y
@ -236,19 +235,19 @@ class Serendipity_Import_Blogger extends Serendipity_Import {
'type' => 'NORMAL' 'type' => 'NORMAL'
); );
serendipity_db_insert('comments', $sComment); serendipity_db_insert('comments', $sComment);
// Update entry list with comment count // Update entry list with comment count
$entryList[$cEntryId][2]++; $entryList[$cEntryId][2]++;
} }
break; break;
} }
} }
// Report on resultant authors // Report on resultant authors
echo '<span class="block_level">Current list of authors: </span>'. join(', ', array_values($authorList)); echo '<span class="block_level">Current list of authors: </span>'. join(', ', array_values($authorList));
// Do cleanup and report on entries // Do cleanup and report on entries
echo '<span class="block_level">The following entries were successfully imported:</span>'; echo '<span class="block_level">The following entries were successfully imported:</span>';
echo '<ul>'; echo '<ul>';
@ -259,7 +258,7 @@ class Serendipity_Import_Blogger extends Serendipity_Import {
echo '<li>'. $eDetails[1] .' comments('. $eDetails[2] .')</li>'; echo '<li>'. $eDetails[1] .' comments('. $eDetails[2] .')</li>';
} }
echo '</ul>'; echo '</ul>';
// Report fails // Report fails
echo '<span class="block_level">The following entries ran into trouble and was not imported:</span>'; echo '<span class="block_level">The following entries ran into trouble and was not imported:</span>';
echo '<ul>'; echo '<ul>';
@ -267,10 +266,10 @@ class Serendipity_Import_Blogger extends Serendipity_Import {
echo '<li>'. $eDetails .'</li>'; echo '<li>'. $eDetails .'</li>';
} }
echo '</ul>'; echo '</ul>';
// Reset autodiscovery // Reset autodiscovery
$serendipity['noautodiscovery'] = $noautodiscovery; $serendipity['noautodiscovery'] = $noautodiscovery;
// All done! // All done!
echo '<span class="msg_notice">Import finished.</span>'; echo '<span class="msg_notice">Import finished.</span>';
return true; return true;

View File

@ -255,7 +255,7 @@ function &serendipity_db_query($sql, $single = false, $result_type = "both", $re
$rows = array(); $rows = array();
foreach($serendipity['dbSth']->fetchAll($result_type) AS $row) { foreach($serendipity['dbSth']->fetchAll($result_type) AS $row) {
$row = serendipity_db_sqlite_fetch_array($row, $result_type); $row = serendipity_db_sqlite_fetch_array($row, $result_type);
if (!empty($assocKey)) { if (!empty($assocKey)) {
// You can fetch a key-associated array via the two function parameters assocKey and assocVal // You can fetch a key-associated array via the two function parameters assocKey and assocVal
if (empty($assocVal)) { if (empty($assocVal)) {