Move importers to Http/Request2 and __construct (#399)

This commit is contained in:
onli 2016-05-10 02:47:22 +00:00
parent fd90812453
commit d4fe793820
22 changed files with 49 additions and 46 deletions

View File

@ -16,7 +16,7 @@ class Serendipity_Import_b2evolution extends Serendipity_Import {
return '';
}
function Serendipity_Import_b2evolution($data) {
function __construct($data) {
$this->data = $data;
$this->inputFields = array(array('text' => INSTALL_DBHOST,
'type' => 'input',

View File

@ -12,7 +12,7 @@ class Serendipity_Import_bblog extends Serendipity_Import {
var $inputFields = array();
var $categories = array();
function Serendipity_Import_bblog($data) {
function __construct($data) {
$this->data = $data;
$this->inputFields = array(array('text' => INSTALL_DBHOST,
'type' => 'input',

View File

@ -6,14 +6,14 @@
* Blogger Importer v0.2, by Jawish Hameed (jawish.org) *
****************************************************************/
require_once S9Y_PEAR_PATH . 'HTTP/Request.php';
require_once S9Y_PEAR_PATH . 'HTTP/Request2.php';
class Serendipity_Import_Blogger extends Serendipity_Import {
var $info = array('software' => 'Blogger.com [using API]');
var $data = array();
var $inputFields = array();
function Serendipity_Import_Blogger($data) {
function __construct($data) {
global $serendipity;
$this->data = $data;
@ -56,17 +56,17 @@ class Serendipity_Import_Blogger extends Serendipity_Import {
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'] .'"');
$req = new HTTP_Request2('https://www.google.com/accounts/AuthSubSessionToken');
$req->setHeader('Authorization', 'AuthSub token="'. $_REQUEST['token'] .'"');
// Request token
$req->sendRequest();
$response = $req->send();
// Handle token reponse
if ($req->getResponseCode() != '200') return;
if ($response->getStatus() != '200') return;
// Extract Auth token
preg_match_all('/^(.+)=(.+)$/m', $req->getResponseBody(), $matches);
preg_match_all('/^(.+)=(.+)$/m', $response->getBody(), $matches);
$tokens = array_combine($matches[1], $matches[2]);
unset($matches);
@ -77,18 +77,18 @@ class Serendipity_Import_Blogger extends Serendipity_Import {
'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'] .'"');
$req = new HTTP_Request2('http://www.blogger.com/feeds/default/blogs');
$req->setHeader('GData-Version', 2);
$req->setHeader('Authorization', 'AuthSub token="'. $tokens['Token'] .'"');
// Fetch blog list
$req->sendRequest();
$response = $req->send();
// Handle errors
if ($req->getResponseCode() != '200') return false;
if ($response->getStatus() != '200') return false;
// Load list
$bXml = simplexml_load_string($req->getResponseBody());
$bXml = simplexml_load_string($response->getBody());
// Generate list of the blogs under the authenticated account
$bList = array();
@ -139,15 +139,15 @@ class Serendipity_Import_Blogger extends Serendipity_Import {
$this->getTransTable();
// Prepare export request
$req = new HTTP_Request('http://www.blogger.com/feeds/'. $this->data['bId'] .'/archive');
$req->addHeader('GData-Version', 2);
$req->addHeader('Authorization', 'AuthSub token="'. $this->data['bAuthToken'] .'"');
$req = new HTTP_Request2('http://www.blogger.com/feeds/'. $this->data['bId'] .'/archive');
$req->setHeader('GData-Version', 2);
$req->setHeader('Authorization', 'AuthSub token="'. $this->data['bAuthToken'] .'"');
// Attempt fetch blog export
$req->sendRequest();
$response = $req->send();
// Handle errors
if ($req->getResponseCode() != '200') {
if ($response->getStatus() != '200') {
echo "Error occured while trying to export the blog.";
return false;
}
@ -164,7 +164,7 @@ class Serendipity_Import_Blogger extends Serendipity_Import {
unset($s9y_users);
// Load export
$bXml = simplexml_load_string($req->getResponseBody());
$bXml = simplexml_load_string($response->getBody());
// Process entries
$entryList = $entryFailList = array();

View File

@ -16,7 +16,7 @@ class Serendipity_Import_bmachine extends Serendipity_Import {
return '';
}
function Serendipity_Import_bmachine($data) {
function __construct($data) {
$this->data = $data;
$this->inputFields = array(array('text' => INSTALL_DBHOST,
'type' => 'input',

View File

@ -16,7 +16,7 @@ class Serendipity_Import_geeklog extends Serendipity_Import {
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) {
function __construct($data) {
$this->data = $data;
$this->inputFields = array(array('text' => INSTALL_DBHOST,
'type' => 'input',

View File

@ -10,7 +10,7 @@ class Serendipity_Import_Generic extends Serendipity_Import {
var $inputFields = array();
var $force_recode = false;
function Serendipity_Import_Generic($data) {
function __construct($data) {
$this->data = $data;
$this->inputFields = array(array('text' => RSS . ' ' . URL,
'type' => 'input',
@ -139,18 +139,21 @@ class Serendipity_Import_Generic extends Serendipity_Import {
$serendipity['noautodiscovery'] = 1;
$uri = $this->data['url'];
require_once S9Y_PEAR_PATH . 'HTTP/Request.php';
require_once S9Y_PEAR_PATH . 'HTTP/Request2.php';
serendipity_request_start();
$req = new HTTP_Request($uri, array('allowRedirects' => true, 'maxRedirects' => 5));
$res = $req->sendRequest();
if (PEAR::isError($res) || $req->getResponseCode() != '200') {
$req = new HTTP_Request2($uri, HTTP_Request2::METHOD_GET, array('follow_redirects' => true, 'max_redirects' => 5));
try {
$res = $req->send();
if ($res->getStatus() != '200') {
throw new HTTP_Request2_Exception('could not fetch url: status != 200');
}
} catch (HTTP_Request2_Exception $e) {
serendipity_request_end();
echo '<span class="block_level">' . IMPORT_FAILED . ': ' . serendipity_specialchars($this->data['url']) . '</span>';
return false;
}
$fContent = $req->getResponseBody();
$fContent = $res->getBody();
serendipity_request_end();
echo '<span class="block_level">' . strlen($fContent) . " Bytes</span>";

View File

@ -16,7 +16,7 @@ class Serendipity_Import_lifetype extends Serendipity_Import {
return '';
}
function Serendipity_Import_lifetype($data) {
function __construct($data) {
$this->data = $data;
$this->inputFields = array(array('text' => INSTALL_DBHOST,
'type' => 'input',

View File

@ -11,7 +11,7 @@ class Serendipity_Import_LiveJournalXML extends Serendipity_Import {
var $inputFields = array();
var $force_recode = false;
function Serendipity_Import_LiveJournalXML($data) {
function __construct($data) {
global $serendipity;
$this->data = $data;
$this->inputFields = array(array('text' => 'LiveJournal XML',

View File

@ -24,7 +24,7 @@ class Serendipity_Import_MovableType extends Serendipity_Import {
var $data = array();
var $inputFields = array();
function Serendipity_Import_MovableType($data) {
function __construct($data) {
$this->data = $data;
$this->inputFields = array(array('text' => MT_DATA_FILE,
'type' => 'file',

View File

@ -12,7 +12,7 @@ class Serendipity_Import_Nucleus extends Serendipity_Import {
var $inputFields = array();
function Serendipity_Import_Nucleus($data) {
function __construct($data) {
$this->data = $data;
$this->inputFields = array(array('text' => INSTALL_DBHOST,
'type' => 'input',

View File

@ -16,7 +16,7 @@ class Serendipity_Import_nuke extends Serendipity_Import {
return '';
}
function Serendipity_Import_nuke($data) {
function __construct($data) {
$this->data = $data;
$this->inputFields = array(array('text' => INSTALL_DBHOST,
'type' => 'input',

View File

@ -7,7 +7,7 @@ class Serendipity_Import_OldBlogger extends Serendipity_Import {
var $data = array();
var $inputFields = array();
function Serendipity_Import_OldBlogger($data) {
function __construct($data) {
global $serendipity;
$this->data = $data;

View File

@ -12,7 +12,7 @@ class Serendipity_Import_phpbb extends Serendipity_Import {
var $inputFields = array();
var $categories = array();
function Serendipity_Import_phpbb($data) {
function __construct($data) {
$this->data = $data;
$this->inputFields = array(array('text' => INSTALL_DBHOST,
'type' => 'input',

View File

@ -10,7 +10,7 @@ class Serendipity_Import_Pivot extends Serendipity_Import {
var $data = array();
var $inputFields = array();
function Serendipity_Import_Pivot($data) {
function __construct($data) {
$this->data = $data;
$this->inputFields = array(array('text' => PARENT_DIRECTORY,
'type' => 'input',

View File

@ -12,7 +12,7 @@ class Serendipity_Import_pMachine extends Serendipity_Import {
var $inputFields = array();
function Serendipity_Import_pMachine($data) {
function __construct($data) {
$this->data = $data;
$this->inputFields = array(array('text' => INSTALL_DBHOST,
'type' => 'input',

View File

@ -24,7 +24,7 @@ class Serendipity_Import_Serendipity extends Serendipity_Import {
<p>After these precautions: The importer code generally works very well for me and my purposes. Your mileage may vary.</p>';
}
function Serendipity_Import_Serendipity ($data) {
function __construct($data) {
global $serendipity;
$this->data = $data;

View File

@ -16,7 +16,7 @@ class Serendipity_Import_smf extends Serendipity_Import {
return '<p>SMF uses salted MD5 passwords that Serendipity cannot import. Thus, those passwords are incompatible with the MD5 hashing of Serendipity. The passwords for all users have been set to a random string. <strong>You need to modify the passwords manually for each user</strong>, we are sorry for that inconvenience.</p>';
}
function Serendipity_Import_smf($data) {
function __construct($data) {
$this->data = $data;
$this->inputFields = array(array('text' => INSTALL_DBHOST,
'type' => 'input',

View File

@ -17,7 +17,7 @@ class Serendipity_Import_sunlog extends Serendipity_Import {
. '<p>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.</p>';
}
function Serendipity_Import_sunlog($data) {
function __construct($data) {
$this->data = $data;
$this->inputFields = array(array('text' => INSTALL_DBHOST,
'type' => 'input',

View File

@ -16,7 +16,7 @@ class Serendipity_Import_textpattern extends Serendipity_Import {
return '<p>Textpattern uses MySQLs native PASSWORD() function to save passwords. Thus, those passwords are incompatible with the MD5 hashing of Serendipity. The passwords for all users have been set to "txp". <strong>You need to modify the passwords manually for each user</strong>, we are sorry for that inconvenience.</p>';
}
function Serendipity_Import_textpattern($data) {
function __construct($data) {
$this->data = $data;
$this->inputFields = array(array('text' => INSTALL_DBHOST,
'type' => 'input',

View File

@ -41,7 +41,7 @@ class Serendipity_Import_VoodooPad extends Serendipity_Import {
var $inputFields = array();
var $force_recode = false;
function Serendipity_Import_VoodooPad($data) {
function __construct($data) {
$this->data = $data;
$this->inputFields = array(
array('text' => IMPORTER_VOODOO_FILEPROMPT,

View File

@ -12,7 +12,7 @@ class Serendipity_Import_WordPress_PG extends Serendipity_Import {
var $inputFields = array();
function Serendipity_Import_WordPress_PG($data) {
function __construct($data) {
$this->data = $data;
$this->inputFields = array(array('text' => INSTALL_DBHOST,
'type' => 'input',

View File

@ -12,7 +12,7 @@ class Serendipity_Import_WordPress extends Serendipity_Import {
var $inputFields = array();
function Serendipity_Import_WordPress($data) {
function __construct($data) {
$this->data = $data;
$this->inputFields = array(array('text' => INSTALL_DBHOST,
'type' => 'input',