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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
#!/usr/bin/env php
<?php
// file import to DAV utility
if(!file_exists('include/cli_startup.php')) {
echo 'Run dcp from the top level Hubzilla web directory, as util/dcp <args>' . PHP_EOL;
exit(1);
}
require_once('include/cli_startup.php');
require_once('include/attach.php');
cli_startup();
if($argc <= 3) {
echo "Usage: " . $argv[0] . ' src dstdir' . "\n";
echo 'Always run from the toplevel web directory.' . "\n";
echo 'destination should begin with store/$nickname/desired/path or $nickname/desired/path' . "\n";
echo 'Example: util/dcp /etc/motd store/joe/etc' . "\n";
exit;
}
$recursive = false;
$dstfile = $argv[$argc - 1];
if(strpos($dstfile,'store/') === 0)
$dstfile = substr($dstfile,6);
$nick = substr($dstfile,0,strpos($dstfile,'/'));
$dstfile = substr($dstfile,strlen($nick)+1);
$channel = channelx_by_nick($nick);
if(! $channel)
return;
$isadir = false;
$r = q("select * from attach where display_path = '%s' and uid = %d limit 1",
dbesc($dstfile),
intval($channel['channel_id'])
);
if($r && $r[0]['is_dir']) {
$isadir = true;
$basepath = $dstfile;
$folder = $r[0]['hash'];
}
else {
$arr = [
'pathname' => dirname($dstfile),
'allow_cid' => $channel['channel_allow_cid'],
'allow_gid' => $channel['channel_allow_gid'],
'deny_cid' => $channel['channel_deny_cid'],
'deny_gid' => $channel['channel_deny_gid'],
];
$folder = '';
if(dirname($dstfile)) {
$x = attach_mkdirp($channel,$channel['channel_hash'],$arr);
if($x['success'])
$folder = $x['data']['hash'];
}
}
for($x = 1; $x < ($argc - 1); $x ++) {
if(($argv[$x] === '-r') || ($argv[$x] === '-R')) {
$recursive = true;
continue;
}
if(is_dir($argv[$x])) {
if($recursive) {
dcp_recurse($channel,$argv[$x],$basepath,$folder);
}
else {
continue;
}
}
else {
$dstname = (($isadir) ? '' : basename($dstfile));
$cmd = [ 'Importfile', $channel['channel_id'], $argv[$x], $folder, $dstname ];
\Zotlabs\Daemon\Master::Summon($cmd);
}
}
function dcp_recurse($channel,$src,$basepath,$folder) {
$dir = opendir($src);
if($dir) {
while(($entry = readdir($dir)) !== false) {
if($entry === '.' || $entry === '..')
continue;
$dstfile = $basepath . '/' . $entry;
if(is_dir($src . '/' . $entry)) {
$r = q("select * from attach where display_path = '%s' and uid = %d limit 1",
dbesc($dstfile),
intval($channel['channel_id'])
);
if($r && $r[0]['is_dir']) {
$folder = $r[0]['hash'];
}
else {
$arr = [
'pathname' => $dstfile,
'allow_cid' => $channel['channel_allow_cid'],
'allow_gid' => $channel['channel_allow_gid'],
'deny_cid' => $channel['channel_deny_cid'],
'deny_gid' => $channel['channel_deny_gid'],
];
$folder = '';
$x = attach_mkdirp($channel,$channel['channel_hash'],$arr);
if($x['success'])
$folder = $x['data']['hash'];
}
$basepath = $dstfile;
dcp_recurse($channel,$src . '/' . $entry,$basepath,$folder);
}
else {
$cmd = [ 'Importfile', $channel['channel_id'], $src . '/' . $entry, $folder ];
\Zotlabs\Daemon\Master::Summon($cmd);
}
}
closedir($dir);
}
}
|