mirror of
https://codeberg.org/streams/streams.git
synced 2024-09-20 02:55:13 +00:00
more groundwork for channel import
This commit is contained in:
parent
d6db8513e8
commit
9784536ff9
3 changed files with 71 additions and 25 deletions
|
@ -89,6 +89,10 @@ function create_identity($arr) {
|
|||
|
||||
$primary = true;
|
||||
|
||||
if(array_key_exists('primary', $arr))
|
||||
$primary = intval($arr['primary']);
|
||||
|
||||
|
||||
$r = q("insert into channel ( channel_account_id, channel_primary,
|
||||
channel_name, channel_address, channel_guid, channel_guid_sig,
|
||||
channel_hash, channel_prvkey, channel_pubkey, channel_pageflags )
|
||||
|
|
|
@ -196,7 +196,7 @@ function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0)
|
|||
}}
|
||||
|
||||
if(! function_exists('z_fetch_url')) {
|
||||
function z_fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_content=Null) {
|
||||
function z_fetch_url($url, $binary = false, $redirects = 0, $opts = array()) {
|
||||
|
||||
$ret = array('return_code' => 0, 'success' => false, 'header' => "", 'body' => "");
|
||||
|
||||
|
@ -208,26 +208,28 @@ function z_fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accep
|
|||
|
||||
@curl_setopt($ch, CURLOPT_HEADER, true);
|
||||
@curl_setopt($ch, CURLOPT_CAINFO, get_capath());
|
||||
|
||||
if (!is_null($accept_content)){
|
||||
curl_setopt($ch,CURLOPT_HTTPHEADER, array (
|
||||
"Accept: " . $accept_content
|
||||
));
|
||||
}
|
||||
|
||||
@curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
|
||||
@curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
|
||||
@curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; Friendica Red)");
|
||||
|
||||
if (x($opts,'accept_content')){
|
||||
curl_setopt($ch,CURLOPT_HTTPHEADER, array (
|
||||
"Accept: " . $opts['accept_content']
|
||||
));
|
||||
}
|
||||
|
||||
if(intval($timeout)) {
|
||||
@curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
||||
if(x($opts,'timeout') && intval($opts['timeout'])) {
|
||||
@curl_setopt($ch, CURLOPT_TIMEOUT, $opts['timeout']);
|
||||
}
|
||||
else {
|
||||
$curl_time = intval(get_config('system','curl_timeout'));
|
||||
@curl_setopt($ch, CURLOPT_TIMEOUT, (($curl_time !== false) ? $curl_time : 60));
|
||||
}
|
||||
|
||||
@curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
|
||||
if(x($opts,'http_auth')) {
|
||||
// "username" . ':' . "password"
|
||||
@curl_setopt($ch, CURLOPT_USERPWD, $opts['http_auth']);
|
||||
}
|
||||
|
||||
$prx = get_config('system','proxy');
|
||||
if(strlen($prx)) {
|
||||
|
@ -269,9 +271,8 @@ function z_fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accep
|
|||
$newurl = $url . $newurl;
|
||||
$url_parsed = @parse_url($newurl);
|
||||
if (isset($url_parsed)) {
|
||||
$redirects++;
|
||||
@curl_close($ch);
|
||||
return z_fetch_url($newurl,$binary,$redirects,$timeout,$accpt_content);
|
||||
return z_fetch_url($newurl,$binary,$redirects++,$opts);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -287,7 +288,7 @@ function z_fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accep
|
|||
|
||||
|
||||
if(! function_exists('z_post_url')) {
|
||||
function z_post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0) {
|
||||
function z_post_url($url,$params, $headers = null, $redirects = 0, $timeout = 0) {
|
||||
|
||||
$ret = array('return_code' => 0, 'success' => false, 'header' => "", 'body' => "");
|
||||
|
||||
|
@ -362,12 +363,11 @@ function z_post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0
|
|||
$newurl = $url . $newurl;
|
||||
$url_parsed = @parse_url($newurl);
|
||||
if (isset($url_parsed)) {
|
||||
$redirects++;
|
||||
curl_close($ch);
|
||||
if($http_code == 303) {
|
||||
return z_fetch_url($newurl,false,$headers,$redirects,$timeout);
|
||||
return z_fetch_url($newurl,false,$headers,$redirects++,$timeout);
|
||||
} else {
|
||||
return z_post_url($newurl,$params,$headers,$redirects,$timeout);
|
||||
return z_post_url($newurl,$params,$headers,$redirects++,$timeout);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,13 +30,39 @@ 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
|
||||
|
||||
// import contacts
|
||||
|
@ -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
|
||||
|
||||
<form action="import" method="post" >
|
||||
Old Address <input type="text" name="old_address" /><br />
|
||||
Login <input type="text" name="email" /><br />
|
||||
Password <input type="password" name="password" /><br />
|
||||
<input type="submit" name="submit" value="submit" />
|
||||
</form>
|
||||
|
||||
EOT;
|
||||
|
||||
return $o;
|
||||
}
|
Loading…
Reference in a new issue