2016-04-19 03:38:38 +00:00
|
|
|
<?php
|
|
|
|
namespace Zotlabs\Module;
|
|
|
|
|
2018-06-05 01:40:11 +00:00
|
|
|
use Zotlabs\Lib\Libsync;
|
2018-08-23 06:04:37 +00:00
|
|
|
use Zotlabs\Lib\ActivityStreams;
|
|
|
|
use Zotlabs\Lib\Activity;
|
|
|
|
use Zotlabs\Web\HTTPSignatures;
|
2018-09-18 05:50:06 +00:00
|
|
|
use Zotlabs\Lib\LDSignatures;
|
2016-04-19 03:38:38 +00:00
|
|
|
|
|
|
|
require_once('include/follow.php');
|
|
|
|
|
|
|
|
|
|
|
|
class Follow extends \Zotlabs\Web\Controller {
|
|
|
|
|
|
|
|
function init() {
|
|
|
|
|
|
|
|
if(! local_channel()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-09-18 05:50:06 +00:00
|
|
|
if(ActivityStreams::is_as_request() && argc() == 2) {
|
|
|
|
$abook_id = intval(argv(1));
|
2018-08-23 06:04:37 +00:00
|
|
|
if(! $abook_id)
|
|
|
|
return;
|
|
|
|
|
|
|
|
$r = q("select * from abook left join xchan on abook_xchan = xchan_hash where abook_id = %d",
|
|
|
|
intval($abook_id)
|
|
|
|
);
|
|
|
|
if (! $r)
|
|
|
|
return;
|
|
|
|
|
|
|
|
$chan = channelx_by_n($r[0]['abook_channel']);
|
|
|
|
|
|
|
|
if(! $chan)
|
|
|
|
http_status_exit(404, 'Not found');
|
|
|
|
|
2018-09-18 05:50:06 +00:00
|
|
|
$actor = Activity::encode_person($chan,true,true);
|
2018-08-23 06:04:37 +00:00
|
|
|
if(! $actor)
|
|
|
|
http_status_exit(404, 'Not found');
|
|
|
|
|
|
|
|
$x = array_merge(['@context' => [
|
|
|
|
ACTIVITYSTREAMS_JSONLD_REV,
|
|
|
|
'https://w3id.org/security/v1',
|
|
|
|
z_root() . ZOT_APSCHEMA_REV
|
|
|
|
]],
|
|
|
|
[
|
|
|
|
'id' => z_root() . '/follow/' . $r[0]['abook_id'],
|
|
|
|
'type' => 'Follow',
|
|
|
|
'actor' => $actor,
|
|
|
|
'object' => $r[0]['xchan_url']
|
|
|
|
]);
|
|
|
|
|
|
|
|
$headers = [];
|
|
|
|
$headers['Content-Type'] = 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"' ;
|
2018-09-18 05:50:06 +00:00
|
|
|
$x['signature'] = LDSignatures::sign($x,$chan);
|
2018-08-23 06:04:37 +00:00
|
|
|
$ret = json_encode($x, JSON_UNESCAPED_SLASHES);
|
|
|
|
$headers['Digest'] = HTTPSig::generate_digest_header($ret);
|
|
|
|
$h = HTTPSig::create_sig($headers,$chan['channel_prvkey'],channel_url($chan));
|
|
|
|
HTTPSig::set_headers($h);
|
|
|
|
echo $ret;
|
|
|
|
killme();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-04-19 03:38:38 +00:00
|
|
|
$uid = local_channel();
|
2018-03-15 01:42:07 +00:00
|
|
|
$url = notags(trim(punify($_REQUEST['url'])));
|
2016-04-19 03:38:38 +00:00
|
|
|
$return_url = $_SESSION['return_url'];
|
|
|
|
$confirm = intval($_REQUEST['confirm']);
|
2018-03-02 09:01:30 +00:00
|
|
|
$interactive = (($_REQUEST['interactive']) ? intval($_REQUEST['interactive']) : 1);
|
2016-04-19 03:38:38 +00:00
|
|
|
$channel = \App::get_channel();
|
2016-05-05 03:24:47 +00:00
|
|
|
|
2018-03-02 09:01:30 +00:00
|
|
|
$result = new_contact($uid,$url,$channel,$interactive,$confirm);
|
2016-04-19 03:38:38 +00:00
|
|
|
|
|
|
|
if($result['success'] == false) {
|
|
|
|
if($result['message'])
|
|
|
|
notice($result['message']);
|
2018-03-02 09:01:30 +00:00
|
|
|
if($interactive) {
|
|
|
|
goaway($return_url);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
json_return_and_die($result);
|
|
|
|
}
|
2016-04-19 03:38:38 +00:00
|
|
|
}
|
|
|
|
|
2018-03-02 22:09:59 +00:00
|
|
|
info( t('Connection added.') . EOL);
|
2016-04-19 03:38:38 +00:00
|
|
|
|
|
|
|
$clone = array();
|
|
|
|
foreach($result['abook'] as $k => $v) {
|
|
|
|
if(strpos($k,'abook_') === 0) {
|
|
|
|
$clone[$k] = $v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unset($clone['abook_id']);
|
|
|
|
unset($clone['abook_account']);
|
|
|
|
unset($clone['abook_channel']);
|
|
|
|
|
2016-06-24 01:12:26 +00:00
|
|
|
$abconfig = load_abconfig($channel['channel_id'],$clone['abook_xchan']);
|
2016-04-19 03:38:38 +00:00
|
|
|
if($abconfig)
|
|
|
|
$clone['abconfig'] = $abconfig;
|
|
|
|
|
2018-06-05 01:40:11 +00:00
|
|
|
Libsync::build_sync_packet(0 /* use the current local_channel */, array('abook' => array($clone)), true);
|
2016-04-19 03:38:38 +00:00
|
|
|
|
2018-05-26 22:12:02 +00:00
|
|
|
$can_view_stream = their_perms_contains($channel['channel_id'],$clone['abook_xchan'],'view_stream');
|
2016-04-19 03:38:38 +00:00
|
|
|
|
|
|
|
// If we can view their stream, pull in some posts
|
|
|
|
|
2016-07-10 02:03:29 +00:00
|
|
|
if(($can_view_stream) || ($result['abook']['xchan_network'] === 'rss'))
|
2016-05-20 05:26:37 +00:00
|
|
|
\Zotlabs\Daemon\Master::Summon(array('Onepoll',$result['abook']['abook_id']));
|
2016-04-19 03:38:38 +00:00
|
|
|
|
2018-03-02 09:01:30 +00:00
|
|
|
if($interactive) {
|
|
|
|
goaway(z_root() . '/connedit/' . $result['abook']['abook_id'] . '?f=&follow=1');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
json_return_and_die([ 'success' => true ]);
|
|
|
|
}
|
2016-04-19 03:38:38 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-05-20 05:26:37 +00:00
|
|
|
function get() {
|
2016-04-19 03:38:38 +00:00
|
|
|
if(! local_channel()) {
|
|
|
|
return login();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|