aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzotlabs <mike@macgirvin.com>2016-10-11 20:53:13 -0700
committerzotlabs <mike@macgirvin.com>2016-10-11 20:53:13 -0700
commitf56b4773cbb84950cd9ff07f920dd738c3ea5dbc (patch)
treed612734da8d63dd452538c0115b7194b695f8208
parent1a4a8f1ef7ba12f5b3eea6f6b2d162380a16fe17 (diff)
downloadvolse-hubzilla-f56b4773cbb84950cd9ff07f920dd738c3ea5dbc.tar.gz
volse-hubzilla-f56b4773cbb84950cd9ff07f920dd738c3ea5dbc.tar.bz2
volse-hubzilla-f56b4773cbb84950cd9ff07f920dd738c3ea5dbc.zip
When importing a channel from another server, try to auto-discover the best available api path.
-rw-r--r--Zotlabs/Module/Import.php24
-rw-r--r--include/network.php19
2 files changed, 33 insertions, 10 deletions
diff --git a/Zotlabs/Module/Import.php b/Zotlabs/Module/Import.php
index 9574de07c..ccad4eace 100644
--- a/Zotlabs/Module/Import.php
+++ b/Zotlabs/Module/Import.php
@@ -77,23 +77,27 @@ class Import extends \Zotlabs\Web\Controller {
$channelname = substr($old_address,0,strpos($old_address,'@'));
$servername = substr($old_address,strpos($old_address,'@')+1);
-
- $scheme = 'https://';
- $api_path = '/api/red/channel/export/basic?f=&channel=' . $channelname;
+
+ $api_path = probe_api_path($servername);
+ if(! $api_path) {
+ notice( t('Unable to download data from old server') . EOL);
+ return;
+ }
+
+ $api_path .= 'channel/export/basic?f=&channel=' . $channelname;
if($import_posts)
$api_path .= '&posts=1';
$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'])
+ $ret = z_fetch_url($api_path, $binary, $redirects, $opts);
+ if($ret['success']) {
$data = $ret['body'];
- else
+ }
+ else {
notice( t('Unable to download data from old server') . EOL);
-
+ return;
+ }
}
if(! $data) {
diff --git a/include/network.php b/include/network.php
index 7851f8976..97dca2b1a 100644
--- a/include/network.php
+++ b/include/network.php
@@ -2288,3 +2288,22 @@ function z_mail($params) {
logger('notification: z_mail returns ' . $res, LOGGER_DEBUG);
return $res;
}
+
+// discover the best API path available for redmatrix/hubzilla servers
+
+function probe_api_path($host) {
+
+ $schemes = ['https', 'http' ];
+ $paths = ['/api/z/1.0/version', '/api/red/version' ];
+
+ foreach($schemes as $scheme) {
+ foreach($paths as $path) {
+ $curpath = $scheme . '://' . $host . $path;
+ $x = z_fetch_url($curpath);
+ if($x['success'] && ! strlen($x['body'],'not implemented'))
+ return str_replace('version','',$curpath);
+ }
+ }
+
+ return '';
+} \ No newline at end of file