2016-11-01 22:27:34 +00:00
|
|
|
#!/usr/bin/env php
|
|
|
|
<?php
|
|
|
|
|
|
|
|
// connect utility
|
|
|
|
|
2018-06-05 01:40:11 +00:00
|
|
|
use Zotlabs\Lib\Libsync;
|
2019-01-22 01:31:24 +00:00
|
|
|
use Zotlabs\Lib\Connect;
|
2020-06-15 07:29:56 +00:00
|
|
|
use Zotlabs\Daemon\Run;
|
2018-06-01 04:05:09 +00:00
|
|
|
|
2020-07-02 06:03:34 +00:00
|
|
|
if (! file_exists('include/cli_startup.php')) {
|
2016-11-01 22:27:34 +00:00
|
|
|
echo t('Run from the top level $Projectname web directory, as util/connect <args>') . PHP_EOL;
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
require_once('include/cli_startup.php');
|
|
|
|
|
|
|
|
cli_startup();
|
|
|
|
|
|
|
|
|
|
|
|
if($argc != 3) {
|
|
|
|
echo t('Usage: util/connect channel_id|channel_address channel[@hub]');
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2020-07-02 06:03:34 +00:00
|
|
|
if (ctype_digit($argv[1])) {
|
2016-11-01 22:27:34 +00:00
|
|
|
$c = channelx_by_n($argv[1]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$c = channelx_by_nick($argv[1]);
|
|
|
|
}
|
|
|
|
|
2020-07-02 06:03:34 +00:00
|
|
|
if (! $c) {
|
2016-11-01 22:27:34 +00:00
|
|
|
echo t('Source channel not found.');
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2019-01-22 01:31:24 +00:00
|
|
|
$result = Connect::connect($c,$argv[2]);
|
2016-11-01 22:27:34 +00:00
|
|
|
|
2020-07-02 06:03:34 +00:00
|
|
|
if ($result['success'] == false) {
|
2016-11-01 22:27:34 +00:00
|
|
|
echo $result['message'];
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2020-07-02 06:03:34 +00:00
|
|
|
$clone = [];
|
|
|
|
foreach ($result['abook'] as $k => $v) {
|
|
|
|
if (strpos($k,'abook_') === 0) {
|
2016-11-01 22:27:34 +00:00
|
|
|
$clone[$k] = $v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unset($clone['abook_id']);
|
|
|
|
unset($clone['abook_account']);
|
|
|
|
unset($clone['abook_channel']);
|
|
|
|
|
|
|
|
$abconfig = load_abconfig($c['channel_id'],$clone['abook_xchan']);
|
2020-07-02 06:03:34 +00:00
|
|
|
if ($abconfig) {
|
2016-11-01 22:27:34 +00:00
|
|
|
$clone['abconfig'] = $abconfig;
|
2020-07-02 06:03:34 +00:00
|
|
|
}
|
|
|
|
Libsync::build_sync_packet($c['channel_id'], [ 'abook' => [ $clone ] ], true);
|
2016-11-01 22:27:34 +00:00
|
|
|
|
2018-05-26 22:12:02 +00:00
|
|
|
$can_view_stream = their_perms_contains($c['channel_id'],$clone['abook_xchan'],'view_stream');
|
2016-11-01 22:27:34 +00:00
|
|
|
|
|
|
|
// If we can view their stream, pull in some posts
|
|
|
|
|
2020-07-02 06:03:34 +00:00
|
|
|
if (($can_view_stream) || ($result['abook']['xchan_network'] === 'rss')) {
|
2020-06-15 07:29:56 +00:00
|
|
|
Run::Summon([ 'Onepoll',$result['abook']['abook_id'] ]);
|
2019-01-22 01:31:24 +00:00
|
|
|
}
|
2016-11-01 22:27:34 +00:00
|
|
|
|
|
|
|
exit(0);
|