aboutsummaryrefslogtreecommitdiffstats
path: root/mod/import.php
blob: 7b5989f51a93dacbe0a8a40e2be38c1c8f1948bb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php

// Import a channel, either by direct file upload or via
// connection to original server. 


function import_post(&$a) {


	$data     = null;
	$seize    = ((x($_REQUEST,'make_primary')) ? intval($_REQUEST['make_primary']) : 0);

	$src      = $_FILES['userfile']['tmp_name'];
	$filename = basename($_FILES['userfile']['name']);
	$filesize = intval($_FILES['userfile']['size']);
	$filetype = $_FILES['userfile']['type'];


	if($src) {
		if($filesize) {
			$data = @file_get_contents($src);
		}
	}

	if(! $src) {
		$old_address = ((x($_REQUEST,'old_address')) ? $_REQUEST['old_address'] : '');
		if(! $old_address) {
			logger('mod_import: nothing to import.');
			notice( t('Nothing to import.') . EOL);
			return;
		}

		$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





	if($seize) {
		// notify old server that it is no longer primary.
		
	}


	// send out refresh requests

}


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;
}