From 9784536ff90d2bda997088fd05c39247e44f52b4 Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 14 Feb 2013 17:39:16 -0800 Subject: more groundwork for channel import --- mod/import.php | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 8 deletions(-) (limited to 'mod/import.php') diff --git a/mod/import.php b/mod/import.php index 5da9d0004..7b5989f51 100644 --- a/mod/import.php +++ b/mod/import.php @@ -7,7 +7,8 @@ function import_post(&$a) { - $sieze = ((x($_REQUEST,'make_primary')) ? intval($_REQUEST['make_primary']) : 0); + $data = null; + $seize = ((x($_REQUEST,'make_primary')) ? intval($_REQUEST['make_primary']) : 0); $src = $_FILES['userfile']['tmp_name']; $filename = basename($_FILES['userfile']['name']); @@ -15,10 +16,10 @@ function import_post(&$a) { $filetype = $_FILES['userfile']['type']; - if(($src) && (! $filesize)) { - logger('mod_import: empty file.'); - notice( t('Imported file is empty.') . EOL); - return; + if($src) { + if($filesize) { + $data = @file_get_contents($src); + } } if(! $src) { @@ -29,12 +30,38 @@ function import_post(&$a) { return; } - // Connect to API of old server with credentials given and suck in the data we need + $email = ((x($_REQUEST,'email')) ? $_REQUEST['email'] : ''); + $password = ((x($_REQUEST,'password')) ? $_REQUEST['password'] : ''); + + $channelname = substr($old_address,0,strpos($old_address,'@')); + $servername = substr($old_address,strpos($old_address,'@')+1); + + $scheme = 'https://'; + $api_path = '/api/export/basic?f=&channel=' . $channelname; + $binary = false; + $redirects = 0; + $opts = array('http_auth' => $email . ':' . $password); + $url = $scheme . $servername . $api_path; + $ret = z_fetch_url($url, $binary, $redirects, $opts); + if(! $ret['success']) + $ret = z_fetch_url('http://' . $servername . $api_path, $binary, $redirects, $opts); + if($ret['success']) + $data = $ret['body']; + else + notice( t('Unable to download data from old server') . EOL); + } + if(! $data) { + logger('mod_import: empty file.'); + notice( t('Imported file is empty.') . EOL); + return; } +// logger('import: data: ' . print_r($data,true)); + +// print_r($data); // import channel @@ -44,7 +71,7 @@ function import_post(&$a) { - if($sieze) { + if($seize) { // notify old server that it is no longer primary. } @@ -55,10 +82,25 @@ function import_post(&$a) { } - function import_content(&$a) { +/* + * Pass in a channel name and desired channel_address + * Check this for validity and duplication + * The page template should have a place to change it and check again + */ + + +$o .= <<< EOT +
+Old Address
+Login
+Password
+ +
+EOT; +return $o; } \ No newline at end of file -- cgit v1.2.3